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:
+39
-3
@@ -15,7 +15,6 @@ import (
|
||||
"supermarket/internal/hugorepo"
|
||||
"supermarket/internal/profile"
|
||||
"supermarket/internal/sites"
|
||||
"supermarket/internal/theme"
|
||||
)
|
||||
|
||||
// siteRepo is a website with a Hugo repository, from the profile.
|
||||
@@ -101,8 +100,12 @@ func (s *Server) renderSites(w http.ResponseWriter, r *http.Request, errMsg stri
|
||||
cancel()
|
||||
}
|
||||
wc.Release()
|
||||
if raw, rerr := os.ReadFile(filepath.Join(wc.Dir, theme.Dir, "VERSION")); rerr == nil {
|
||||
data["Theme"] = strings.TrimSpace(string(raw))
|
||||
if ts := sites.ReadTheme(wc.Dir); ts.Has {
|
||||
data["Theme"] = ts
|
||||
var pr formsPR
|
||||
if ok, _ := s.DB.GetJSON(themePRKey(cur.Repo), &pr); ok {
|
||||
data["ThemePR"] = pr
|
||||
}
|
||||
data["Kinds"] = []string{"home", "about", "contact"}
|
||||
if p, _ := profile.Load(s.DB); p != nil {
|
||||
data["Products"] = p.Products
|
||||
@@ -399,3 +402,36 @@ func (n noListing) Open(name string) (http.File, error) {
|
||||
}
|
||||
return f, nil
|
||||
}
|
||||
|
||||
func themePRKey(repo string) string { return "sites:theme-pr:" + repo }
|
||||
|
||||
// sitesThemeUpdate opens the pull request that brings a site's copy of the
|
||||
// theme up to date.
|
||||
func (s *Server) sitesThemeUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
_, cur := s.currentSite(r)
|
||||
if cur == nil || cur.Repo == "" {
|
||||
s.renderSites(w, r, "Choose a website with a Hugo repository.")
|
||||
return
|
||||
}
|
||||
if s.gitea() == nil {
|
||||
s.renderSites(w, r, "Save a Gitea token under Settings → Search engines first.")
|
||||
return
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 10*time.Minute)
|
||||
defer cancel()
|
||||
pull, d, err := sites.UpdateTheme(ctx, s.applier(seoSite{Index: cur.Index, URL: cur.URL}))
|
||||
if err != nil {
|
||||
s.renderSites(w, r, err.Error())
|
||||
return
|
||||
}
|
||||
pr := formsPR{Number: pull.Number, URL: pull.HTMLURL, At: time.Now(), State: "open", Capture: strconv.Itoa(d.To)}
|
||||
if err := s.DB.PutJSON(themePRKey(cur.Repo), pr); err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, "/sites?site="+strconv.Itoa(cur.Index), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user