Fix see all posts and convert css to sprinkles

This commit is contained in:
Michal Vanko 2021-12-09 17:57:15 +01:00
parent 2bdd56fc5f
commit f8b6792a71
10 changed files with 143 additions and 126 deletions

View File

@ -0,0 +1,41 @@
import { style } from '@vanilla-extract/css'
import { desaturate, transparentize } from 'polished'
import { colors } from '../../styles/vars.css'
import { sprinkles } from '../../styles/sprinkles.css'
export const tagsListClass = sprinkles({
listStyle: 'none',
margin: 'none',
padding: 'none',
display: 'inline',
})
export const tagsListLiClass = sprinkles({
display: 'inline',
fontStyle: 'italic',
})
export const publishedClass = sprinkles({
whiteSpace: 'nowrap',
fontStyle: 'italic',
})
export const publishedLabelClass = sprinkles({
color: 'tintedText',
})
export const footerClass = style([
sprinkles({
display: 'flex',
fontSize: 'sm',
justifyContent: 'space-between',
paddingTop: '1x',
marginTop: '2x',
}),
{
borderTop: `1px solid ${transparentize(
0.6,
desaturate(0.5, colors.tearkiss)
)}`,
},
])

View File

@ -0,0 +1,34 @@
<script lang="ts">
import { format } from 'date-fns'
import type { PostContent } from '../../routes/blog/_content'
import {
footerClass,
publishedClass,
publishedLabelClass,
tagsListClass,
tagsListLiClass,
} from './ArticleFooter.css'
export let post: PostContent
</script>
<footer class={footerClass}>
<div class="article-tags">
{#if post.tags.length > 0}
<span class="lighten">Tags:</span>
<ul class={tagsListClass}>
{#each post.tags as tag}
<li class={tagsListLiClass}>
<a href="/blog?tag={tag}">{tag}</a>
</li>
{/each}
</ul>
{/if}
</div>
<div class="created-at">
<span class={publishedLabelClass}>Published on</span>
<time datetime={post.date} class={publishedClass}>
{format(new Date(post.date), "do MMMM',' y")}
</time>
</div>
</footer>

View File

@ -1,61 +0,0 @@
<script lang="ts">
import { format } from 'date-fns'
import type { PostContent } from '../../routes/blog/_content'
export let post: PostContent
</script>
<footer>
<div class="article-tags">
{#if post.tags.length > 0}
<span class="lighten">Tags:</span>
<ul class="tags-list">
{#each post.tags as tag}
<li>
<a href="/blog?tag={tag}">{tag}</a>
</li>
{/each}
</ul>
{/if}
</div>
<div class="created-at">
<span class="lighten">Published on</span>
<time datetime={post.date}>
{format(new Date(post.date), "do MMMM',' y")}
</time>
</div>
</footer>
<style lang="less">
@import '../../styles/variables.module.less';
.tags-list {
list-style: none;
margin: 0;
padding: 0;
display: inline;
}
.tags-list li {
display: inline;
font-style: italic;
}
.lighten {
color: tint(@article-text-color, 25%);
}
time {
white-space: nowrap;
font-style: italic;
}
footer {
display: flex;
font-size: 0.8em;
justify-content: space-between;
padding-top: 0.6em;
margin-top: 1em;
border-top: 1px solid fade(desaturate(@tearkiss, 50%), 40%);
}
</style>

View File

@ -26,7 +26,8 @@
</script> </script>
<script lang="ts"> <script lang="ts">
import ArticleFooter from '../../components/blog/article-footer.svelte' import ArticleFooter from '../../components/blog/ArticleFooter.svelte'
import { contentClass } from './blog.css'
export let post export let post
</script> </script>
@ -37,37 +38,7 @@
<h1>{post.title}</h1> <h1>{post.title}</h1>
<div class="content"> <div class="content {contentClass}">
{@html post.body} {@html post.body}
</div> </div>
<ArticleFooter {post} /> <ArticleFooter {post} />
<style lang="less">
@import '../../styles/variables.module.less';
/*
By default, CSS is locally scoped to the component,
and any unused styles are dead-code-eliminated.
In this page, Svelte can't know which elements are
going to appear inside the {{{post.html}}} block,
so we have to use the :global(...) modifier to target
all elements inside .content
*/
.content :global(ul) {
line-height: 1.5;
}
.content :global(li) {
margin: 0 0 0.5em 0;
}
.content :global(img) {
max-height: 640px;
}
.content :global(img:only-child) {
display: block;
margin: 0 auto;
}
</style>

View File

@ -0,0 +1,21 @@
import { globalStyle, style } from '@vanilla-extract/css'
import { vars } from 'src/styles/vars.css'
export const contentClass = style({})
globalStyle(`${contentClass} ul, ${contentClass} ol`, {
lineHeight: vars.lineHeight['2x'],
})
globalStyle(`${contentClass} li`, {
marginBottom: vars.space['2x'],
})
globalStyle(`${contentClass} img`, {
maxHeight: vars.height.image,
})
globalStyle(`${contentClass} img:only-child`, {
display: 'block',
margin: '0 auto',
})

View File

@ -0,0 +1,20 @@
import { globalStyle } from '@vanilla-extract/css'
import { vars } from '../../styles/vars.css'
import { sprinkles } from '../../styles/sprinkles.css'
export const postListClass = sprinkles({
padding: 'none',
lineHeight: '3x',
listStyle: 'none',
})
export const seeAllClass = sprinkles({
textAlign: 'end',
width: 'parent',
maxWidth: 'max',
margin: 'auto',
})
globalStyle(`${postListClass} > li:not(:last-child)`, {
marginBottom: vars.space['4x'],
})

View File

@ -1,7 +1,7 @@
import { getBlogListing } from './_content' import { getBlogListing } from './_content'
export async function get({ query }) { export async function get({ query }) {
const { tag } = query const tag = query.get('tag')
const filteredContents = await getBlogListing(tag) const filteredContents = await getBlogListing(tag)
return { return {
status: 200, status: 200,

View File

@ -1,14 +1,10 @@
<script context="module" lang="ts"> <script context="module" lang="ts">
// TODO Fix query & seeAll functionality
/** /**
* @type {import('@sveltejs/kit').Load} * @type {import('@sveltejs/kit').Load}
*/ */
export function load({ fetch, page: { params, query } }) { export function load({ fetch, page: { params, query } }) {
const blogQuery = query const blogQuery = query ? '?' + query.toString() : ''
? '?' +
Object.entries(query)
.map((q) => q.join('='))
.join('&')
: ''
return fetch(`blog.json${blogQuery}`) return fetch(`blog.json${blogQuery}`)
.then((r) => r.json()) .then((r) => r.json())
.then((posts) => { .then((posts) => {
@ -18,11 +14,15 @@
</script> </script>
<script lang="ts"> <script lang="ts">
import ArticleFooter from '../../components/blog/article-footer.svelte' import ArticleFooter from '../../components/blog/ArticleFooter.svelte'
import { postListClass, seeAllClass } from './index.css'
import type { PostContent } from './_content' import type { PostContent } from './_content'
export let posts: PostContent[] export let posts: PostContent[]
export let query export let query
export let tagQuery
$: tagQuery = query.get('tag')
</script> </script>
<svelte:head> <svelte:head>
@ -34,18 +34,18 @@
{:else} {:else}
<h1> <h1>
Recent Recent
{#if query.tag} {#if tagQuery}
<em>{query.tag}</em> <em>{tagQuery}</em>
{/if} {/if}
posts posts
</h1> </h1>
{#if query.tag} {#if tagQuery}
<div class="see-all"> <div class={seeAllClass}>
<a href="/blog" class="">See all posts</a> <a href="/blog">See all posts</a>
</div> </div>
{/if} {/if}
{/if} {/if}
<ul class="post-list"> <ul class="post-list {postListClass}">
{#each posts as post} {#each posts as post}
<!-- we're using the non-standard `rel=prefetch` attribute to <!-- we're using the non-standard `rel=prefetch` attribute to
tell Sapper to load the data for the page as soon as tell Sapper to load the data for the page as soon as
@ -64,20 +64,3 @@
</li> </li>
{/each} {/each}
</ul> </ul>
<style>
.post-list {
padding: 0;
line-height: 1.5;
list-style: none;
}
.post-list > li:not(:last-child) {
margin-bottom: 3em;
}
.see-all {
text-align: end;
margin-top: -1.5em;
}
</style>

View File

@ -33,7 +33,7 @@ const responsiveProperties = defineProperties({
], ],
alignItems: ['stretch', 'flex-start', 'center', 'flex-end'], alignItems: ['stretch', 'flex-start', 'center', 'flex-end'],
flex: ['1'], flex: ['1'],
textAlign: ['left', 'center', 'right', 'justify', 'start'], textAlign: ['center', 'justify', 'start', 'end'],
textShadow: vars.textShadow, textShadow: vars.textShadow,
paddingTop: vars.space, paddingTop: vars.space,
paddingBottom: vars.space, paddingBottom: vars.space,
@ -47,6 +47,7 @@ const responsiveProperties = defineProperties({
fontSize: vars.fontSize, fontSize: vars.fontSize,
fontFamily: vars.fontFamily, fontFamily: vars.fontFamily,
fontWeight: vars.fontWeight, fontWeight: vars.fontWeight,
fontStyle: ['italic', 'normal'],
lineHeight: vars.lineHeight, lineHeight: vars.lineHeight,
whiteSpace: ['normal', 'nowrap'], whiteSpace: ['normal', 'nowrap'],
width: vars.width, width: vars.width,

View File

@ -19,6 +19,7 @@ export const colors = {
export const menuBackground = transparentize(0.6, colors.tearkiss) export const menuBackground = transparentize(0.6, colors.tearkiss)
export const transparent = transparentize(1, '#ffffff') export const transparent = transparentize(1, '#ffffff')
const articleText = desaturate(0.16, colors.midnightBlue)
export enum breakpoints { export enum breakpoints {
s = 400, s = 400,
@ -57,7 +58,8 @@ export const vars = createGlobalTheme(':root', {
'8x': spaceScale(8), '8x': spaceScale(8),
}, },
color: { color: {
articleText: desaturate(0.16, colors.midnightBlue), articleText,
tintedText: tint(0.25, articleText),
selection: tint(0.4, colors.pinky), selection: tint(0.4, colors.pinky),
link: saturate(0.2, mix(0.66, colors.tearkiss, colors.midnightBlue)), link: saturate(0.2, mix(0.66, colors.tearkiss, colors.midnightBlue)),
linkHover: colors.tearkiss, linkHover: colors.tearkiss,
@ -119,4 +121,9 @@ export const vars = createGlobalTheme(':root', {
full: '100vw', full: '100vw',
parent: '100%', parent: '100%',
}, },
height: {
full: '100hw',
parent: '100%',
image: '640px',
},
}) })