- Go 49.9%
- JavaScript 31.2%
- templ 11.4%
- CSS 6.7%
- Shell 0.4%
- Other 0.4%
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. |
||
|---|---|---|
| cmd | ||
| docs | ||
| internal | ||
| .gitignore | ||
| default.nix | ||
| flake.lock | ||
| flake.nix | ||
| go.mod | ||
| go.sum | ||
| README.md | ||
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:
- One stylesheet.
internal/ui/static/app.cssis 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. - One chrome.
ui.Layout(title, apps, current, summary)renders<head>, header and the app switcher. Each binary passes its own[]ui.Appand marks itselfcurrent, so "Library" and "Downloads" are the same nav from either side. - One component set.
ui.Card,ui.Chip,ui.ResultsGrid,ui.Pagerplus the status/avail label helpers. The downloader's history list will reuseui.Cardrather 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,
buildGoModuleto 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/downloaderis the job machinery ported fromrms/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 incmd/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
continueas literal text in a template block — the word "continue" appeared twice in the sidebar until it was replaced with a guard. go mod tidydrops the templ requirement if no.gofile imports it yet; generate first, then tidy.- A templ block cannot live inside a
.gofile:page.templ, notmain.go.