-
Install the package in your sveltekit app
npm i -D svelte-git-cms
-
Create src/hooks.js
with following content
import { synced } from 'svelte-git-cms';
import { sync } from 'svelte-git-cms';
import { get } from 'svelte/store';
export async function handle({ event, resolve }) {
if (!get(synced)) { await sync() }
const response = await resolve(event);
return response;
}
-
Create an webhook route for github, so github can inform your app when issues or labels change.
a) Create webhook endpoint src/routes/api/git-webhook/+server.js
import { handleWebhook } from 'svelte-git-cms';
export async function POST({ request }) {
return handleWebhook(request)
}
b) Go to your github repo Settings > Webhooks > Add webhook
and create a new webhook with following config:
- Payload URL
https://YOUR_PRODUCTION_DOMAIN/api/git-webhook
- Content type
application/json
- Events Select
Issues
and Labels
-
Create +page.server.js
in the route you want to show the posts / labels.
a) src/routes/+page.server.js
import { labels, posts } from 'svelte-git-cms';
import { get } from 'svelte/store';
export async function load({ params }) {
return {
posts: get(posts),
labels: get(labels)
}
}
b) src/routes/+page.svelte
<script>
export let data;
</script>
<ul>
{#each Object.keys(data.labels) as label}
<li>{label}</li>
{/each}
</ul>
{#if Object.keys(data.posts).length}
<ul>
{#each Object.entries(data.posts) as [slug, post]}
<li>
/{slug}
{post.title}
{post.body}
</li>
{/each}
</ul>
{:else}
No posts
{/if}