Phase 1, part 4: promote the company's own products

- Content lists the company first, at /content/own: its products from
  the profile (always there to pick from), its own feeds (a new profile
  field for the blog, news and releases), and new or updated pages from
  its websites' sitemaps, with each page's title and description.
- Drafts from it are kind "product" (utm_campaign=product), filed under
  the company's name, and prompted to promote the company's own work
  without unsupported claims; on Reddit, in the makers' voice, with a
  warning that self-promotion is often restricted.

This completes Phase 1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-20 14:42:37 -07:00
co-authored by Claude Opus 5.5
parent 0e34f574b7
commit cd24f2a06d
20 changed files with 685 additions and 30 deletions
+64 -7
View File
@@ -11,9 +11,11 @@ import (
"supermarket/internal/ai"
"supermarket/internal/api/reddit"
"supermarket/internal/api/sitemap"
"supermarket/internal/content"
"supermarket/internal/fetcher"
"supermarket/internal/inventory"
"supermarket/internal/models"
"supermarket/internal/profile"
)
@@ -24,6 +26,8 @@ const maxPerItem = 10
type contentRow struct {
Entry inventory.Entry
Own bool
Name string
Sources []string
Waiting int
LastChecked time.Time
@@ -40,10 +44,23 @@ func (s *Server) contentIndex(w http.ResponseWriter, r *http.Request) {
s.serverError(w, err)
return
}
rows := make([]contentRow, 0, len(entries))
p, err := profile.Load(s.DB)
if err != nil {
s.serverError(w, err)
return
}
own := content.OwnEntry(p)
ownLast, _ := content.LastChecked(s.DB, own.Name)
ownSources := fetcher.Sources(own)
if len(p.Products) > 0 {
ownSources = append([]string{plural(len(p.Products), "product")}, ownSources...)
}
rows := make([]contentRow, 0, len(entries)+1)
rows = append(rows, contentRow{Entry: *own, Own: true, Name: ifElse(p.Name != "", p.Name, "Your company"),
Sources: ownSources, Waiting: counts[own.Name], LastChecked: ownLast})
for _, e := range entries {
last, _ := content.LastChecked(s.DB, e.Name)
rows = append(rows, contentRow{Entry: e, Sources: fetcher.Sources(&e),
rows = append(rows, contentRow{Entry: e, Name: e.Name, Sources: fetcher.Sources(&e),
Waiting: counts[strings.ToLower(e.Name)], LastChecked: last})
}
s.render(w, r, "content", page{Title: "Content", Nav: "content", Data: map[string]any{"Rows": rows}})
@@ -56,6 +73,10 @@ type channelChoice struct {
type entryPage struct {
Entry *inventory.Entry
Own bool // the company's own products, feeds and pages
Base string // the page's address: /content/<id> or /content/own
Name string // what to call the entry
Products []content.Item
Sources []string
Items []content.Item
ShowDismissed bool
@@ -72,6 +93,18 @@ type entryPage struct {
}
func (s *Server) loadEntry(w http.ResponseWriter, r *http.Request) *inventory.Entry {
if r.PathValue("id") == "own" {
p, err := profile.Load(s.DB)
if err != nil {
s.serverError(w, err)
return nil
}
if err := content.SyncProducts(s.DB, p); err != nil {
s.serverError(w, err)
return nil
}
return content.OwnEntry(p)
}
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
if err != nil {
http.NotFound(w, r)
@@ -93,6 +126,19 @@ func (s *Server) entryData(e *inventory.Entry, showDismissed bool) (*entryPage,
if err != nil {
return nil, err
}
// Products are always there to pick from; they're listed on their own.
var products []content.Item
if content.IsOwn(e) {
rest := items[:0]
for _, it := range items {
if it.Source == models.SourceProduct {
products = append(products, it)
} else {
rest = append(rest, it)
}
}
items = rest
}
last, err := content.LastChecked(s.DB, e.Name)
if err != nil {
return nil, err
@@ -117,7 +163,11 @@ func (s *Server) entryData(e *inventory.Entry, showDismissed bool) (*entryPage,
}
}
}
return &entryPage{Subreddits: subs, Entry: e, Sources: fetcher.Sources(e), Items: items, ShowDismissed: showDismissed,
base, name := fmt.Sprintf("/content/%d", e.ID), e.Name
if content.IsOwn(e) {
base, name = "/content/own", ifElse(p.Name != "", p.Name, "Your company")
}
return &entryPage{Own: content.IsOwn(e), Base: base, Name: name, Products: products, Subreddits: subs, Entry: e, Sources: fetcher.Sources(e), Items: items, ShowDismissed: showDismissed,
LastChecked: last, Since: since, Channels: chans, ProfileSet: p.IsSet()}, nil
}
@@ -131,7 +181,7 @@ func (s *Server) contentEntry(w http.ResponseWriter, r *http.Request) {
s.serverError(w, err)
return
}
s.render(w, r, "content-entry", page{Title: e.Name, Nav: "content", Data: d})
s.render(w, r, "content-entry", page{Title: d.Name, Nav: "content", Data: d})
}
func (s *Server) contentFetch(w http.ResponseWriter, r *http.Request) {
@@ -147,7 +197,11 @@ func (s *Server) contentFetch(w http.ResponseWriter, r *http.Request) {
}
ctx, cancel := context.WithTimeout(r.Context(), 90*time.Second)
defer cancel()
res := s.fetcher().Fetch(ctx, e, since)
f := s.fetcher()
if content.IsOwn(e) {
f.Sitemap = sitemap.New("Supermarket/" + s.Version + " (sitemap reader)")
}
res := f.Fetch(ctx, e, since)
n, err := content.SaveItems(s.DB, res.Items)
if err != nil {
s.serverError(w, err)
@@ -167,7 +221,7 @@ func (s *Server) contentFetch(w http.ResponseWriter, r *http.Request) {
return
}
d.Fetched, d.NewItems, d.Errors, d.Skipped = true, n, res.Errors, res.Skipped
s.render(w, r, "content-entry", page{Title: e.Name, Nav: "content", Data: d})
s.render(w, r, "content-entry", page{Title: d.Name, Nav: "content", Data: d})
}
// contentItems handles the item list's buttons: dismiss, restore, write.
@@ -182,13 +236,16 @@ func (s *Server) contentItems(w http.ResponseWriter, r *http.Request) {
}
ids := r.PostForm["item"]
back := fmt.Sprintf("/content/%d", e.ID)
if content.IsOwn(e) {
back = "/content/own"
}
showErr := func(msg string) {
d, err := s.entryData(e, r.PostForm.Get("dismissed") == "1")
if err != nil {
s.serverError(w, err)
return
}
s.render(w, r, "content-entry", page{Title: e.Name, Nav: "content", Error: msg, Data: d})
s.render(w, r, "content-entry", page{Title: d.Name, Nav: "content", Error: msg, Data: d})
}
if len(ids) == 0 {
showErr("Select at least one item first.")