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.")
+43
View File
@@ -2,7 +2,9 @@ package web
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"strconv"
"strings"
@@ -273,3 +275,44 @@ func TestWriteRedditNeedsSubreddit(t *testing.T) {
t.Errorf("write without subreddit: %s", rec.Body.String())
}
}
func TestOwnContentPage(t *testing.T) {
var site *httptest.Server
site = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/sitemap.xml":
fmt.Fprintf(w, `<urlset><url><loc>%s/blog/launch</loc><lastmod>%s</lastmod></url></urlset>`, site.URL, time.Now().UTC().Format("2006-01-02"))
case "/blog/launch":
w.Write([]byte(`<title>We launched Acme Mail</title><meta name="description" content="Hosted email.">`))
default:
http.NotFound(w, r)
}
}))
defer site.Close()
s, h := newTestServer(t, nil)
_ = profile.Save(s.DB, &profile.Profile{Name: "Acme", Description: "Widgets.",
Products: []profile.Product{{Name: "Acme Mail", Description: "Hosted email.", URL: "https://acme.example/mail"}},
Websites: []profile.Website{{URL: site.URL}}})
body := do(h, http.MethodGet, "/content", nil, nil).Body.String()
if !strings.Contains(body, `href="/content/own">Acme</a>`) || !strings.Contains(body, "1 product, new pages on your websites") {
t.Errorf("content index:\n%s", body)
}
body = do(h, http.MethodGet, "/content/own", nil, nil).Body.String()
for _, want := range []string{"<h1>Acme <span class=\"badge product\">", `value="product:acme-mail"`, `action="/content/own/fetch"`,
`href="/profile">Edit profile`, `action="/content/own/items"`} {
if !strings.Contains(body, want) {
t.Errorf("own page lacks %q", want)
}
}
rec := postForm(h, "/content/own/fetch", nil)
if body := rec.Body.String(); !strings.Contains(body, "1 new item") || !strings.Contains(body, "We launched Acme Mail") {
t.Errorf("fetch:\n%s", body)
}
// Writing goes through the same form; without an AI key, its error shows.
rec = postForm(h, "/content/own/items", url.Values{"action": {"write"}, "item": {"product:acme-mail"}, "channel": {"linkedin"}})
if !strings.Contains(rec.Body.String(), "Anthropic API key") {
t.Errorf("write: %s", rec.Body.String())
}
}
+2 -1
View File
@@ -126,7 +126,8 @@ func (s *Server) redditViews(ctx context.Context, drafts []content.Draft) map[in
historyRead = true
}
info, _ := content.GetSubreddit(s.DB, d.Target)
check := content.RedditCheck{Target: d.Target, HasLink: d.SourceURL != "", Info: info, History: history, Now: time.Now()}
check := content.RedditCheck{Target: d.Target, HasLink: d.SourceURL != "", Info: info, History: history, Now: time.Now(),
Promo: d.Kind == content.KindProduct}
if tags != nil {
check.Own = tags.Own
check.OwnLink = tags.Own(d.SourceURL) || tags.HasOwnLink(d.Content)
+1
View File
@@ -48,6 +48,7 @@ func profileFromForm(r *http.Request) *profile.Profile {
Voice: f.Get("voice"),
Avoid: profile.Lines(f.Get("avoid")),
Keywords: profile.Lines(f.Get("keywords")),
Feeds: profile.Lines(f.Get("feeds")),
Targets: profile.Targets{
Industries: profile.Lines(f.Get("industries")),
CompanySizes: profile.Lines(f.Get("company_sizes")),
+1
View File
@@ -67,6 +67,7 @@ details.card[open] > summary { margin-bottom: 0.75rem; }
.badge.partner { background: #e0f2f7; color: var(--cyan-dark); }
.badge.competitor { background: #fbe4f0; color: var(--magenta); }
.badge.watch { background: #eef0f4; color: var(--muted); }
.badge.product { background: #e7f6ed; color: var(--ok); }
.tabs { display: flex; gap: 0.25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs a { padding: 0.45rem 0.9rem; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; text-transform: capitalize; }
+31 -9
View File
@@ -5,16 +5,18 @@
<a href="/content/published">Published</a>
</nav>
<div class="heading">
<h1>{{.Entry.Name}} <span class="badge {{.Entry.Relationship}}">{{.Entry.Relationship}}</span></h1>
<h1>{{.Name}} <span class="badge {{.Entry.Relationship}}">{{.Entry.Relationship}}</span></h1>
<div class="buttons">
<form method="post" action="/content/{{.Entry.ID}}/fetch" data-busy="Fetching…">
<form method="post" action="{{.Base}}/fetch" data-busy="Fetching…">
<button type="submit" {{if not .Sources}}disabled{{end}}>Fetch new</button>
</form>
<a class="button secondary" href="/inventory/{{.Entry.ID}}">Edit entry</a>
{{if .Own}}<a class="button secondary" href="/profile">Edit profile</a>{{else}}<a class="button secondary" href="/inventory/{{.Entry.ID}}">Edit entry</a>{{end}}
</div>
</div>
<p class="lede">
{{if .Sources}}Reads {{join .Sources ", "}}.{{else}}This entry has no sources yet: add an X handle, hashtags, a YouTube channel or RSS feeds to it.{{end}}
{{if .Own}}Posts that promote your own work: pick a product, or fetch your feeds and new pages on your websites.
{{if .Sources}}Reads {{join .Sources ", "}}.{{else}}Add your blog and release feeds, and your websites, to the <a href="/profile">profile</a> to fetch them.{{end}}
{{else}}{{if .Sources}}Reads {{join .Sources ", "}}.{{else}}This entry has no sources yet: add an X handle, hashtags, a YouTube channel or RSS feeds to it.{{end}}{{end}}
Last fetched {{ago .LastChecked}}; the next fetch looks for posts since {{.Since.Local.Format "2 Jan 15:04"}}.
</p>
@@ -28,13 +30,32 @@
{{end}}
<nav class="tabs">
<a href="/content/{{.Entry.ID}}" {{if not .ShowDismissed}}aria-current="page"{{end}}>Items</a>
<a href="/content/{{.Entry.ID}}?dismissed=1" {{if .ShowDismissed}}aria-current="page"{{end}}>Dismissed</a>
<a href="{{.Base}}" {{if not .ShowDismissed}}aria-current="page"{{end}}>Items</a>
<a href="{{.Base}}?dismissed=1" {{if .ShowDismissed}}aria-current="page"{{end}}>Dismissed</a>
</nav>
{{if .Items}}
<form method="post" action="/content/{{.Entry.ID}}/items" data-busy-on="write" data-busy="Writing drafts…">
{{if or .Items (and .Products (not .ShowDismissed))}}
<form method="post" action="{{.Base}}/items" data-busy-on="write" data-busy="Writing drafts…">
{{if .ShowDismissed}}<input type="hidden" name="dismissed" value="1">{{end}}
{{if and .Products (not .ShowDismissed)}}
<h2>Products</h2>
<ul class="items">
{{range .Products}}
<li class="item{{if .Used}} used{{end}}">
<label class="check">
<input type="checkbox" name="item" value="{{.ID}}">
<span>
<strong>{{.Title}}</strong>{{if .Used}} <span class="meta"><em>drafted before</em></span>{{end}}
<span class="body">{{truncate 300 .Body}}</span>
{{if .URL}}<a href="{{.URL}}" target="_blank" rel="noopener noreferrer">Open</a>{{end}}
</span>
</label>
</li>
{{end}}
</ul>
{{if .Items}}<h2>News from your feeds and sites</h2>{{end}}
{{end}}
{{if .Items}}
<ul class="items">
{{range .Items}}
<li class="item{{if .Used}} used{{end}}">
@@ -50,6 +71,7 @@
</li>
{{end}}
</ul>
{{end}}
{{if .ShowDismissed}}
<div class="actions"><button type="submit" name="action" value="restore" class="secondary">Restore selected</button></div>
@@ -83,7 +105,7 @@
</form>
{{else}}
<section class="card empty">
<p>{{if .ShowDismissed}}Nothing dismissed.{{else}}No items yet. Fetch to see what {{.Entry.Name}} has been up to.{{end}}</p>
<p>{{if .ShowDismissed}}Nothing dismissed.{{else if .Own}}No products or news yet: add products, feeds or websites to your <a href="/profile">profile</a>, then fetch.{{else}}No items yet. Fetch to see what {{.Name}} has been up to.{{end}}</p>
</section>
{{end}}
{{end}}{{end}}
+7 -1
View File
@@ -13,9 +13,15 @@
<tbody>
{{range .Rows}}
<tr>
<td><a href="/content/{{.Entry.ID}}">{{.Entry.Name}}</a></td>
{{if .Own}}
<td><a href="/content/own">{{.Name}}</a> <span class="muted small">your own work</span></td>
<td><span class="badge product">product</span></td>
<td>{{if .Sources}}{{join .Sources ", "}}{{else}}<span class="muted">none: add products, websites or feeds to your <a href="/profile">profile</a></span>{{end}}</td>
{{else}}
<td><a href="/content/{{.Entry.ID}}">{{.Name}}</a></td>
<td><span class="badge {{.Entry.Relationship}}">{{.Entry.Relationship}}</span></td>
<td>{{if .Sources}}{{join .Sources ", "}}{{else}}<span class="muted">none: <a href="/inventory/{{.Entry.ID}}">add some</a></span>{{end}}</td>
{{end}}
<td>{{if .Waiting}}{{.Waiting}}{{end}}</td>
<td>{{ago .LastChecked}}</td>
</tr>
+2
View File
@@ -85,6 +85,8 @@
</fieldset>
{{end}}
<p class="help">To remove a website, clear its address.</p>
<label>Feeds of your own <textarea name="feeds" rows="3" placeholder="https://example.com/blog/index.xml">{{lines .P.Feeds}}</textarea>
<span class="help">Your blog, news and release feeds (RSS or Atom; a GitHub or Gitea repository's <code>releases.atom</code> works), one per line. Content → Your company writes posts from them, from your products, and from new pages in your sites' sitemaps.</span></label>
</section>
{{with .P.Accounts}}