I've finally got this blog(ish) website setup in a way I'm happy with. Most of the site is just a static export from sapper but the learning pieces are all entries in a Notion table. Each page in the table has a slug
property which sets the url you navigate to e.g. this piece is building-a-blog-with-svelte-and-notion
.
To begin you'll need to create a new sapper project:
npx degit "sveltejs/sapper-template#rollup" my-svelte-notion-blog
cd my-svelte-notion-blog
npm install
This will scaffold the general structure for a sapper site. There's lots of template pages that you'll want to change (index.svelte
, about.svelte
, etc) but we're going to focus on the blog folder.
Go ahead and delete everything inside the blog
folder and create an empty index.svelte
file.
First we'll need a Notion table where we are going to pull the posts from.
slug
with value my-first-post
– we'll use this for the url510a05b08ef842498d686c92614fe912
Now, we can get all the items from this table and display them in our website. Notion doesn't have a public API yet but fortunately Splitbee have created a wrapper for their private API, which we'll interact with using sotion
npm install -D sotion
Sotion
has built in support for building a blog based on our Notion table. First we'll scope our posts to that table. In _layout.svelte
<script>
import { sotion } from "sotion";
const tableId = 'xxxxxxxx' // Whatever you copied before
sotion.setScope(tableId)
</script>