From e96bbec551c0388e972894b349413fa6ef607352 Mon Sep 17 00:00:00 2001 From: grm Date: Thu, 17 Sep 2026 21:29:44 +0300 Subject: Add custom fonts: upload WOFF2/WOFF/TTF/OTF files and pick them on the Design tab Fonts become a file kind of their own (sniffed from the bytes like images, served inline from /media), and the theme gets custom_font and custom_heading_font: a chosen file is declared as @font-face and put first in the stack, the built-in Font / Heading font choice behind it as the fallback, so there is no "custom" enum value and no invalid state. The pickers are plain selects with an upload input, no script. Fonts uploaded before this are reclassified by the migration. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01Sd8UPWrvyYCLj97JexNw3A --- internal/db/migrations/blog/00010_font_kind.sql | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 internal/db/migrations/blog/00010_font_kind.sql (limited to 'internal/db') diff --git a/internal/db/migrations/blog/00010_font_kind.sql b/internal/db/migrations/blog/00010_font_kind.sql new file mode 100644 index 0000000..cf741e4 --- /dev/null +++ b/internal/db/migrations/blog/00010_font_kind.sql @@ -0,0 +1,21 @@ +-- +goose Up +-- Fonts become a file kind of their own so the design page can offer them. +ALTER TABLE files DROP CONSTRAINT files_kind_check; +ALTER TABLE files ADD CONSTRAINT files_kind_check + CHECK (kind IN ('image', 'document', 'audio', 'video', 'font', 'archive', 'other')); +-- Fonts uploaded before this were stored as "other"; the magic bytes tell them +-- apart (the same signatures the Go sniffer trusts), and substring() reads +-- only that slice. +UPDATE files SET kind = 'font', content_type = CASE substring(data from 1 for 4) + WHEN '\x774f4632'::bytea THEN 'font/woff2' + WHEN '\x774f4646'::bytea THEN 'font/woff' + WHEN '\x4f54544f'::bytea THEN 'font/otf' + ELSE 'font/ttf' END +WHERE kind = 'other' + AND substring(data from 1 for 4) IN ('\x774f4632'::bytea, '\x774f4646'::bytea, '\x4f54544f'::bytea, '\x00010000'::bytea); + +-- +goose Down +UPDATE files SET kind = 'other', content_type = 'application/octet-stream' WHERE kind = 'font'; +ALTER TABLE files DROP CONSTRAINT files_kind_check; +ALTER TABLE files ADD CONSTRAINT files_kind_check + CHECK (kind IN ('image', 'document', 'audio', 'video', 'archive', 'other')); -- cgit v1.2.3