Line numbers are places in import and export; fix stale scripts

Import: each row's place is its line number, so blank lines leave a
place empty; a fully numbered text file ("38. Title") or a Rank column
gives places directly, and repeated numbers take the next free place.
Entries are added at those places (existing ones there move down), the
review shows each row's #, and the room check covers the highest place.

Export writes a blank line for every empty place, so line N is #N and a
file round-trips.

Static files now carry an ETag and unversioned ones are revalidated on
every load. Scripts import each other without a ?v= tag, so browsers kept
an hour-old import.js (with the "null" bug) after an update.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
cdnutterandClaude Opus 5.5 committed 2026-10-08 14:43:53 -07:00
1 parent 88373176f2
commit 62fcf6b45d
7 files changed
+151 -72

No files matched your search

+26 -1
View File
@@ -321,20 +321,45 @@ func (s *Server) isHTTPS(r *http.Request) bool {
func (s *Server) staticHandler() http.Handler {
fsrv := http.FileServerFS(s.static)
etags := staticETags(s.static)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasSuffix(r.URL.Path, "/") {
s.notFound(w, r)
return
}
if tag, ok := etags[strings.TrimPrefix(r.URL.Path, "/")]; ok {
w.Header().Set("ETag", tag) // FileServer answers If-None-Match with 304
}
if r.URL.Query().Get("v") != "" {
w.Header().Set("Cache-Control", "public, max-age=31536000, immutable")
} else {
w.Header().Set("Cache-Control", "public, max-age=3600")
// Scripts load each other without a ?v= (import "./places.js"),
// so unversioned files are re-checked on every load; the ETag
// makes that a quick 304 until a new build changes them.
w.Header().Set("Cache-Control", "no-cache")
}
fsrv.ServeHTTP(w, r)
})
}
// staticETags fingerprints every embedded static file once at startup.
func staticETags(fsys fs.FS) map[string]string {
tags := map[string]string{}
fs.WalkDir(fsys, ".", func(p string, d fs.DirEntry, err error) error {
if err != nil || d.IsDir() {
return nil
}
b, err := fs.ReadFile(fsys, p)
if err != nil {
return nil
}
sum := sha256.Sum256(b)
tags[p] = `"` + hex.EncodeToString(sum[:8]) + `"`
return nil
})
return tags
}
func (s *Server) handleImage(w http.ResponseWriter, r *http.Request) {
name := r.PathValue("name")
if !imgcache.ValidName(name) {