diff options
| author | grm <grm@eyesin.space> | 2026-09-17 22:54:19 +0300 |
|---|---|---|
| committer | grm <grm@eyesin.space> | 2026-09-17 22:54:19 +0300 |
| commit | ad30b38759dc222a7137598559998acbd0c06740 (patch) | |
| tree | ee6f00b03a32420dd70211ade20684697b325086 /internal/web/theme.go | |
| parent | 9d3ab1b781a712b73311d2f2b0b822ae02de99ff (diff) | |
| download | blogspace-ad30b38759dc222a7137598559998acbd0c06740.tar.gz blogspace-ad30b38759dc222a7137598559998acbd0c06740.tar.bz2 blogspace-ad30b38759dc222a7137598559998acbd0c06740.zip | |
Add Fira Code as a built-in font choice
The variable face (v6.2, OFL, licence alongside) is bundled in static/ and
declared as @font-face whenever the text or heading font is "fira"; the
stack falls back through Fira Mono, Menlo and Consolas to Courier.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Sd8UPWrvyYCLj97JexNw3A
Diffstat (limited to 'internal/web/theme.go')
| -rw-r--r-- | internal/web/theme.go | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/internal/web/theme.go b/internal/web/theme.go index 53e48c5..676a01e 100644 --- a/internal/web/theme.go +++ b/internal/web/theme.go @@ -25,8 +25,8 @@ type Theme struct { LinkUnderline string `json:"link_underline"` // always | hover | never ContentStyle string `json:"content_style"` // card | flat ContentPadding string `json:"content_padding"` // normal | compact | roomy - Font string `json:"font"` // sans | serif | mono - HeadingFont string `json:"heading_font"` // same | sans | serif | mono + Font string `json:"font"` // sans | serif | mono | fira (Fira Code, bundled in static/) + HeadingFont string `json:"heading_font"` // same | sans | serif | mono | fira FontSize string `json:"font_size"` // small | normal | large // Uploaded fonts (file uuids or ""): when set, the blog is typeset in the // file and Font/HeadingFont are the stack readers see until it loads, or @@ -176,8 +176,8 @@ func (t *Theme) normalize() { t.LinkUnderline = pick(t.LinkUnderline, "always", "hover", "never") t.ContentStyle = pick(t.ContentStyle, "card", "flat") t.ContentPadding = pick(t.ContentPadding, "normal", "compact", "roomy") - t.Font = pick(t.Font, "sans", "serif", "mono") - t.HeadingFont = pick(t.HeadingFont, "same", "sans", "serif", "mono") + t.Font = pick(t.Font, "sans", "serif", "mono", "fira") + t.HeadingFont = pick(t.HeadingFont, "same", "sans", "serif", "mono", "fira") t.FontSize = pick(t.FontSize, "normal", "small", "large") t.CustomFont = fileID(t.CustomFont) t.CustomHeadingFont = fileID(t.CustomHeadingFont) @@ -410,10 +410,16 @@ func fontStack(name string) string { return `Georgia, "Times New Roman", Times, serif` case "mono": return `"Courier New", Courier, monospace` + case "fira": + return `"Fira Code", "Fira Mono", Menlo, Consolas, "Courier New", monospace` } return `"Helvetica Neue", Helvetica, Arial, sans-serif` } +// UsesFira says whether the bundled Fira Code face must be declared: the +// only built-in choice that is a web font rather than a system stack. +func (t Theme) UsesFira() bool { return t.Font == "fira" || t.HeadingFont == "fira" } + // Helpers used by the CSS template. The @font-face families are named for // their role, so a stack is the uploaded font first and the built-in choice as // its fallback. @@ -516,6 +522,9 @@ func (t Theme) HeaderImageMaxHeight() string { } var themeCSS = template.Must(template.New("theme").Funcs(template.FuncMap{"sub": func(a, b int) int { return a - b }}).Parse(` +{{- if .UsesFira}} +@font-face { font-family:"Fira Code"; src:url(/static/FiraCode-VF.woff2) format("woff2"); font-weight:300 700; font-display:swap; } +{{- end}} {{- if .CustomFont}} @font-face { font-family:"BlogFont"; src:url(/media/{{.CustomFont}}); font-display:swap; } {{- end}} |
