Fixes from the first round of TEST.md

SEO: a domain property (sc-domain:) covers every subdomain, so the shop,
Gitea and forum were counted as the website. What ranks, the morning
check, the Monday report, keywords, change candidates and the audit's
traffic now read only the website's own host (with or without www).
The report keeps pages worth a proposal apart from "Waiting for your
yes", explains only moves past the thresholds, and says "places up/down".

Also:
- Feed summaries drop the posts' scripts and styles.
- Spend you log can't be negative.
- Test and check buttons can't be clicked twice while they run.
- Previews show the site's web fonts and icon sprites.
- Backups are read without leaving -wal/-shm files; deleting one removes
  them, and leftovers are swept at start.
- The Overview's setup flags a CRM that Hermes can't reach.
- Import now says what came in; adding a prospect that exists says so;
  prospects can be deleted.
- Signal tags and brief addresses keep accented letters (Ü → u).
- Page errors start with a capital; clearer messages for bad uploads,
  CRM retry and cancel, keywords, and the finished audit.
- The module you're in stays unfolded in the sidebar.
- A picked keyword can be unpicked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-24 06:31:42 -07:00
co-authored by Claude Opus 5.5
parent 3ddf716e71
commit c36f786ae9
52 changed files with 796 additions and 128 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ func TestAuditPage(t *testing.T) {
}
time.Sleep(50 * time.Millisecond)
}
if rec := do(h, http.MethodGet, "/seo/audit/status?site=0", nil, nil); rec.Header().Get("HX-Refresh") != "true" {
if rec := do(h, http.MethodGet, "/seo/audit/status?site=0", nil, nil); !strings.HasPrefix(rec.Header().Get("HX-Redirect"), "/seo/audit?site=0") {
t.Error("the status poll doesn't reload when done")
}
body := do(h, http.MethodGet, "/seo/audit", nil, nil).Body.String()
+8 -1
View File
@@ -187,10 +187,17 @@ func (s *Server) backupUpload(w http.ResponseWriter, r *http.Request) {
}
tmp.Close()
if err := backup.Check(tmp.Name()); err != nil {
s.renderBackups(w, r, hdr.Filename+" isn't a backup Supermarket can use: "+err.Error(), "")
s.renderBackups(w, r, hdr.Filename+" isn't a Supermarket backup: "+err.Error()+".", "")
return
}
// A backup downloaded from here keeps its note, not its whole name.
note := "uploaded " + strings.TrimSuffix(filepath.Base(hdr.Filename), ".db")
if b, ok := backup.Parse(filepath.Base(hdr.Filename)); ok {
note = "uploaded " + b.Kind
if b.Note != "" {
note = "uploaded " + b.Note
}
}
b, err := backup.Adopt(tmp.Name(), s.backupDir(), note, time.Now())
if err != nil {
s.serverError(w, err)
+1 -1
View File
@@ -104,7 +104,7 @@ func TestBackupUpload(t *testing.T) {
if !strings.Contains(body, "Uploaded as app-") || !strings.Contains(body, "-manual-uploaded-app-from-laptop.db") {
t.Errorf("upload: %s", body)
}
if body := upload("notes.txt", []byte("hello")); !strings.Contains(body, "isn&#39;t a backup Supermarket can use") {
if body := upload("notes.txt", []byte("hello")); !strings.Contains(body, "isn&#39;t a Supermarket backup") {
t.Errorf("bad upload: %s", body)
}
if bs, _ := backup.List(s.backupDir()); len(bs) != 1 {
+1 -1
View File
@@ -61,7 +61,7 @@ func TestBriefPages(t *testing.T) {
if !strings.Contains(body, "We tested it with 12 users.") || !strings.Contains(body, `name="claim" value="We tested it with 12 users."`) {
t.Error("the draft or its claim isn't shown")
}
if rec := postForm(h, "/seo/briefs/1/pr", url.Values{}); !strings.Contains(rec.Body.String(), "save a Gitea token") {
if rec := postForm(h, "/seo/briefs/1/pr", url.Values{}); !strings.Contains(rec.Body.String(), "Save a Gitea token") {
t.Errorf("pr without Gitea: %d", rec.Code)
}
s.Secrets.Set(map[string]string{secrets.GiteaToken: "tok"})
+6 -4
View File
@@ -358,6 +358,7 @@ func (s *Server) seoKeywordAction(w http.ResponseWriter, r *http.Request) {
}
back := "/seo/keywords?site=" + strconv.Itoa(site.Index) + "#k-" + strconv.FormatInt(id, 10)
now := time.Now()
var msg string
switch r.PathValue("action") {
case "top":
rs, rerr := s.researcher()
@@ -371,12 +372,13 @@ func (s *Server) seoKeywordAction(w http.ResponseWriter, r *http.Request) {
return
}
redirect(w, r, back, "top-read")
return
case "pick":
err = seo.SetKeywordStatus(s.DB, id, seo.KeywordPicked, now)
err, msg = seo.SetKeywordStatus(s.DB, id, seo.KeywordPicked, now), "keyword-picked"
case "dismiss":
err = seo.SetKeywordStatus(s.DB, id, seo.KeywordDismissed, now)
err, msg = seo.SetKeywordStatus(s.DB, id, seo.KeywordDismissed, now), "keyword-dismissed"
case "restore":
err = seo.SetKeywordStatus(s.DB, id, seo.KeywordNew, now)
err, msg = seo.SetKeywordStatus(s.DB, id, seo.KeywordNew, now), "keyword-back"
default:
http.NotFound(w, r)
return
@@ -385,5 +387,5 @@ func (s *Server) seoKeywordAction(w http.ResponseWriter, r *http.Request) {
s.renderKeywords(w, r, err.Error())
return
}
redirect(w, r, back, "saved")
redirect(w, r, back, msg)
}
+5 -5
View File
@@ -53,7 +53,7 @@ func TestContentPages(t *testing.T) {
t.Errorf("write with nothing selected: %d", rec.Code)
}
rec = postForm(h, "/content/"+id+"/items", url.Values{"action": {"write"}, "item": {"a"}})
if !strings.Contains(rec.Body.String(), "choose at least one channel") {
if !strings.Contains(rec.Body.String(), "Choose at least one channel") {
t.Errorf("write without channels:\n%s", rec.Body.String())
}
// No AI key: the provider's error is shown.
@@ -142,10 +142,10 @@ func TestScheduleFromInbox(t *testing.T) {
// A past time, or none, is refused.
past := time.Now().Add(-time.Hour).Format(dateTimeLocal)
if rec := postForm(h, "/drafts/"+id+"/schedule", url.Values{"when": {past}}); !strings.Contains(rec.Body.String(), "that time has passed") {
if rec := postForm(h, "/drafts/"+id+"/schedule", url.Values{"when": {past}}); !strings.Contains(rec.Body.String(), "That time has passed") {
t.Errorf("past time: %s", rec.Body.String())
}
if rec := postForm(h, "/drafts/"+id+"/schedule", url.Values{"when": {""}}); !strings.Contains(rec.Body.String(), "choose a date") {
if rec := postForm(h, "/drafts/"+id+"/schedule", url.Values{"when": {""}}); !strings.Contains(rec.Body.String(), "Choose a date") {
t.Errorf("no time: %s", rec.Body.String())
}
@@ -235,7 +235,7 @@ func TestRedditInInbox(t *testing.T) {
if d, _ := content.GetDraft(s.DB, mustID(id)); d.Title != "Jitsi 3 is out" || d.Content != "Edited" {
t.Errorf("saved: %+v", d)
}
if rec := postForm(h, "/drafts/"+id+"/save", url.Values{"title": {""}}); !strings.Contains(rec.Body.String(), "the title is empty") {
if rec := postForm(h, "/drafts/"+id+"/save", url.Values{"title": {""}}); !strings.Contains(rec.Body.String(), "The title is empty") {
t.Errorf("empty title: %s", rec.Body.String())
}
if rec := postForm(h, "/drafts/"+id+"/publish", nil); !strings.Contains(rec.Body.String(), "Reddit isn&#39;t connected") {
@@ -271,7 +271,7 @@ func TestWriteRedditNeedsSubreddit(t *testing.T) {
}
_ = s.Secrets.Set(map[string]string{secrets.AnthropicAPIKey: "k"})
rec := postForm(h, "/content/"+id+"/items", url.Values{"action": {"write"}, "item": {"a"}, "channel": {"reddit"}, "subreddit": {" "}})
if !strings.Contains(rec.Body.String(), "choose a subreddit") {
if !strings.Contains(rec.Body.String(), "Choose a subreddit") {
t.Errorf("write without subreddit: %s", rec.Body.String())
}
}
+20 -3
View File
@@ -100,6 +100,22 @@ func unreachableError(actions []crm.Action) string {
return ""
}
// crmBroken says whether the newest finished action failed because
// EspoCRM couldn't be reached (and nothing has got through since).
func crmBroken(actions []crm.Action) bool {
for _, a := range actions { // newest first
switch a.Status {
case crm.StatusDone:
return false
case crm.StatusFailed:
if connErr.MatchString(a.Error) {
return true
}
}
}
return false
}
// crmReach is an htmx fragment shown when Hermes couldn't reach EspoCRM.
// Hermes goes through the Core's MCP hub, which connects to EspoCRM with
// its own settings; checking EspoCRM from here tells the user which side
@@ -167,11 +183,12 @@ func (s *Server) crmAction(w http.ResponseWriter, r *http.Request) {
http.NotFound(w, r)
return
}
msg := ""
switch r.PathValue("action") {
case "retry":
err = crm.Retry(s.DB, id)
err, msg = crm.Retry(s.DB, id), "crm-retried"
case "cancel":
err = crm.Cancel(s.DB, id)
err, msg = crm.Cancel(s.DB, id), "crm-cancelled"
default:
http.NotFound(w, r)
return
@@ -184,6 +201,6 @@ func (s *Server) crmAction(w http.ResponseWriter, r *http.Request) {
s.serverError(w, err)
return
}
redirect(w, r, "/crm", "saved")
redirect(w, r, "/crm", msg)
}
}
+7
View File
@@ -16,6 +16,7 @@ import (
"supermarket/internal/bridge"
"supermarket/internal/content"
"supermarket/internal/core"
"supermarket/internal/crm"
"supermarket/internal/inventory"
"supermarket/internal/profile"
"supermarket/internal/secrets"
@@ -146,6 +147,12 @@ func (s *Server) dashboard(w http.ResponseWriter, r *http.Request) {
{Label: "Hermes bridge", Done: last != nil, Link: "/settings/core",
Detail: ifElse(last != nil, "Last check-in "+ago(atOf(last)), "Hermes hasn't checked in yet")},
}
if actions, err := crm.List(s.DB, 50); err == nil && len(actions) > 0 {
broken := crmBroken(actions)
steps = append(steps, step{Label: "CRM through Hermes", Done: !broken, Link: "/crm",
Detail: ifElse(broken, "Hermes couldn't reach EspoCRM: see the CRM queue for what to send your Core's admin",
"Hermes reaches EspoCRM")})
}
queued, _ := content.CountDrafts(s.DB)
scheduled, _ := content.ListDrafts(s.DB, 1000, content.StatusScheduled)
+87
View File
@@ -0,0 +1,87 @@
package web
import (
"bytes"
"os"
"path"
"path/filepath"
"regexp"
"strings"
)
// A preview page is sandboxed, so it has an origin of its own, and a
// browser won't let it draw <use href="icons.svg#name"> from a separate
// file: that counts as cross-origin. inlineSprites copies each local sprite
// file the page uses into the page itself, and points the <use> elements
// at the copy, so icons show as they do on the live site.
var (
useHref = regexp.MustCompile(`(<use\b[^>]*?\b(?:xlink:)?href=")([^"#:]+\.svg)#([^"]+)"`)
svgOpen = regexp.MustCompile(`(?is)^.*?<svg\b[^>]*>`)
svgClose = regexp.MustCompile(`(?is)</svg>\s*$`)
bodyOpen = regexp.MustCompile(`(?i)<body\b[^>]*>`)
maxSprite = int64(2 << 20)
)
// inlineSprites rewrites a page served from dir at urlPath (the page's
// path within the preview, e.g. "/about/").
func inlineSprites(page []byte, dir, urlPath string) []byte {
base := urlPath
if !strings.HasSuffix(base, "/") {
base = path.Dir(base) + "/"
}
sprites := map[string]string{} // file (within the preview) → its symbols
var order []string
out := useHref.ReplaceAllFunc(page, func(m []byte) []byte {
g := useHref.FindSubmatch(m)
ref := string(g[2])
file := path.Clean(path.Join(base, ref))
if strings.HasPrefix(ref, "/") {
file = path.Clean(ref)
}
if _, ok := sprites[file]; !ok {
sprites[file] = readSprite(dir, file)
order = append(order, file)
}
if sprites[file] == "" {
return m
}
return []byte(string(g[1]) + "#" + string(g[3]) + `"`)
})
var inline strings.Builder
for _, f := range order {
if s := sprites[f]; s != "" {
inline.WriteString(`<svg xmlns="http://www.w3.org/2000/svg" style="display:none" aria-hidden="true">` + s + `</svg>`)
}
}
if inline.Len() == 0 {
return page
}
loc := bodyOpen.FindIndex(out)
if loc == nil {
return page
}
return bytes.Join([][]byte{out[:loc[1]], []byte(inline.String()), out[loc[1]:]}, nil)
}
// readSprite is the inside of an SVG file in the preview, or "" if it
// isn't one (or isn't inside the preview).
func readSprite(dir, file string) string {
p := filepath.Join(dir, filepath.FromSlash(file))
if rel, err := filepath.Rel(dir, p); err != nil || strings.HasPrefix(rel, "..") {
return ""
}
st, err := os.Stat(p)
if err != nil || st.IsDir() || st.Size() > maxSprite {
return ""
}
raw, err := os.ReadFile(p)
if err != nil {
return ""
}
s := svgOpen.ReplaceAllString(string(raw), "")
if s == string(raw) {
return ""
}
return svgClose.ReplaceAllString(s, "")
}
+26
View File
@@ -0,0 +1,26 @@
package web
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestInlineSprites(t *testing.T) {
dir := t.TempDir()
os.MkdirAll(filepath.Join(dir, "images"), 0o755)
os.WriteFile(filepath.Join(dir, "images", "icons.svg"), []byte(`<?xml version="1.0"?><svg xmlns="http://www.w3.org/2000/svg"><symbol id="cloud"><path d="M0 0"/></symbol></svg>`), 0o644)
os.WriteFile(filepath.Join(dir, "secret.svg"), []byte(`<svg><symbol id="x"/></svg>`), 0o644)
page := []byte(`<html><body class="a"><svg><use href="../images/icons.svg#cloud"></use></svg><svg><use href="images/missing.svg#y"></use></svg><svg><use href="../../../secret.svg#x"></use></svg></body></html>`)
out := string(inlineSprites(page, dir, "/about/"))
if !strings.Contains(out, `<use href="#cloud">`) || !strings.Contains(out, `<body class="a"><svg xmlns="http://www.w3.org/2000/svg" style="display:none" aria-hidden="true"><symbol id="cloud">`) {
t.Errorf("not inlined: %s", out)
}
if !strings.Contains(out, `images/missing.svg#y`) {
t.Errorf("a missing sprite should be left alone: %s", out)
}
if string(inlineSprites([]byte(`<body><p>no icons</p></body>`), dir, "/")) != `<body><p>no icons</p></body>` {
t.Error("a page without sprites changed")
}
}
+9 -4
View File
@@ -197,6 +197,8 @@ func (s *Server) prospectAction(w http.ResponseWriter, r *http.Request) {
if action == "verify" {
msg = "verified"
}
case "company/delete", "contact/delete":
err, msg = prospects.Delete(s.DB, kind, id), "deleted"
case "company/reconsider", "contact/reconsider":
err, msg = prospects.Reconsider(s.DB, kind, id), "reconsidered"
case "company/suppress":
@@ -303,29 +305,32 @@ func (s *Server) prospectAdd(w http.ResponseWriter, r *http.Request) {
fail("Give a company, a person, or both.")
return
}
added := false
if d.CompanyID == 0 && hasCompany {
if strings.TrimSpace(d.Company.Name) == "" {
fail("Give the company's name.")
return
}
id, _, err := prospects.AddCompany(s.DB, d.Company, now)
id, isNew, err := prospects.AddCompany(s.DB, d.Company, now)
if err != nil {
fail(addError(err))
return
}
d.CompanyID = id
d.CompanyID, added = id, isNew
}
if hasPerson {
d.Contact.CompanyID = d.CompanyID
if _, _, err := prospects.AddContact(s.DB, d.Contact, now); err != nil {
_, isNew, err := prospects.AddContact(s.DB, d.Contact, now)
if err != nil {
fail(addError(err))
return
}
added = added || isNew
} else if d.CompanyID != 0 && !hasCompany {
fail("Give the person's name or email.")
return
}
redirect(w, r, "/prospects", "prospect-added")
redirect(w, r, "/prospects", ifElse(added, "prospect-added", "prospect-exists"))
}
func addError(err error) string {
+25 -7
View File
@@ -89,6 +89,9 @@ type seoSite struct {
Last *seo.SyncResult
}
// scope narrows the site's Search Console property to the website's host.
func (st seoSite) scope() seo.Scope { return seo.NewScope(st.Property, st.URL) }
func (s *Server) seoSites() []seoSite {
p, _ := profile.Load(s.DB)
if p == nil {
@@ -290,7 +293,7 @@ func (s *Server) seoPage(w http.ResponseWriter, r *http.Request) {
data, cur := s.seoBase(r)
data["Path"], data["Days"] = "/seo", seo.RanksDays
if cur != nil {
ranks, err := seo.WhatRanks(s.DB, cur.Property)
ranks, err := seo.WhatRanks(s.DB, cur.scope())
if err != nil {
s.serverError(w, err)
return
@@ -300,16 +303,22 @@ func (s *Server) seoPage(w http.ResponseWriter, r *http.Request) {
s.render(w, r, "seo", page{Title: "SEO", Nav: "seo/ranks", Data: data})
}
// pagePath shows a page's address without the site, for tables.
// pagePath shows a page's address without the site, for tables. A page on
// the www. form of the site keeps its host, so it doesn't look like the
// same page as the one without.
func pagePath(u string) string {
p, err := url.Parse(u)
if err != nil || p.Path == "" {
return u
}
out := p.Path
if p.RawQuery != "" {
return p.Path + "?" + p.RawQuery
out += "?" + p.RawQuery
}
return p.Path
if h := strings.ToLower(p.Hostname()); strings.HasPrefix(h, "www.") {
out = h + out
}
return out
}
// seoCurrent is the site the request asks for (?site=), or the first.
@@ -347,7 +356,7 @@ func (s *Server) seoCheckPage(w http.ResponseWriter, r *http.Request) {
data, cur := s.seoBase(r)
data["Path"] = "/seo/check"
if cur != nil {
c, err := seo.MorningCheck(s.DB, cur.Property, seo.LoadSettings(s.DB))
c, err := seo.MorningCheck(s.DB, cur.scope(), seo.LoadSettings(s.DB))
if err != nil {
s.serverError(w, err)
return
@@ -413,7 +422,7 @@ func (s *Server) seoReportWrite(w http.ResponseWriter, r *http.Request) {
// writeReport builds and stores a site's report, and emails it if the
// settings say so (and email is set up).
func (s *Server) writeReport(ctx context.Context, site seoSite, email bool) (*seo.Report, error) {
rep, err := seo.Weekly(s.DB, site.Property, time.Now())
rep, err := seo.Weekly(s.DB, site.scope(), time.Now())
if err != nil || rep == nil {
return rep, err
}
@@ -590,7 +599,16 @@ func (s *Server) seoAuditStatus(w http.ResponseWriter, r *http.Request) {
return
}
if a == nil || a.Status != "running" {
w.Header().Set("HX-Refresh", "true")
// Reload without the "Auditing…" message the page was opened with.
msg := "audited"
if a != nil && a.Status == "failed" {
msg = ""
}
target := "/seo/audit?site=" + strconv.Itoa(cur.Index)
if msg != "" {
target += "&msg=" + msg
}
w.Header().Set("HX-Redirect", target)
}
w.Write([]byte(""))
}
+54 -1
View File
@@ -16,6 +16,8 @@ import (
"strings"
"sync"
"time"
"unicode"
"unicode/utf8"
"supermarket/internal/api/reddit"
"supermarket/internal/api/twitter"
@@ -484,8 +486,9 @@ func (s *Server) render(w http.ResponseWriter, r *http.Request, name string, p p
p.NewProspects = s.newProspects()
p.Drafts = s.outreachDrafts()
if p.Flash == "" {
p.Flash = flashes[r.URL.Query().Get("msg")]
p.Flash = flashText(r.URL.Query())
}
p.Error = sentence(p.Error)
w.Header().Set("Content-Type", "text/html; charset=utf-8")
if err := t.ExecuteTemplate(w, "layout.html", p); err != nil {
s.Log.Error("render", "page", name, "err", err)
@@ -525,6 +528,10 @@ var flashes = map[string]string{
"proposed": "Proposed: read each one, edit it if you like, then say yes or no.",
"approved": "Approved: Supermarket is making the pull request; it shows here in a minute.",
"declined": "Declined.",
"keyword-picked": "Picked. Write its brief when you're ready.",
"keyword-dismissed": "Dismissed: it's under Dismissed if you change your mind.",
"keyword-back": "Back among the candidates.",
"audited": "The audit is done.",
"auditing": "Auditing. It reads up to 300 pages politely, so it takes a few minutes; this page updates when it's done.",
"no-data": "There isn't two weeks of Search Console data yet.",
"reddit-connected": "Reddit is connected.",
@@ -536,10 +543,14 @@ var flashes = map[string]string{
"suppressed": "Added to the suppression list.",
"unsuppressed": "Taken off the suppression list.",
"prospect-added": "Added. Review it below.",
"crm-retried": "Queued again: Hermes tries it on its next run.",
"crm-cancelled": "Taken back: Hermes won't do it.",
"prospect-exists": "Already there: nothing new was added. It's in the list below.",
"outcome": "Outcome recorded.",
"discovering": "Searching. It takes a few minutes; new companies appear in Review, tagged with this signal.",
"rules-refreshed": "Rules refreshed.",
"imported": "Imported.",
"imported-counts": "Imported: %d new steps in the funnel, %d new people to review, %d new on the suppression list.",
"hunter-done": "Hunter.io search done: the result is on the card.",
"verified": "Checked with Hunter.io: the result is on each person.",
"drafted-outreach": "Drafted. Read it, edit it, then queue it to send.",
@@ -561,6 +572,48 @@ var flashes = map[string]string{
"unscheduled": "Back in Posts: edit it, then publish or schedule it again.",
}
// sentence starts a message with a capital letter: errors from deeper
// down are written in lower case, to be wrapped.
func sentence(msg string) string {
r, n := utf8.DecodeRuneInString(msg)
if n == 0 || !unicode.IsLower(r) {
return msg
}
return string(unicode.ToUpper(r)) + msg[n:]
}
// flashText is the message a redirect asked for (?msg=), from the fixed
// list. A message with %d verbs takes its numbers from n1, n2… (digits
// only), so nothing but a number can be put into it from the address.
func flashText(q url.Values) string {
msg := flashes[q.Get("msg")]
if n := strings.Count(msg, "%d"); n > 0 {
args := make([]any, n)
for i := range args {
v, _ := strconv.Atoi(q.Get("n" + strconv.Itoa(i+1)))
args[i] = v
}
msg = fmt.Sprintf(msg, args...)
}
return msg
}
// redirectCounts redirects with a message that has numbers in it.
func redirectCounts(w http.ResponseWriter, r *http.Request, path, msg string, counts ...int) {
base, frag, hasFrag := strings.Cut(path, "#")
for i, c := range counts {
sep := "?"
if strings.Contains(base, "?") {
sep = "&"
}
base += sep + "n" + strconv.Itoa(i+1) + "=" + strconv.Itoa(c)
}
if hasFrag {
base += "#" + frag
}
redirect(w, r, base, msg)
}
func redirect(w http.ResponseWriter, r *http.Request, path, msg string) {
if msg != "" {
// The message goes in the query, before any #fragment.
+1 -1
View File
@@ -470,7 +470,7 @@ func (s *Server) importSource(w http.ResponseWriter, r *http.Request) {
s.renderSignals(w, r, "Importing from "+source+": "+err.Error())
return
}
redirect(w, r, "/signals#campaigns", "imported")
redirectCounts(w, r, "/signals#campaigns", "imported-counts", res.Events, res.Prospects, res.Suppressed)
}
// runImport imports from one tool, if its key is saved. It returns nil, nil
+21 -3
View File
@@ -6,6 +6,7 @@ import (
"net/http"
"net/url"
"os"
"path"
"path/filepath"
"strconv"
"strings"
@@ -344,9 +345,11 @@ func (s *Server) sitesPreviewDelete(w http.ResponseWriter, r *http.Request) {
// pages, scripts and all, but whatever a branch holds mustn't be able to
// act on Supermarket: sandbox gives each page an origin of its own, so
// its requests to the app are cross-site (and refused), and nothing is
// sent anywhere else (no analytics from previews).
// sent anywhere else (no analytics from previews). Stylesheets and fonts
// may come from elsewhere, as web fonts do, so the page looks like the
// live one; scripts may not.
const previewCSP = "sandbox allow-scripts allow-popups allow-popups-to-escape-sandbox; default-src 'self'; " +
"img-src 'self' data: https:; media-src 'self' https:; font-src 'self' data:; style-src 'self' 'unsafe-inline'; " +
"img-src 'self' data: https:; media-src 'self' https:; font-src 'self' data: https:; style-src 'self' 'unsafe-inline' https:; " +
"script-src 'self' 'unsafe-inline'; connect-src 'none'; form-action 'none'; frame-ancestors 'none'"
// previewServe serves a built preview.
@@ -381,7 +384,22 @@ func (s *Server) previewServe(w http.ResponseWriter, r *http.Request) {
h.Set("Content-Security-Policy", previewCSP)
h.Set("Cache-Control", "no-store")
prefix := strings.TrimSuffix(previewPrefix(site, slug), "/")
http.StripPrefix(prefix, http.FileServer(noListing{http.Dir(s.previewDir(cur.Repo, slug))})).ServeHTTP(w, r)
dir := s.previewDir(cur.Repo, slug)
// A page gets the site's icon sprites inlined (see inlineSprites).
if rest := strings.TrimPrefix(r.URL.Path, prefix); rest != r.URL.Path && !strings.Contains(rest, "..") {
file := rest
if strings.HasSuffix(file, "/") {
file += "index.html"
}
if strings.HasSuffix(file, ".html") {
if raw, err := os.ReadFile(filepath.Join(dir, filepath.FromSlash(path.Clean(file)))); err == nil {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Write(inlineSprites(raw, dir, rest))
return
}
}
}
http.StripPrefix(prefix, http.FileServer(noListing{http.Dir(dir)})).ServeHTTP(w, r)
}
// noListing serves files, and folders only through their index.html.
+1 -1
View File
@@ -284,7 +284,7 @@ func TestSitePageBuilder(t *testing.T) {
}
// The claim must be confirmed before the pull request.
if body := postForm(h, "/sites/pages/1/pr", form(good)).Body.String(); !strings.Contains(body, "confirm or remove this claim first") || len(pulls) != 0 {
if body := postForm(h, "/sites/pages/1/pr", form(good)).Body.String(); !strings.Contains(body, "Confirm or remove this claim first") || len(pulls) != 0 {
t.Errorf("unconfirmed: %s", body)
}
body = postForm(h, "/sites/pages/1/pr", form(good, "We tested it with our own team.")).Body.String()
+1
View File
@@ -464,3 +464,4 @@ input[type="color"] { height: 2.6rem; padding: 0.25rem; cursor: pointer; }
.nav-sum { margin-left: auto; }
.nav-row:not(.collapsed) .nav-sum { display: none; }
.nav .nav-toggle:active { transform: none; }
.nav .nav-toggle:disabled, .nav .nav-toggle:disabled:hover { opacity: 0.35; cursor: default; background: transparent; color: hsl(var(--muted-foreground)); }
+8 -1
View File
@@ -161,7 +161,14 @@
total.title = sum + " waiting";
total.hidden = false;
}
set(sub, btn, sub.hasAttribute("data-current") || state[sub.dataset.subnav] === true);
if (sub.hasAttribute("data-current")) {
// The module you're in stays open: its chevron shows it, but doesn't fold it.
set(sub, btn, true);
btn.disabled = true;
btn.title = "Open while you're in it";
return;
}
set(sub, btn, state[sub.dataset.subnav] === true);
btn.addEventListener("click", function () {
var open = sub.hidden;
set(sub, btn, open);
+2 -2
View File
@@ -27,7 +27,7 @@
<span class="help">Supermarket runs in Docker: for a server on this computer use <code>http://host.docker.internal:11434</code>, and use an IP address rather than a <code>.local</code> name.</span></label>
<datalist id="servers">{{range .Servers}}<option value="{{.BaseURL}}">{{.Name}}</option>{{end}}</datalist>
{{if .Servers}}<p class="help">Found by CoreDesktop's <code>configure ai-servers</code>: {{range $i, $s := .Servers}}{{if $i}}, {{end}}{{$s.Name}} ({{$s.BaseURL}}){{end}}.</p>{{end}}
<button type="button" class="secondary" hx-get="/settings/ai/models" hx-include="#base_url" hx-target="#model-list">List its models</button>
<button hx-disabled-elt="this" type="button" class="secondary" hx-get="/settings/ai/models" hx-include="#base_url" hx-target="#model-list" hx-indicator="#listing-models">List its models</button> <span id="listing-models" class="htmx-indicator">Asking the server…</span>
<div id="model-list"></div>
{{range .Keys}}{{if eq .Group "openai"}}{{template "key-field" (dict "F" . "Set" (index $set .Name))}}{{end}}{{end}}
</section>
@@ -55,7 +55,7 @@
<div class="actions">
<button type="submit">Save</button>
<button type="button" class="secondary" hx-post="/settings/ai/test" hx-include="#ai-form" hx-target="#test-result" hx-indicator="#testing">Test</button>
<button hx-disabled-elt="this" type="button" class="secondary" hx-post="/settings/ai/test" hx-include="#ai-form" hx-target="#test-result" hx-indicator="#testing">Test</button>
<span id="testing" class="htmx-indicator">Asking the model…</span>
</div>
<p class="help">Test uses the provider and model in the form, and the keys already saved: save a new key before testing it.</p>
+1 -1
View File
@@ -17,7 +17,7 @@
<h2>Hermes bridge</h2>
<p>Hermes, CoreDesktop's agent, is the only thing that talks to your Core's MCP hub. It reaches Supermarket through the socket <code>{{.MCPSocket}}</code>; other agents, such as Claude Code, use <code>{{.MCPURL}}</code> with the MCP token.</p>
{{with .Last}}
<p class="ok">Hermes last checked in {{ago .At}}{{if .Note}}: “{{.Note}}”{{end}}.</p>
<p class="ok">Hermes last checked in {{ago .At}}.{{if .Note}} It said: “{{.Note}}”{{end}}</p>
{{if .MCPHubTools}}
<details><summary>It can use {{len .MCPHubTools}} tools from the MCP hub</summary>
<ul class="pills">{{range .MCPHubTools}}<li><span class="pill">{{.}}</span></li>{{end}}</ul>
+1 -1
View File
@@ -58,7 +58,7 @@
<h3>Check</h3>
<p class="small">Signs in to both servers and looks up your domain's SPF, DKIM and DMARC records, which decide whether outreach reaches the inbox. Nothing is sent.</p>
<div class="row">
<button type="button" class="secondary small" hx-post="/settings/email/test" hx-target="#email-test" hx-indicator="#testing-email">Check the settings</button>
<button hx-disabled-elt="this" type="button" class="secondary small" hx-post="/settings/email/test" hx-target="#email-test" hx-indicator="#testing-email">Check the settings</button>
<form method="post" action="/settings/email/send-test" data-busy="Sending…"><button type="submit" class="secondary small">Send a test email to {{or $s.FromAddress "the From address"}}</button></form>
<span id="testing-email" class="htmx-indicator">Checking…</span>
</div>
+2
View File
@@ -58,6 +58,7 @@
{{else}}
<form method="post" action="/prospects/company/{{.ID}}/reconsider"><input type="hidden" name="tab" value="{{$tab}}"><input type="hidden" name="filter" value="{{$d.Signal}}"><button type="submit" class="secondary small">Reconsider</button></form>
{{end}}
<form method="post" action="/prospects/company/{{.ID}}/delete" data-confirm="Delete {{.Name}}{{if .Contacts}} and its people{{end}}? Their steps in the funnel go too, and a CRM action not yet done is taken back. Anything already in EspoCRM stays there."><input type="hidden" name="tab" value="{{$tab}}"><input type="hidden" name="filter" value="{{$d.Signal}}"><button type="submit" class="link small">Delete</button></form>
</div>
{{end}}
</div>
@@ -141,6 +142,7 @@
{{else}}
<form method="post" action="/prospects/contact/{{$p.ID}}/reconsider"><input type="hidden" name="tab" value="{{$tab}}"><input type="hidden" name="filter" value="{{$d.Signal}}"><button type="submit" class="secondary small">Reconsider</button></form>
{{end}}
<form method="post" action="/prospects/contact/{{$p.ID}}/delete" data-confirm="Delete {{$p.Name}}? Their steps in the funnel go too, and a CRM action not yet done is taken back. Anything already in EspoCRM stays there."><input type="hidden" name="tab" value="{{$tab}}"><input type="hidden" name="filter" value="{{$d.Signal}}"><button type="submit" class="link small">Delete</button></form>
</div>
{{end}}
</div>
+1 -1
View File
@@ -46,7 +46,7 @@
<label>Gitea's address <input name="gitea_url" value="{{.GiteaURL}}" placeholder="https://gitea.example.com"></label>
{{template "key-field" (dict "F" .GiteaKey "Set" .GiteaSet)}}
{{if .GiteaSet}}
<button type="button" class="secondary small" hx-post="/settings/search/test/gitea" hx-target="#test-gitea" hx-indicator="#testing-gitea">Test</button>
<button hx-disabled-elt="this" type="button" class="secondary small" hx-post="/settings/search/test/gitea" hx-target="#test-gitea" hx-indicator="#testing-gitea">Test</button>
<span id="testing-gitea" class="htmx-indicator">Checking…</span>
<div id="test-gitea"></div>
{{end}}
+2 -1
View File
@@ -42,7 +42,8 @@
{{if ne .Status "picked"}}<form method="post" action="/seo/keywords/{{.ID}}/pick"><button type="submit" class="small">Pick this one</button></form>
{{else}}<form method="post" action="/seo/briefs" data-busy="Writing the brief…"><input type="hidden" name="site_url" value="{{.Site}}"><input type="hidden" name="keyword" value="{{.Keyword}}"><button type="submit" class="small">Write the brief</button></form>{{end}}
{{if eq .Status "dismissed"}}<form method="post" action="/seo/keywords/{{.ID}}/restore"><button type="submit" class="secondary small">Bring back</button></form>
{{else}}<form method="post" action="/seo/keywords/{{.ID}}/dismiss"><button type="submit" class="secondary small">Dismiss</button></form>{{end}}
{{else}}{{if eq .Status "picked"}}<form method="post" action="/seo/keywords/{{.ID}}/restore"><button type="submit" class="secondary small">Unpick</button></form>{{end}}
<form method="post" action="/seo/keywords/{{.ID}}/dismiss"><button type="submit" class="secondary small">Dismiss</button></form>{{end}}
</div>
</div>
{{if .Top}}
+7 -2
View File
@@ -33,8 +33,13 @@
<h2>3. Waiting for your yes</h2>
{{range .Waiting}}
<p><a href="{{.Page}}" target="_blank" rel="noopener noreferrer">{{pagePath .Page}}</a><br><span class="small">{{.Why}}</span></p>
{{else}}<p class="help">Nothing this week.</p>{{end}}
<p class="help">Say yes or no to each on <a href="/seo/changes?site={{$d.Current.Index}}">Changes</a>: a yes opens a pull request.</p>
{{else}}<p class="help">Nothing is waiting: no change has been proposed.</p>{{end}}
{{if .Waiting}}<p class="help">Say yes or no to each on <a href="/seo/changes?site={{$d.Current.Index}}">Changes</a>: a yes opens a pull request.</p>{{end}}
{{with .Candidates}}
<h3>Worth a proposal</h3>
{{range .}}<p><a href="{{.Page}}" target="_blank" rel="noopener noreferrer">{{pagePath .Page}}</a><br><span class="small">{{.Why}}</span></p>{{end}}
<p class="help"><em>Propose changes</em> on <a href="/seo/changes?site={{$d.Current.Index}}">Changes</a> writes new wording for pages like these.</p>
{{end}}
</section>
{{else}}
<section class="card empty"><p>No report yet. It's written on Monday once there are two weeks of data, or now with <em>Write it now</em>.</p></section>
+2 -2
View File
@@ -12,7 +12,7 @@
<span class="help">If your organization has projects, the ID of the one to read. Leave empty to read the whole organization.</span></label>
{{end}}
{{if .Set}}
<button type="button" class="secondary small" hx-post="/settings/sources/test/{{.ID}}" hx-target="#test-{{.ID}}" hx-indicator="#testing-{{.ID}}">Test</button>
<button hx-disabled-elt="this" type="button" class="secondary small" hx-post="/settings/sources/test/{{.ID}}" hx-target="#test-{{.ID}}" hx-indicator="#testing-{{.ID}}">Test</button>
<span id="testing-{{.ID}}" class="htmx-indicator">Checking…</span>
<div id="test-{{.ID}}"></div>
{{end}}
@@ -36,7 +36,7 @@
</label>
</fieldset>
{{if .Set}}
<button type="button" class="secondary small" hx-post="/settings/sources/test/hunter" hx-target="#test-hunter" hx-indicator="#testing-hunter">Test</button>
<button hx-disabled-elt="this" type="button" class="secondary small" hx-post="/settings/sources/test/hunter" hx-target="#test-hunter" hx-indicator="#testing-hunter">Test</button>
<span id="testing-hunter" class="htmx-indicator">Checking…</span>
<div id="test-hunter"></div>
{{end}}
+2 -2
View File
@@ -11,7 +11,7 @@
<p class="help">Sites read: {{if .Sites}}{{range $i, $s := .Sites}}{{if $i}}, {{end}}<code>{{$s}}</code>{{end}}{{else}}none yet: add your websites (and their Plausible site, if it differs from the domain) to the <a href="/settings/profile">profile</a>{{end}}.</p>
{{if .PlausibleSet}}
<div class="row">
<button type="button" class="secondary small" hx-post="/settings/tracking/test/plausible" hx-target="#test-plausible" hx-indicator="#testing-plausible">Test</button>
<button hx-disabled-elt="this" type="button" class="secondary small" hx-post="/settings/tracking/test/plausible" hx-target="#test-plausible" hx-indicator="#testing-plausible">Test</button>
<button type="submit" class="secondary small" formaction="/settings/tracking/run/plausible" formnovalidate>Import now</button>
<span id="testing-plausible" class="htmx-indicator">Checking…</span>
</div>
@@ -35,7 +35,7 @@ metadata[utm_content] = optional: which message or post</pre>
</details>
{{if .StripeSet}}
<div class="row">
<button type="button" class="secondary small" hx-post="/settings/tracking/test/stripe" hx-target="#test-stripe" hx-indicator="#testing-stripe">Test</button>
<button hx-disabled-elt="this" type="button" class="secondary small" hx-post="/settings/tracking/test/stripe" hx-target="#test-stripe" hx-indicator="#testing-stripe">Test</button>
<button type="submit" class="secondary small" formaction="/settings/tracking/run/stripe" formnovalidate>Sync now</button>
<span id="testing-stripe" class="htmx-indicator">Checking…</span>
</div>