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

+9 -5
View File
@@ -14,8 +14,9 @@ var exportFormats = map[string]struct{ ext, contentType string }{
"txt": {"txt", "text/plain; charset=utf-8"},
}
// handleExport downloads a list's titles in rank order, one per line, with
// nothing else: no ranks, header row or metadata.
// handleExport downloads a list's titles, one per line, with nothing else:
// no ranks, header row or metadata. Line N is place #N, so an empty place
// is a blank line, and importing the file puts everything back where it was.
func (s *Server) handleExport(w http.ResponseWriter, r *http.Request) {
format := r.URL.Query().Get("format")
if format == "" {
@@ -35,9 +36,12 @@ func (s *Server) handleExport(w http.ResponseWriter, r *http.Request) {
s.serverError(w, r, err)
return
}
titles := make([]string, len(items))
for i, it := range items {
titles[i] = it.Title
var titles []string
for _, it := range items {
for len(titles) < it.Rank-1 {
titles = append(titles, "")
}
titles = append(titles, it.Title)
}
w.Header().Set("Content-Type", f.contentType)
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s.%s"`, l.Slug, f.ext))
+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) {