diff --git a/.planning/phases/11.2-ready-to-share-summercms-io-website-and-newsletter-plugin/11.2-PATTERNS.md b/.planning/phases/11.2-ready-to-share-summercms-io-website-and-newsletter-plugin/11.2-PATTERNS.md new file mode 100644 index 0000000..3c23d98 --- /dev/null +++ b/.planning/phases/11.2-ready-to-share-summercms-io-website-and-newsletter-plugin/11.2-PATTERNS.md @@ -0,0 +1,430 @@ +# Phase 11.2: summercms.io Alpha 0.1 landing page on SummerCMS - Pattern Map + +**Mapped:** 2026-10-01 +**Files analyzed:** 27 (new or modified, across 4 repos) +**Analogs found:** 22 / 27 + +Paths: `FW` = `summercms/summercms.go` (framework), `APP` = `summercms/sm-summercms-app` (new), `PLUG` = `APP/plugins/golem15/summercms` (new submodule, module `git.golem15.com/golem15/sm-summercms-plugin`), `SITE` = `APP/vue-summercms-app` (new submodule), `FON` = `summercms/fonoteka.go`, `VFON` = `/media/nvme/dev/golem15/fonoteka/vue-fonoteka-app`. All framework analog paths below are git-tracked source (checked with `git ls-files`); none are mirrors. + +## File Classification + +| New/Modified File | Role | Data Flow | Closest Analog | Match Quality | +|---|---|---|---|---| +| `FW/internal/docsite/load.go` (Site.SiteURL, SiteLabel, validation) | config/model | transform | itself: `Site.BaseURL` + `ParseSite` (load.go:21-31, 88-100) | exact | +| `FW/internal/docsite/emit.go` (pageView.SiteURL/SiteLabel, baseView) | utility | transform | itself: `pageView.HomeURL` / `baseView` (emit.go ~62-95) | exact | +| `FW/internal/docsite/theme/templates/header.html` | template | transform | itself (wordmark anchor, line 4) | exact | +| `FW/internal/docsite/theme/assets/site.css` (`.site-link`) | style | - | existing `.wordmark` / `.search-trigger` rules | exact | +| `FW/cmd/summer/docs.go` (`--site-url`, `--site-label` on build and serve) | controller (CLI) | request-response | itself: `base-url` flag (docs.go:31, 93, 128) | exact | +| `FW/internal/docsite/load.go` Options + override in `load()` | config | transform | `opts.BaseURL` override (load.go:217-221) | exact | +| `FW/docs/console/utilities.md` | docs | - | itself, the flags table (lines ~33-37) | exact | +| `FW/README.md`, `FW/docs/setup/installation.md` (PG 15+) | docs | - | in-place text edit | n/a | +| `FW/internal/docsite/load_test.go`, `theme_test.go` | test | - | `TestParseSite` table (load_test.go:11-50) | exact | +| `PLUG/plugin.go` | plugin (route registrar) | request-response | `FW/examples/hello/plugins/base/plugin.go` + `greeter/plugin.go` Routes | role-match | +| `PLUG/static.go` | handler (static file server) | file-I/O | `FW/modules/boardwalk/boardwalk.go` + `FW/internal/docsite/serve.go:236-290` | exact (idea), with deliberate deviations | +| `PLUG/public/README.md` | placeholder | - | none (embed needs a matching file) | no analog | +| `PLUG/go.mod` | config | - | `FON/plugins/golem15/user/go.mod` | exact | +| `PLUG/static_test.go` | test | - | `FW/modules/boardwalk/boardwalk_test.go` (fstest + httptest) | exact | +| `PLUG/routes_test.go` | test | - | `FW/modules/surf/example_test.go:114-140` (`surf.Assemble`) and `FW/examples/hello/hello_test.go:201` | role-match | +| `PLUG/links_test.go` | test (integration, built tree) | file-I/O | `boardwalk_test.go` `assetRef` regex walk | partial | +| `APP/go.mod`, `APP/go.work` | config | - | `FON/go.mod`, `FON/go.work` | exact | +| `APP/summer.yaml` | config | - | `FON/summer.yaml` | exact | +| `APP/main.go`, `APP/plugins.gen.go` | generated | - | `FON/main.go`, `FON/plugins.gen.go` (`summer build` output) | exact (generated, do not hand-write) | +| `APP/config/{app,http,storage,database,queue}.yaml` | config | - | `FON/config/*.yaml` | exact | +| `APP/.gitignore` | config | - | `FON/.gitignore` | exact | +| `APP/scripts/build.sh` | script | batch | `FON/scripts/check-openapi.sh` (bash skeleton) + RESEARCH build outline | role-match | +| `APP/terminal_check_test.go` | test (e2e) | batch | `FW/examples/hello/hello_test.go` | partial | +| `APP/scripts/smoke.sh`, `APP/deploy/*.conf`, `APP/DEPLOY.md`, `APP/README.md` | script/config/docs | - | none in repo | no analog (use RESEARCH Deploy section) | +| `SITE/nuxt.config.ts`, `package.json`, `pnpm-workspace.yaml` | config | - | `VFON/nuxt.config.ts`, `VFON/package.json`, `VFON/pnpm-workspace.yaml` | exact (subset) | +| `SITE/i18n/locales/en.json` | config (copy) | - | `VFON/i18n/locales/en.json` | exact (location) | +| `SITE/app/components/*.vue`, `app/utils/*.ts`, `app/data/terminal.json`, `tests/*.test.ts`, `scripts/derive-images.sh` | component/utility/test | event-driven (scroll, clipboard) | none suitable (VFON uses Tailwind + shadcn; D-35 forbids) | no analog (use design handoff + RESEARCH Pattern 3) | + +## Pattern Assignments + +### `FW/internal/docsite/load.go` (config, transform) — D-41/D-46 + +**Analog:** itself. Add fields next to `BaseURL` (load.go, struct `Site`): +```go +type Site struct { + Title string `yaml:"title"` + Description string `yaml:"description"` + BaseURL string `yaml:"base_url"` + // EditURL and SourceURL carry a {path} token ... + EditURL string `yaml:"edit_url"` + SourceURL string `yaml:"source_url"` + LLMSNotes []string `yaml:"llms_notes"` + Sections []Section `yaml:"sections"` +} +``` +A struct field is mandatory: `ParseSite` decodes with `yaml.DisallowUnknownField()`. Validation goes with the existing checks in `ParseSite`, same error style: +```go +if s.Title == "" { + return Site{}, fmt.Errorf("docsite: site config: title is required") +} +``` +(add e.g. `"docsite: site config: site_url must be http(s):// or start with /"`; reject `javascript:` and `//host`). + +**CLI override pattern** (load.go:217-221), mirror for site_url/site_label from `Options`: +```go +s.cfg, s.cfgRaw = cfg, raw +s.base = strings.TrimRight(cfg.BaseURL, "/") +if opts.BaseURL != "" { + s.base = strings.TrimRight(opts.BaseURL, "/") +} +``` +Validate the flag value through the same function as the yaml value. Label rule (D-46): explicit label, else URL host, else "Home" for relative. + +### `FW/internal/docsite/emit.go` (utility, transform) + +Add `SiteURL, SiteLabel string` to `pageView` and fill them in `baseView`, which the 404 page also uses (`baseView(nil)`), so the link appears on every page: +```go +func (s *site) baseView(current *Page) pageView { + return pageView{ + Assets: s.url("assets"), + HomeURL: s.url("index.html"), + SearchIndex: s.url("search-index.json"), + LLMS: s.url("llms.txt"), + LLMSFull: s.url("llms-full.txt"), + Nav: s.nav(current), + } +} +``` +Do not pass SiteURL through `s.url()` (that prefixes base_url); it is an absolute or root-relative link to a different site. + +### `FW/internal/docsite/theme/templates/header.html` + +Current line 4 (insert after it, before `header-spacer`, so unset output is byte-identical): +```html +{{template "icon-sun"}}SummerCMS +``` +Insert: `{{- if .SiteURL}}{{template "icon-chevron-left"}}{{.SiteLabel}}{{end}}`. Use `{{-` trimming carefully so the unset branch adds no whitespace; assert byte-identical output in the test. + +### `FW/cmd/summer/docs.go` (CLI) + +Flag declaration (docs.go:31, repeat at :93 for docs:serve): +```go +{Name: "base-url", Description: "Base URL for site links (overrides site.yaml base_url)"}, +``` +Flag read (docs.go:124-130): +```go +func docsOptions(in bonfire.Input) docsite.Options { + opts := docsite.Options{Commands: docsCommands()} + opts.Root, _ = in.Flag("root") + opts.Src, _ = in.Flag("src") + opts.Out, _ = in.Flag("out") + opts.BaseURL, _ = in.Flag("base-url") + return opts +} +``` +Add `site-url` / `site-label` the same way. Check whether docs:serve builds options through `docsOptions` too; if not, add the read there. + +### `FW/docs/console/utilities.md` + +Extend the `Flags` cells of the `docs:build` and `docs:serve` rows (`--root` (default `.`), `--src`, `--out`, `--base-url`, `--check`) and add a short "site.yaml keys" paragraph. Example URL must be neutral (`https://acme.example/`), never summercms.io (CLAUDE.md docs rule). + +### `FW/internal/docsite/load_test.go` (test) + +Analog `TestParseSite` (load_test.go:11-50): `const valid = "title: Acme\ndescription: Acme docs.\nsections:\n - name: setup\n title: Setup\n"` then a `[]struct{ name, raw, want string }` table checked with `strings.Contains(err.Error(), tc.want)`. Add rows `valid + "site_url: javascript:alert(1)\n"` etc., and a positive case. Header present/absent assertions go in `theme_test.go` next to existing render tests. + +--- + +### `PLUG/plugin.go` (plugin, request-response) + +**Analog:** `FW/examples/hello/plugins/base/plugin.go` (lines 1-54) for the skeleton, `greeter/plugin.go:59-76` for `Routes`. + +Imports + interface assertions + embed (base/plugin.go:1-25): +```go +import ( + "embed" + "io/fs" + + "git.golem15.com/golem15/summercms/modules/backpack" + "git.golem15.com/golem15/summercms/modules/pact" + "git.golem15.com/golem15/summercms/modules/party" +) + +var ( + _ pact.HasConfig = (*Plugin)(nil) + ... +) + +//go:embed config +var configFS embed.FS +``` +Use `var _ pact.HasRoutes = (*Plugin)(nil)` only. Do NOT add `pact.HasAdminControllers` (activates cabana, needs `admin.jwt.secret`). Embed must be `//go:embed all:public` (boardwalk.go:24 uses `//go:embed all:dist` for the same reason). + +Lifecycle methods (base/plugin.go:30-34, 52-54): +```go +func (p *Plugin) ID() string { return "golem15.hello" } +func (p *Plugin) Requires() []string { return nil } + +func (p *Plugin) Register(*backpack.App) error { return nil } +func (p *Plugin) Boot(*backpack.App) error { return nil } + +func init() { + party.Register(&Plugin{}) +} +``` +ID becomes `"golem15.summercms"` (must be a string literal: `summer plugin:add` reads it from source). + +Routes (greeter/plugin.go:59-68) — plain `r.Get(path, func(w, req))`; for the site wrap in `r.GroupRaw("", nil, func(g pact.Router){ g.Get("/docs", ...); g.Get("/docs/{path...}", ...); g.Get("/", ...) })` per RESEARCH Pattern 2. Return the handler-construction error from `Routes` (fail closed when `public/site/index.html` is missing), as boardwalk's `newHandler` does: +```go +raw, err := fs.ReadFile(root, "index.html") +if err != nil { + return nil, fmt.Errorf("boardwalk: dist/index.html: %w", err) +} +``` + +### `PLUG/static.go` (handler, file-I/O) + +**Analogs:** `FW/modules/boardwalk/boardwalk.go` (embed.FS + ServeContent + content-type table + cache by prefix) and `FW/internal/docsite/serve.go:236-290` (public static: dot-segment refusal, dir index.html, 404.html with 404 status). The docsite handler is the closer semantic match (public site, real 404s); boardwalk gives the embed/cache mechanics. + +Content-type table + fallback (boardwalk.go:34-43, 153-162) — copy and extend with `.md`, `.webmanifest`, `.txt`, `.xml`/`.xsl`: +```go +var contentTypes = map[string]string{ + ".js": "text/javascript; charset=utf-8", + ".mjs": "text/javascript; charset=utf-8", + ".css": "text/css; charset=utf-8", + ".html": "text/html; charset=utf-8", + ".woff2": "font/woff2", + ".woff": "font/woff", + ".svg": "image/svg+xml", + ".json": "application/json", +} + +func ContentType(name string) string { + ext := strings.ToLower(path.Ext(name)) + if ct, ok := contentTypes[ext]; ok { + return ct + } + if ct := mime.TypeByExtension(ext); ct != "" { + return ct + } + return "application/octet-stream" +} +``` +Sub-tree (boardwalk.go:46-48): `fs.Sub(distFS, "dist")` → `fs.Sub(publicFS, "public/site")` and `"public/docs"`. + +Serve-file + cache (boardwalk.go:135-148) — replace the single `assets/` prefix with RESEARCH's cache table (`_nuxt/` except `_nuxt/builds/`, and `_fonts/` immutable; everything else `no-cache`), and preset an `ETag` header before `ServeContent`: +```go +w.Header().Set("Content-Type", ContentType(name)) +if strings.HasPrefix(name, "assets/") { + w.Header().Set("Cache-Control", "public, max-age=31536000, immutable") +} else { + w.Header().Set("Cache-Control", "no-cache") +} +http.ServeContent(w, r, path.Base(name), time.Time{}, bytes.NewReader(body)) +``` +Path cleaning + dot refusal + dir index + 404 page (serve.go:250-283): +```go +clean := path.Clean("/" + r.URL.Path) +for _, seg := range strings.Split(clean, "/") { + if strings.HasPrefix(seg, ".") { + notFound(w, root) + return + } +} +... +if err == nil && info.IsDir() { + name = filepath.Join(name, "index.html") +... +func notFound(w http.ResponseWriter, root string) { + body, err := os.ReadFile(filepath.Join(root, "404.html")) + if err != nil { + http.NotFound(w, nil) + return + } + w.Header().Set("Content-Type", "text/html; charset=utf-8") + w.WriteHeader(http.StatusNotFound) + _, _ = io.Copy(w, bytes.NewReader(body)) +} +``` +Port to `fs.Stat`/`fs.ReadFile` on the embedded `fs.FS`. Add the D-47 step: for docs, if `
` is not found and `
.html` is a regular file, `http.Redirect(w, r, "/docs/"+strings.TrimPrefix(clean,"/")+".html", http.StatusMovedPermanently)` built only from the cleaned path. Method check is already done by ServeMux (GET/HEAD patterns), so serve.go's 405 block is not needed.
+
+**Do NOT copy:** `SetSecurityHeaders` (boardwalk.go:167-173: noindex, CSP `script-src 'self'`, DENY), `RewriteIndex`, the SPA fallback (boardwalk.go:118-126), `serveIndex`'s `no-store`. Optional headers allowed: `X-Content-Type-Options: nosniff`, `Referrer-Policy: strict-origin-when-cross-origin`.
+
+### `PLUG/static_test.go` (test)
+
+**Analog:** `FW/modules/boardwalk/boardwalk_test.go:1-44`:
+```go
+import (
+ "io/fs"
+ "net/http"
+ "net/http/httptest"
+ "path"
+ "regexp"
+ "strings"
+ "testing"
+ "testing/fstest"
+)
+
+func get(h http.Handler, target string) *httptest.ResponseRecorder {
+ rec := httptest.NewRecorder()
+ h.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, target, nil))
+ return rec
+}
+```
+Build fixtures with `fstest.MapFS` and call the unexported constructor (boardwalk splits `Handler` / `newHandler(root fs.FS, ...)` exactly for this — copy that split). Cases: RESEARCH Validation table row SC2.
+
+### `PLUG/routes_test.go` (test)
+
+**Analog:** `FW/modules/surf/example_test.go:114-140`:
+```go
+app := backpack.New(nil)
+plugin := &BlogPlugin{}
+if err := plugin.Register(app); err != nil { ... }
+h, err := surf.Assemble(app, []party.Plugin{plugin})
+...
+rec := httptest.NewRecorder()
+h.ServeHTTP(rec, req)
+```
+`backpack.New(nil)` (nil config) skips the body_limits requirement. Add a fake plugin implementing admin controllers to prove no conflict; assert `/backend` hits the site catch-all when alone, `/docs` → 301, `POST /` → 405.
+
+### `PLUG/links_test.go` (integration on built tree, gated `SUMMERCMS_REQUIRE_BUILD=1`)
+
+Reuse boardwalk_test.go's href extractor idea (line 17): `assetRef = regexp.MustCompile(`(?:src|href)="([^"]+)"`)`; resolve each internal href through the real handler (follow one 301, require 200) and each `#id` against `id="..."` in index.html. Also the drift guard: each command in `SITE/app/data/terminal.json` appears in `public/site/index.html`.
+
+### `PLUG/go.mod`
+
+**Analog:** `FON/plugins/golem15/user/go.mod`: `module ...`, `go 1.27.0`, `require git.golem15.com/golem15/summercms v0.0.0` (v0.1.0 after the tag), plus `replace git.golem15.com/golem15/summercms => ../../../../summercms.go` (same depth as fonoteka). No third-party requires (stdlib only).
+
+---
+
+### `APP/go.work`, `APP/go.mod`, `APP/summer.yaml`, `APP/.gitignore`
+
+**Analog:** `FON/go.work`:
+```
+go 1.27.0
+
+toolchain go1.27.0
+
+use (
+ .
+ ./plugins/golem15/user
+ ./plugins/golem15/fonoteka
+)
+```
+→ `use ( . ./plugins/golem15/summercms )`. Does not `use` the framework.
+
+`FON/go.mod` header:
+```
+module git.golem15.com/golem15/fonoteka
+
+go 1.27.0
+toolchain go1.27.0
+
+replace git.golem15.com/golem15/summercms => ../summercms.go
+
+require (
+ git.golem15.com/golem15/fonoteka/plugins/golem15/fonoteka v0.0.0
+ ...
+ git.golem15.com/golem15/summercms v0.0.0
+...
+replace git.golem15.com/golem15/fonoteka/plugins/golem15/user => ./plugins/golem15/user
+```
+→ module `git.golem15.com/golem15/sm-summercms-app`, require `summercms v0.1.0` (D-42) and `sm-summercms-plugin v0.0.0` with `replace ... => ./plugins/golem15/summercms`. Prefer generating these with `summer plugin:add plugins/golem15/summercms`.
+
+`FON/summer.yaml`:
+```yaml
+module: git.golem15.com/golem15/fonoteka
+binary: fonoteka
+plugins:
+ - id: golem15.user
+ module: git.golem15.com/golem15/fonoteka/plugins/golem15/user
+```
+→ `binary: summercms-io`, one plugin `golem15.summercms` / `git.golem15.com/golem15/sm-summercms-plugin`.
+
+`FON/.gitignore`: `/bin/`, `/tmp/`, `*.exe`, `go.work.sum` → add `.env`, `/storage/`.
+
+`main.go` / `plugins.gen.go`: generated by `summer build`; commit them as fonoteka does, never hand-edit.
+
+### `APP/config/*.yaml`
+
+Analogs from `FON/config/` (copy shape, change values):
+- `app.yaml`: `name`, `debug: false`, `locale: en`, `fallback_locale: en`, `key: ""` with the comment "Set SUMMER_APP__KEY to a 32-byte base64 value (summer key:generate)".
+- `http.yaml`: keep only `body_limits: {default_bytes: 1048576, upload_bytes: 1048576}` (numeric, YAML-only) and `trusted_proxies: []` (consider `127.0.0.1/32` for nginx); drop fonoteka's CORS block.
+- `storage.yaml`: `uploads.bucket_url: "file://./storage/app/uploads"` (empty fails boot).
+- `queue.yaml`: `work_in_serve: false` (fonoteka has `true`; the site has no jobs).
+- `database.yaml`: `dsn: ""` (env `SUMMER_DATABASE__DSN`).
+
+### `APP/scripts/build.sh` (script, batch)
+
+**Analog skeleton:** `FON/scripts/check-openapi.sh:1-9`:
+```bash
+#!/usr/bin/env bash
+#