Building a TIL website with datasette

I came across an article from https://til.simonwillison.net/ and learned about datasette. It's a pretty cool template to write and publish TILs.

TLDR; this is the commit for a base setup that works.

List of features I like:

  1. Markdown articles
  2. Integration with Github actions
  3. Search, OpenAI integration
  4. Vercel deployment

Github Actions

Thanks to simonw on the well written and easy-to-understand .github/workflows/build.yml. I disabled some features for basic template to work:

Added environment variables in github actions' secrets:

Adjusted Actions permissions > Workflow permissions to enable read and write permission.

Vercel setup

This is simple, just create a new project in vercel, disable the github integration and change the deploy script --project values.

Update on 15 Aug 2024 - Currently vercel supports python 3.9 deployment only on node.js 18.x (legacy build), not the default 20.x. The version can be changed in vercel settings.

Also, add a domain til.alvinsj.net in both vercel and cloudflare dns, e.g., cname til cname.vercel-dns.com.

Cleaning up SQLite schema

I downloaded the db but it needed some cleanup.

# Clean up records
DELETE from similarities;
DELETE from embeddings;
DELETE from til;

# This will drop all til_fts_* tables as well
DROP TABLE til_fts; 

# Recreate fts
CREATE VIRTUAL TABLE til_fts USING fts5(title, body);
INSERT INTO til_fts(title, body) SELECT title, body FROM til;

It's useful to test the build_database.py script locally.

$ conda create --name=alvinsj-til
$ conda activate alvinsj-til
$ conda install pip 
$ pip install -r requirements.txt
$ python build_database.py

References

  1. Github repo: https://github.com/simonw/til
  2. Datasette docs: https://datasette.io/plugins/datasette-publish-vercel

Related links

  1. SQLite on web: http://static.wiki
  2. Hosting SQLite databases on Github Pages: https://phiresky.github.io/blog/2021/hosting-sqlite-databases-on-github-pages/

Created 2023-12-08T19:53:59+08:00, updated 2024-08-15T18:11:50+02:00 · History · Edit