This assumes you have an existing Svelte project you wish to add a blog to. If not, see here.
Pullnote can power an area of your site (say /blog and all of the folders underneath) or individual folders / pages.
In your blog folder (or whatever your content directory is) create a +layout.server.js
file to retrieve data from the pullnote API:
export async function load({url, params}) {
var res = await fetch("https://pullnote.com/pull/note" + url.pathname, {
headers: {
"Content-Type": "application/json; charset=utf-8",
"pn_authorization": "Bearer YOUR_API_KEY"
}
});
var note = await res.json();
return {note}
}
Replace YOUR_API_KEY with the free key in Pullnote project settings.
Create a folder called [...slug]
and add an empty +page.svelte file to it (yes, completely empty) so that the Svelte router will pick the folder up. This will catch all of the sub-folder content too.
Drop this +layout.svelte file into your content root:
<script>
export let data;
// Make the note reactive so that the layout refreshes on url change
$: note = data.note;
</script>
<svelte:head>
{@html note.head_html}
</svelte:head>
<a href={data.note.category.pathname}>
{data.note.category.title}
</a>
<h1>{note.title}</h1>
{#if note.picture}
<img src={note.img.src} alt={note.img.alt} />
{/if}
{@html note.content_html}
<slot />
{#if note.is_category}
<hr />
<ul>
{#each note.links as link}
<li>
<a class="link" href={link.pathname}>
{link.title}
</a>
</li>
{/each}
</ul>
{/if}
npm run dev
and you should see any content you've entered in the pullnote console.