Phase 5 part 4: landing pages per buying signal
Each signal's page lists its landing pages with their Gitea status, live address and 30-day visitors from Plausible, and builds a new one. Pages can be duplicated as variants (B, C…, with their own utm_content), taken off the site through a pull request that deletes the file, or have their pull request closed. The scorecard counts live pages. Schema 23. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+132
-6
@@ -285,8 +285,9 @@ var mdLink = regexp.MustCompile(`\]\(([^)\s]+)\)`)
|
||||
// the site has (an error otherwise); fields the type isn't known to use,
|
||||
// and links to pages the site doesn't have, are warnings. With a campaign,
|
||||
// links to the site get utm_campaign (and utm_medium=landing) so visits
|
||||
// and sign-ups count for the signal.
|
||||
func Check(c *Catalog, sectionsYAML, siteURL, campaign string) (*Checked, error) {
|
||||
// and sign-ups count for the signal, and utm_content when given (which
|
||||
// variant of the page they came from).
|
||||
func Check(c *Catalog, sectionsYAML, siteURL, campaign, content string) (*Checked, error) {
|
||||
var doc yaml.Node
|
||||
if err := yaml.Unmarshal([]byte(sectionsYAML), &doc); err != nil {
|
||||
return nil, fmt.Errorf("the sections aren't valid YAML: %v", err)
|
||||
@@ -341,7 +342,7 @@ func Check(c *Catalog, sectionsYAML, siteURL, campaign string) (*Checked, error)
|
||||
out.Warnings = append(out.Warnings, fmt.Sprintf("Section %d (%s) links to %s, which isn't a page on the site.", i+1, t.Name, target))
|
||||
}
|
||||
if own && campaign != "" {
|
||||
n.Value = tag(n.Value, campaign)
|
||||
n.Value = tag(n.Value, campaign, content)
|
||||
}
|
||||
case "type", "style", "id", "image", "photo", "icon", "logImage", "video":
|
||||
default:
|
||||
@@ -353,7 +354,7 @@ func Check(c *Catalog, sectionsYAML, siteURL, campaign string) (*Checked, error)
|
||||
out.Warnings = append(out.Warnings, fmt.Sprintf("Section %d (%s) links to %s, which isn't a page on the site.", i+1, t.Name, target))
|
||||
}
|
||||
if own && campaign != "" {
|
||||
return strings.Replace(m, "("+link+")", "("+tag(link, campaign)+")", 1)
|
||||
return strings.Replace(m, "("+link+")", "("+tag(link, campaign, content)+")", 1)
|
||||
}
|
||||
return m
|
||||
})
|
||||
@@ -437,8 +438,9 @@ func ownPath(link string, site *url.URL) (string, bool) {
|
||||
return p, true
|
||||
}
|
||||
|
||||
// tag adds the campaign to a link (tags already there win).
|
||||
func tag(link, campaign string) string {
|
||||
// tag adds the campaign (and content) to a link. Tags already there win,
|
||||
// except utm_content, which follows the page's variant.
|
||||
func tag(link, campaign, content string) string {
|
||||
u, err := url.Parse(link)
|
||||
if err != nil {
|
||||
return link
|
||||
@@ -450,6 +452,9 @@ func tag(link, campaign string) string {
|
||||
if q.Get("utm_medium") == "" {
|
||||
q.Set("utm_medium", "landing")
|
||||
}
|
||||
if content != "" {
|
||||
q.Set("utm_content", content)
|
||||
}
|
||||
u.RawQuery = q.Encode()
|
||||
return u.String()
|
||||
}
|
||||
@@ -585,3 +590,124 @@ func ConfirmedAll(claims, confirmed []string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Content is the utm_content a variant's links carry ("for-churches-b"),
|
||||
// so its sign-ups can be told from the original's; the original (A) and
|
||||
// pages without variants carry none.
|
||||
func Content(p *SitePage) string {
|
||||
if p.Source.VariantOf == 0 || p.Path == "" {
|
||||
return ""
|
||||
}
|
||||
return strings.ReplaceAll(strings.Trim(p.Path, "/"), "/", "-")
|
||||
}
|
||||
|
||||
// Variant makes a copy of a page to test against it: the same sections at
|
||||
// its own address (the original's with -b, -c…), a draft until pushed.
|
||||
func Variant(d *db.DB, orig *SitePage) (*SitePage, error) {
|
||||
rootID := orig.Root()
|
||||
root := orig
|
||||
if rootID != orig.ID {
|
||||
r, err := GetPage(d, rootID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
root = r
|
||||
}
|
||||
all, err := Pages(d, orig.Site)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
used := map[string]bool{}
|
||||
letters := 1 // the root is A
|
||||
for _, p := range all {
|
||||
used[p.Path] = true
|
||||
if p.Source.VariantOf == rootID {
|
||||
letters++
|
||||
}
|
||||
}
|
||||
letter := string(rune('A' + letters))
|
||||
base := strings.TrimSuffix(root.Path, "/")
|
||||
path := base + "-" + strings.ToLower(letter) + "/"
|
||||
for n := 2; used[path]; n++ {
|
||||
path = fmt.Sprintf("%s-%s%d/", base, strings.ToLower(letter), n)
|
||||
}
|
||||
v := &SitePage{Site: orig.Site, Repo: orig.Repo, Kind: orig.Kind, Source: orig.Source, Notes: orig.Notes, Path: path,
|
||||
Title: orig.Title, Description: orig.Description, Sections: orig.Sections, Needs: orig.Needs, Warnings: orig.Warnings,
|
||||
Claims: orig.Claims, Status: PageDraft}
|
||||
v.Source.VariantOf, v.Source.Variant = rootID, letter
|
||||
if root.Source.Variant == "" {
|
||||
root.Source.Variant = "A"
|
||||
if err := SavePage(d, root); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return v, SavePage(d, v)
|
||||
}
|
||||
|
||||
// Remove opens a pull request that takes a published page off the site.
|
||||
func Remove(ctx context.Context, d *db.DB, ap *seo.Applier, p *SitePage) error {
|
||||
if p.Status != PageMerged {
|
||||
return errors.New("only a page that's on the site can be taken off it")
|
||||
}
|
||||
if p.File == "" {
|
||||
return errors.New("Supermarket doesn't know this page's file")
|
||||
}
|
||||
wc, full, published, err := ap.WorkingCopy(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer wc.Release()
|
||||
if !wc.Exists(p.File) {
|
||||
return fmt.Errorf("%s isn't on the published branch any more", p.File)
|
||||
}
|
||||
branch := fmt.Sprintf("supermarket/remove-site-page-%d", p.ID)
|
||||
if err := wc.NewBranch(ctx, branch); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := wc.RemoveFile(p.File); err != nil {
|
||||
return err
|
||||
}
|
||||
note := "Not checked with a build: there's no Hugo in Supermarket's image."
|
||||
if hugorepo.HugoVersion(ctx) != "" {
|
||||
out, err := wc.Build(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("without this page, %w", err)
|
||||
}
|
||||
os.RemoveAll(out)
|
||||
note = "Checked with a build: the site builds without it."
|
||||
}
|
||||
subject := fmt.Sprintf("Sites: remove %s", p.Path)
|
||||
if err := wc.CommitAndPush(ctx, branch, subject); err != nil {
|
||||
return err
|
||||
}
|
||||
body := fmt.Sprintf("Takes **%s** (`%s`, %s) off the site, as asked in Supermarket.\n\nLinks to it from elsewhere (outreach, posts, other pages) will stop working; consider a redirect (an `aliases:` entry on another page) if it was shared.\n\n%s\n\nMerging removes it from the live site.",
|
||||
p.Title, p.Path, p.File, note)
|
||||
pull, err := ap.Gitea.OpenPull(ctx, full, branch, published, subject, body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.RemovalBranch, p.RemovalPRNumber, p.RemovalPRURL, p.Status, p.Error = branch, pull.Number, pull.HTMLURL, PageRemoving, ""
|
||||
return SavePage(d, p)
|
||||
}
|
||||
|
||||
// ClosePR closes a page's open pull request (adding it, or removing it)
|
||||
// without merging.
|
||||
func ClosePR(ctx context.Context, d *db.DB, g interface {
|
||||
ClosePull(ctx context.Context, full string, n int64) error
|
||||
}, full string, p *SitePage) error {
|
||||
switch p.Status {
|
||||
case PagePR:
|
||||
if err := g.ClosePull(ctx, full, p.PRNumber); err != nil {
|
||||
return err
|
||||
}
|
||||
p.Status = PageClosed
|
||||
case PageRemoving:
|
||||
if err := g.ClosePull(ctx, full, p.RemovalPRNumber); err != nil {
|
||||
return err
|
||||
}
|
||||
p.Status, p.RemovalPRNumber, p.RemovalPRURL = PageMerged, 0, ""
|
||||
default:
|
||||
return errors.New("there's no open pull request to close")
|
||||
}
|
||||
return SavePage(d, p)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user