Migrate articles to standalone endpoints

This commit is contained in:
Michal Vanko 2022-03-24 18:38:53 +01:00
parent fecdeee94d
commit 5f1c7e9804
4 changed files with 15 additions and 5 deletions

View File

@ -1,5 +1,5 @@
/** @type {import('@sveltejs/kit').ParamMatcher} */
export function match(param: string) {
console.log('parma', param)
console.debug('parma', param)
return !['tags', 'page'].some((keyword) => param.startsWith(keyword))
}

View File

@ -3,14 +3,12 @@
import type { LoadInput, LoadOutput } from '@sveltejs/kit/types/page'
export async function load({ fetch, url }: LoadInput): Promise<LoadOutput> {
const blogPostsResponse = await fetch(`/blog`, {
headers: { accept: 'application/json' },
})
const blogPostsResponse = await fetch(`/blog/articles`)
const blogPostsContent = await blogPostsResponse.json()
return {
props: {
latestPosts: take(5, blogPostsContent.posts),
// TODO Check if not bugged
// TODO Check if not bugged FIXME
segment: '',
},
}

View File

@ -1,3 +1,15 @@
<script lang="ts" context="module">
/**
* @type {import('@sveltejs/kit').Load}
*/
export async function load({ fetch }) {
const articleResponse = await fetch(`/blog/articles`)
.then((r) => r.json())
return { props: { posts: articleResponse.posts } }
}
</script>
<script lang="ts">
import ArticleFooter from '../../components/blog/ArticleFooter.svelte'
import { postListClass, seeAllClass } from './index.css'