Phase 6 part 5, step 3: theme updates by pull request

The theme carries a MANIFEST of its files' SHA-256s. A site's Theme card
shows its copy's version against Supermarket's and any files changed by
hand; Update the theme opens a pull request that writes new and changed
files, removes retired ones, rebuilds, and lists what it replaces.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 15:30:48 -07:00
co-authored by Claude Opus 5.5
parent 2a605ac265
commit 7da7c5fd9c
9 changed files with 384 additions and 6 deletions
+45 -1
View File
@@ -4,7 +4,9 @@
package theme
import (
"crypto/sha256"
"embed"
"fmt"
"io/fs"
"sort"
"strconv"
@@ -26,8 +28,50 @@ const Name = "supermarket"
var files embed.FS
// Files are the theme's files: path (inside the theme) → content,
// VERSION included.
// VERSION and MANIFEST included.
func Files() map[string]string {
out := files0()
out["MANIFEST"] = Manifest(out)
return out
}
// Manifest lists each file's SHA-256 (VERSION and MANIFEST aside), so a
// site's copy can be checked for files changed by hand.
func Manifest(files map[string]string) string {
var b strings.Builder
for _, p := range sortedKeys(files) {
if p == "VERSION" || p == "MANIFEST" {
continue
}
fmt.Fprintf(&b, "%x %s\n", sha256.Sum256([]byte(files[p])), p)
}
return b.String()
}
// ParseManifest reads a MANIFEST: path → SHA-256 (hex).
func ParseManifest(m string) map[string]string {
out := map[string]string{}
for _, l := range strings.Split(m, "\n") {
if sum, p, ok := strings.Cut(l, " "); ok && p != "" {
out[p] = sum
}
}
return out
}
// Sum is a file's SHA-256, as in the manifest.
func Sum(content []byte) string { return fmt.Sprintf("%x", sha256.Sum256(content)) }
func sortedKeys(m map[string]string) []string {
var ks []string
for k := range m {
ks = append(ks, k)
}
sort.Strings(ks)
return ks
}
func files0() map[string]string {
out := map[string]string{"VERSION": strconv.Itoa(Version) + "\n"}
_ = fs.WalkDir(files, "files", func(p string, d fs.DirEntry, err error) error {
if err != nil || d.IsDir() {
+4
View File
@@ -133,6 +133,10 @@ disableKinds = ["taxonomy", "term", "RSS"]
func TestFiles(t *testing.T) {
fs := Files()
man := ParseManifest(fs["MANIFEST"])
if len(man) != len(fs)-2 || man["static/css/supermarket.css"] != Sum([]byte(fs["static/css/supermarket.css"])) {
t.Errorf("manifest: %d entries for %d files", len(man), len(fs))
}
if fs["VERSION"] != "1\n" || !strings.Contains(fs["README.md"], "| `hero` |") || !strings.Contains(LeadScript(), "window.leadPost") {
t.Error("files")
}