1
Fork 0

build a fulltext-searchable databose for the blog

This commit is contained in:
Jan-Erik Rediger 2022-04-22 22:44:09 +02:00
parent 9dcb4e9b14
commit 998794db4a
4 changed files with 34 additions and 2 deletions

2
.gitignore vendored
View file

@ -1,2 +1,2 @@
_site _site
.rake_tasks~ blog.db

View file

@ -1,5 +1,6 @@
SOURCE = /home/jer/git/fnordig.de/_site/ SOURCE = /home/jer/git/fnordig.de/_site/
DEST = /var/www/sites/fnordig.de/ DEST = /var/www/sites/fnordig.de/
DATABASE_PATH = blog.db
default: default:
rm -rf _site rm -rf _site
@ -18,10 +19,14 @@ serve: build
cd _site && http cd _site && http
.PHONY: serve .PHONY: serve
deploy: clean build deploy: clean build index
rsync -va --delete $(SOURCE) $(DEST) rsync -va --delete $(SOURCE) $(DEST)
.PHONY: deploy .PHONY: deploy
index:
DATABASE_PATH="$(DATABASE_PATH)" ./index.sh
.PHONY: index
clean: clean:
cobalt clean cobalt clean
.PHONY: clean .PHONY: clean

View file

@ -24,6 +24,8 @@ ignore:
- ext/ - ext/
- README.md - README.md
- Makefile - Makefile
- index.sh
- blog.db
syntax_highlight: syntax_highlight:
theme: "InspiredGitHub" theme: "InspiredGitHub"
assets: assets:

25
index.sh Executable file
View file

@ -0,0 +1,25 @@
#!/bin/bash
set -e
DATABASE_PATH="${DATABASE_PATH:-blog.db}"
sqlite3 -batch -bail "$DATABASE_PATH" "
CREATE TABLE IF NOT EXISTS [posts] (
[_id] TEXT PRIMARY KEY,
[_path] TEXT,
[text] TEXT,
[html] TEXT,
[permalink] TEXT,
[title] TEXT,
[published_date] TEXT,
[layout] TEXT,
[data] TEXT,
[excerpt] TEXT
);
PRAGMA journal_mode = WAL;
PRAGMA foreign_keys = ON;
" >/dev/null
markdown-to-sqlite "$DATABASE_PATH" posts _posts/*
sqlite-utils enable-fts --fts5 "$DATABASE_PATH" posts title text 2>/dev/null || true
sqlite-utils rebuild-fts "$DATABASE_PATH" posts