Library viewer: Go + templ + htmx, one module with a shared UI layer
  • Go 49.9%
  • JavaScript 31.2%
  • templ 11.4%
  • CSS 6.7%
  • Shell 0.4%
  • Other 0.4%
Find a file
RMS 5cbd9c746a fix(downloader): match a pre-existing archive by gallery id, not just [slug]
The second run of a gallery that is already downloaded finds nothing
"fresh" - every file is in the before-snapshot - so it fell through to the
[slug] match. Only the custom site extractors put [slug] in a filename;
nhentai writes "701414 [artist] title.cbz", so the run reported no archive
while the .cbz sat in the tree, and promote stayed impossible.

Match on the gallery id from the URL (last path segment) before giving up,
keep [slug] as the earlier preference, and take the only archive in the tree
as a last resort. Seen on the re-run of https://nhentai.net/g/701414.
2026-12-03 18:04:53 -06:00
cmd fix(downloader): match a pre-existing archive by gallery id, not just [slug] 2026-12-03 18:04:53 -06:00
docs docs: record that the translation-layer fix landed 2026-10-25 19:57:10 -06:00
internal feat(viewer): sort chips and an order toggle 2026-11-25 18:42:38 -06:00
.gitignore chore: add node_modules and test-results to .gitignore 2026-10-29 21:36:39 -06:00
default.nix build: pin the real vendorHash and commit the flake lock 2026-10-25 17:42:23 -06:00
flake.lock build: pin the real vendorHash and commit the flake lock 2026-10-25 17:42:23 -06:00
flake.nix fix(library): parse the index as TSV, tolerating bare quotes 2026-10-25 17:32:00 -06:00
go.mod feat: one module, two binaries, one shared UI layer 2026-10-18 14:32:39 -06:00
go.sum feat: one module, two binaries, one shared UI layer 2026-10-18 14:32:39 -06:00
README.md feat(downloader): port the gallery-dl download UI into the module 2026-10-18 15:42:13 -06:00

library-viewer

One Go module, two binaries, sharing a presentation layer. The point of the layout is that the tools read as one product — same header, same app switcher, same stylesheet — while staying separate processes with separate trust levels.

cmd/viewer        browse/search the library catalogue (read-only)      :8098
cmd/downloader    gallery download UI (write-capable), ported from gallery-dl-ui
internal/ui       THE shared layer: chrome, components, stylesheet
internal/query    the search language (a port of the viewer's lib.js, same test cases)
internal/library  reads the libfind index and resolves pool paths

How the UI is shared (the bit worth knowing)

Three mechanisms, deliberately small:

  1. One stylesheet. internal/ui/static/app.css is embedded (//go:embed static) and served by every binary at /static/app.css. Design tokens are CSS custom properties at the top; a style change lands in both tools on the next build, and neither can drift. Assets are vendored — htmx is a committed file, not a CDN reference, because this is an offline LAN.
  2. One chrome. ui.Layout(title, apps, current, summary) renders <head>, header and the app switcher. Each binary passes its own []ui.App and marks itself current, so "Library" and "Downloads" are the same nav from either side.
  3. One component set. ui.Card, ui.Chip, ui.ResultsGrid, ui.Pager plus the status/avail label helpers. The downloader's history list will reuse ui.Card rather than grow a near-copy.

What is not shared: data access and anything with side effects. The viewer is read-only by construction (it reads the index and serves files); the downloader is write-capable, so it keeps its own service, state directory and blast radius. A wedged download must not take browsing down.

Why Go + templ (+ htmx)

  • Server-rendered pages mean every filter is a URL: shareable, bookmarkable, works with JavaScript off. That replaces the client-side history plumbing in the old viewer.
  • htmx is layered on for the live-search feel — the search box swaps just the grid and pushes the URL — which is ~40 KB vendored and no build step, versus a framework and a bundler.
  • One binary to deploy, buildGoModule to package it, and the OPDS/Komga endpoints for external readers can live in the same process later.

templ is a pre-processor: edit *.templ, run templ generate, and the generated *_templ.go is committed so a plain go build needs no codegen tool.

Running

go test ./...                                   # query semantics (ported from the vitest cases)
go run ./cmd/viewer -index <index.tsv> -thumbs <thumb-root> -addr 127.0.0.1:8098
go run ./cmd/downloader -addr 127.0.0.1:8097

Defaults point at the deployment paths (/mnt/storage/other/library-index/…).

Status

  • Viewer: server-rendered list/search/facets/paging with real URLs, thumbnails and read-only archive serving (used by the in-browser reader and plain downloads).
  • The ledger merge, the reader, and the downloader port are done; OPDS is not.
  • cmd/downloader is the job machinery ported from rms/gallery-dl-ui (job service, SSE progress, log on demand, clear-finished, verify-before-skip), with its page rebuilt on the shared chrome and its own rules layered in cmd/downloader/assets/downloader.css. The old repo stays until this one is deployed and verified in its place.

Traps found while building this

  • templ renders a bare continue as literal text in a template block — the word "continue" appeared twice in the sidebar until it was replaced with a guard.
  • go mod tidy drops the templ requirement if no .go file imports it yet; generate first, then tidy.
  • A templ block cannot live inside a .go file: page.templ, not main.go.