Give blog posts an optional table of contents
Blog posts -> Show contents (migration 043, off by default): with two or more headings, the post's headings sit in a sticky column beside it with the one being read lit (an IntersectionObserver, not a scroll listener), and fold out at the top on phones. Content-block headings now carry anchor ids, so a link can point at one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f59ab314e0
commit
92e7938b64
10 changed files with 264 additions and 44 deletions
|
|
@ -26,6 +26,7 @@ export const blogPosts = {
|
|||
text("excerpt"),
|
||||
text("cover_image"),
|
||||
text("cover_alt"),
|
||||
bool("show_contents"),
|
||||
date("published_on"),
|
||||
text("tags"),
|
||||
text("guest_author"),
|
||||
|
|
|
|||
10
server/src/migrations/043_blog_contents.sql
Normal file
10
server/src/migrations/043_blog_contents.sql
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
-- ═══════════════════════════════════════════════════════════════
|
||||
-- 043 A POST'S TABLE OF CONTENTS
|
||||
--
|
||||
-- Blog posts → "Show contents": list the post's headings beside it
|
||||
-- (a fold-out on phones), the one being read lit. Off unless an
|
||||
-- editor turns it on, since a short post doesn't need one.
|
||||
-- ═══════════════════════════════════════════════════════════════
|
||||
|
||||
ALTER TABLE blog_posts ADD COLUMN show_contents INTEGER NOT NULL DEFAULT 0
|
||||
CHECK (show_contents IN (0, 1));
|
||||
|
|
@ -99,6 +99,7 @@ blog.get("/blog/:id", (c) => {
|
|||
excerpt: row.excerpt,
|
||||
cover_image: row.cover_image,
|
||||
cover_alt: row.cover_alt,
|
||||
show_contents: row.show_contents === 1,
|
||||
published_on: row.published_on,
|
||||
tags: splitTags(row.tags),
|
||||
authors,
|
||||
|
|
|
|||
|
|
@ -462,6 +462,7 @@ tx(db, () => {
|
|||
cover_image: IMAGE,
|
||||
published_on: db.prepare(`SELECT date('now') AS d`).get().d,
|
||||
tags: "Test, Showcase",
|
||||
show_contents: 1,
|
||||
guest_author: "A Guest Author",
|
||||
guest_photo: IMAGE,
|
||||
is_published: 1,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue