Phase 3 part 6: briefs and pages

A brief for a search (a new page) or a page (a rewrite) starts from what
Search Console shows the page for, reads the live top 5 with Claude's web
search (unread results marked, never guessed), and gives the title,
description, H1, angle, sections, questions, internal links to pages we
have, and the questions only the owner can answer. The page is drafted
around those answers, with no invented tests, prices or customers; every
sentence claiming an experience must be confirmed before a pull request
adds or rewrites the page, checked with a Hugo build. Merged pages are
followed to the live site. Schema 17.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 08:18:49 -07:00
co-authored by Claude Opus 5.5
parent c0a5ddf77f
commit 68c224f51b
19 changed files with 1440 additions and 22 deletions
+61 -1
View File
@@ -101,13 +101,19 @@ func (r *Repo) NewBranch(ctx context.Context, name string) error {
return err
}
// Diff is the working copy's uncommitted change.
// Diff is the working copy's uncommitted change, new files included.
func (r *Repo) Diff(ctx context.Context) (string, error) {
if _, err := r.git(ctx, "add", "-A", "--intent-to-add", "content"); err != nil {
return "", err
}
return r.git(ctx, "diff")
}
// CommitAndPush commits everything changed and pushes the current branch.
func (r *Repo) CommitAndPush(ctx context.Context, branch, message string) error {
if _, err := r.git(ctx, "add", "-A", "content"); err != nil {
return err
}
if _, err := r.git(ctx, "commit", "--quiet", "-am", message); err != nil {
return err
}
@@ -382,3 +388,57 @@ func BuiltHead(outDir, pagePath string) (title, description string, err error) {
walk(doc)
return title, description, nil
}
// --- Writing pages ---
// Field is a front matter key and value.
type Field struct{ Key, Value string }
// NewPage writes a new content file with YAML front matter. It refuses to
// overwrite a file that exists.
func (r *Repo) NewPage(rel string, fields []Field, body string) error {
path := filepath.Join(r.Dir, rel)
if !strings.HasPrefix(filepath.Clean(path), filepath.Clean(filepath.Join(r.Dir, "content"))+string(filepath.Separator)) {
return fmt.Errorf("%s isn't in the content folder", rel)
}
if _, err := os.Stat(path); err == nil {
return fmt.Errorf("%s already exists", rel)
}
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
return err
}
var b strings.Builder
b.WriteString("---\n")
for _, f := range fields {
b.WriteString(f.Key + ": " + strconv.Quote(f.Value) + "\n")
}
b.WriteString("---\n\n")
b.WriteString(strings.TrimSpace(body) + "\n")
return os.WriteFile(path, []byte(b.String()), 0o644)
}
// ReplaceBody keeps a content file's front matter and replaces what follows.
func (r *Repo) ReplaceBody(rel, body string) error {
path := filepath.Join(r.Dir, rel)
raw, err := os.ReadFile(path)
if err != nil {
return err
}
lines := strings.Split(string(raw), "\n")
delim := strings.TrimSpace(lines[0])
if delim != "---" && delim != "+++" {
return fmt.Errorf("%s has no YAML or TOML front matter", rel)
}
end := -1
for i := 1; i < len(lines); i++ {
if strings.TrimSpace(lines[i]) == delim {
end = i
break
}
}
if end < 0 {
return fmt.Errorf("%s's front matter doesn't end", rel)
}
out := strings.Join(lines[:end+1], "\n") + "\n\n" + strings.TrimSpace(body) + "\n"
return os.WriteFile(path, []byte(out), 0o644)
}