codefloe/forgejo-codefloe
Watch
4
12
Fork
You've already forked forgejo-codefloe
0

feat(ui): preload the Inter font when a CodeFloe theme is active #215

Merged
pat-s merged 1 commit from feat/preload-inter-font into v16.0/forgejo-codefloe 2026-10-02 10:02:40 +00:00
Owner

Closes #195.

Motivation

The CodeFloe themes render with self-hosted Inter, but the browser only discovers inter-latin.*.woff2 after it has downloaded and parsed index.css.
On a cold load text first paints in the fallback font and then swaps, a visible layout shift on every first visit.

Changes

  • templates/base/head.tmpl: add a single {{template "base/codefloe_head" .}} hook before the stylesheets.
  • templates/base/codefloe_head.tmpl: when ThemeName starts with codefloe-, emit <link rel="preload" as="font" type="font/woff2" crossorigin> for the Latin Inter file.
  • modules/templates/codefloe_fonts.go: CodefloeFontPreload finds the content-hashed inter-latin.<hash>.woff2 in assets/fonts of the public asset FS, once per process. No webpack manifest is needed. If the file is missing, or a stale build left several, it returns nothing and no preload is emitted.
  • modules/templates/helper.go: register CodefloeFontPreload.
  • README.md: add a Font preload row.

Only the Latin subset is preloaded; the other subsets keep loading on demand by unicode-range.

Verification

  • Unit test for the file-name lookup.
  • Built frontend and a sqlite backend and ran a fresh instance: with codefloe-auto the head contains <link rel="preload" href="/assets/fonts/inter-latin.4f2981d8.woff2" ...>, matching the URL index.css references; with forgejo-auto no preload is emitted.
  • In headless Chromium the font is requested exactly once (the preload is reused by the @font-face) and there is no "preloaded but not used" console warning.
  • make lint-go (pinned toolchain) and prek pass.
Closes #195. ## Motivation The CodeFloe themes render with self-hosted Inter, but the browser only discovers `inter-latin.*.woff2` after it has downloaded and parsed `index.css`. On a cold load text first paints in the fallback font and then swaps, a visible layout shift on every first visit. ## Changes - `templates/base/head.tmpl`: add a single `{{template "base/codefloe_head" .}}` hook before the stylesheets. - `templates/base/codefloe_head.tmpl`: when `ThemeName` starts with `codefloe-`, emit `<link rel="preload" as="font" type="font/woff2" crossorigin>` for the Latin Inter file. - `modules/templates/codefloe_fonts.go`: `CodefloeFontPreload` finds the content-hashed `inter-latin.<hash>.woff2` in `assets/fonts` of the public asset FS, once per process. No webpack manifest is needed. If the file is missing, or a stale build left several, it returns nothing and no preload is emitted. - `modules/templates/helper.go`: register `CodefloeFontPreload`. - `README.md`: add a `Font preload` row. Only the Latin subset is preloaded; the other subsets keep loading on demand by `unicode-range`. ## Verification - Unit test for the file-name lookup. - Built frontend and a sqlite backend and ran a fresh instance: with `codefloe-auto` the head contains `<link rel="preload" href="/assets/fonts/inter-latin.4f2981d8.woff2" ...>`, matching the URL `index.css` references; with `forgejo-auto` no preload is emitted. - In headless Chromium the font is requested exactly once (the preload is reused by the `@font-face`) and there is no "preloaded but not used" console warning. - `make lint-go` (pinned toolchain) and `prek` pass.
pat-s force-pushed feat/preload-inter-font from 6f4071a00e
Some checks failed
testing / test-unit (pull_request) Has been cancelled
testing / test-e2e (1/2) (pull_request) Has been cancelled
testing / test-e2e (2/2) (pull_request) Has been cancelled
testing / test-pgsql (1/4) (pull_request) Has been cancelled
testing / test-pgsql (2/4) (pull_request) Has been cancelled
testing / test-pgsql (3/4) (pull_request) Has been cancelled
testing / test-pgsql (4/4) (pull_request) Has been cancelled
testing / backend-checks (pull_request) Has been cancelled
testing / frontend-checks (pull_request) Has been cancelled
to d2ff5a503c
Some checks failed
testing / frontend-checks (pull_request) Successful in 2m14s
testing / backend-checks (pull_request) Successful in 5m16s
testing / test-pgsql (4/4) (pull_request) Has been cancelled
testing / test-e2e (2/2) (pull_request) Has been cancelled
testing / test-e2e (1/2) (pull_request) Has been cancelled
testing / test-pgsql (1/4) (pull_request) Has been cancelled
testing / test-pgsql (2/4) (pull_request) Has been cancelled
testing / test-unit (pull_request) Has been cancelled
testing / test-pgsql (3/4) (pull_request) Has been cancelled
2026-10-02 09:19:13 +00:00
Compare
pat-s scheduled this pull request to auto merge when all checks succeed 2026-10-02 09:19:24 +00:00
pat-s force-pushed feat/preload-inter-font from d2ff5a503c
Some checks failed
testing / frontend-checks (pull_request) Successful in 2m14s
testing / backend-checks (pull_request) Successful in 5m16s
testing / test-pgsql (4/4) (pull_request) Has been cancelled
testing / test-e2e (2/2) (pull_request) Has been cancelled
testing / test-e2e (1/2) (pull_request) Has been cancelled
testing / test-pgsql (1/4) (pull_request) Has been cancelled
testing / test-pgsql (2/4) (pull_request) Has been cancelled
testing / test-unit (pull_request) Has been cancelled
testing / test-pgsql (3/4) (pull_request) Has been cancelled
to 046e02ee71
All checks were successful
testing / test-pgsql (2/4) (pull_request) Successful in 5m48s
testing / frontend-checks (pull_request) Successful in 2m23s
testing / backend-checks (pull_request) Successful in 8m50s
testing / test-pgsql (1/4) (pull_request) Successful in 8m19s
testing / test-e2e (1/2) (pull_request) Successful in 4m57s
testing / test-unit (pull_request) Successful in 7m31s
testing / test-pgsql (3/4) (pull_request) Successful in 7m13s
testing / test-e2e (2/2) (pull_request) Successful in 4m45s
testing / test-pgsql (4/4) (pull_request) Successful in 8m56s
issue-labels / backporting (pull_request_target) Has been skipped
milestone / set (pull_request_target) Has been skipped
2026-10-02 09:30:10 +00:00
Compare
pat-s merged commit 35bad38b5d into v16.0/forgejo-codefloe 2026-10-02 10:02:40 +00:00
pat-s deleted branch feat/preload-inter-font 2026-10-02 10:02:41 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
codefloe/forgejo-codefloe!215
No description provided.