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

View File

@ -3,14 +3,12 @@
import type { LoadInput, LoadOutput } from '@sveltejs/kit/types/page' import type { LoadInput, LoadOutput } from '@sveltejs/kit/types/page'
export async function load({ fetch, url }: LoadInput): Promise<LoadOutput> { export async function load({ fetch, url }: LoadInput): Promise<LoadOutput> {
const blogPostsResponse = await fetch(`/blog`, { const blogPostsResponse = await fetch(`/blog/articles`)
headers: { accept: 'application/json' },
})
const blogPostsContent = await blogPostsResponse.json() const blogPostsContent = await blogPostsResponse.json()
return { return {
props: { props: {
latestPosts: take(5, blogPostsContent.posts), latestPosts: take(5, blogPostsContent.posts),
// TODO Check if not bugged // TODO Check if not bugged FIXME
segment: '', 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"> <script lang="ts">
import ArticleFooter from '../../components/blog/ArticleFooter.svelte' import ArticleFooter from '../../components/blog/ArticleFooter.svelte'
import { postListClass, seeAllClass } from './index.css' import { postListClass, seeAllClass } from './index.css'