Broadcasting section

This commit is contained in:
2023-02-18 06:41:07 +01:00
parent dac3e13520
commit 3640a5f13a
13 changed files with 79 additions and 53 deletions

View File

@ -3,7 +3,7 @@ import {
parseParams,
} from '$lib/pagination/dropTakeParams'
import { json } from '@sveltejs/kit'
import { getBlogListing } from '$lib/content/articleContentListing'
import { getBlogListing } from '$lib/articleContent/articleContentListing'
import type { RequestHandler } from './$types'
export const prerender = true

View File

@ -1,6 +1,6 @@
import { parseParams } from '$lib/pagination/dropTakeParams'
import type { PageLoad } from './$types'
import type { ArticleContent } from '$lib/content/articleContentListing'
import type { ArticlePreviewAttributes } from '$lib/articleContent/articleContentListing'
import type { PaginationResult } from '$lib/pagination/pagination'
export const load = (async ({ fetch, params }) => {
@ -9,7 +9,7 @@ export const load = (async ({ fetch, params }) => {
`/articles/segments/blog${params.params ? `/${params.params}` : ''}.json`
).then((r) => r.json())
return {
posts: articleResponse.posts as PaginationResult<ArticleContent>,
posts: articleResponse.posts as PaginationResult<ArticlePreviewAttributes >,
page: Number(page),
pageSize,
filters,

View File

@ -1,35 +1,9 @@
import { readFile } from 'fs'
import { promisify } from 'util'
import fm from 'front-matter'
import { parseField } from '../../../markdown/parse-markdown'
import { error } from '@sveltejs/kit'
import type { ArticleAttributes } from '$lib/content/articleContentListing'
import type { PageServerLoad } from './$types'
import { getArticleContent } from '$lib/articleContent/articleContent'
export const prerender = true
export interface SinglePost {
body: string
}
export const load = (async ({ params: { slug } }) => {
let postSource: string
try {
postSource = await promisify(readFile)(`_posts/blog/${slug}.md`, 'utf-8')
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
if (e.code === 'ENOENT') {
throw error(404, 'Post not found \n' + e.toString())
}
throw e
}
const parsedPost = fm<ArticleAttributes>(postSource)
const post = parseField<SinglePost>('body')({
...parsedPost.attributes,
body: parsedPost.body,
})
const post = await getArticleContent(slug);
return post
}) satisfies PageServerLoad

View File

@ -1,7 +1,7 @@
<script lang="ts">
import ArticleFooter from '$lib/components/articles/ArticlePreviewFooter/ArticlePreviewFooter.svelte'
import type { PageData } from './$types'
import { contentClass } from './page.css'
import { contentClass } from '$lib/styles/article/article.css'
export let data: PageData
</script>

View File

@ -1,21 +0,0 @@
import { globalStyle, style } from '@vanilla-extract/css'
import { vars } from '$lib/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

@ -1,6 +1,6 @@
import { parseParams } from '$lib/pagination/dropTakeParams'
import type { PageLoad } from './$types'
import type { ArticleContent } from '$lib/content/articleContentListing'
import type { ArticlePreviewAttributes } from '$lib/articleContent/articleContentListing'
import type { PaginationResult } from '$lib/pagination/pagination'
export const load = (async ({ fetch, params }) => {
@ -10,7 +10,7 @@ export const load = (async ({ fetch, params }) => {
).then((r) => r.json())
return {
posts: articleResponse.posts as PaginationResult<ArticleContent>,
posts: articleResponse.posts as PaginationResult<ArticlePreviewAttributes>,
page: Number(page),
pageSize,
filters,

View File

@ -0,0 +1,9 @@
import type { PageServerLoad } from './$types'
import { getArticleContent } from '$lib/articleContent/articleContent'
export const prerender = true
export const load = (async ({ params: { slug } }) => {
const post = await getArticleContent(slug);
return post
}) satisfies PageServerLoad

View File

@ -0,0 +1,18 @@
<script lang="ts">
import ArticleFooter from '$lib/components/articles/ArticlePreviewFooter/ArticlePreviewFooter.svelte'
import type { PageData } from './$types'
import { contentClass } from '$lib/styles/article/article.css'
export let data: PageData
</script>
<svelte:head>
<title>{data.title}</title>
</svelte:head>
<h1>{data.title}</h1>
<div class="content {contentClass}">
{@html data.body}
</div>
<ArticleFooter article={data} segment="broadcasts" />

View File

@ -3,7 +3,7 @@ import { promisify } from 'util'
import fm from 'front-matter'
// TODO Switch marked for unified
import marked from 'marked'
import { parseField } from '../../markdown/parse-markdown'
import { parseField } from '$lib/markdown/parse-markdown'
import type { PageServerLoad } from './$types'
export const prerender = true