diff --git a/cmd/hotdog-cms/main.go b/cmd/hotdog-cms/main.go index 0ed1c32..dc8c889 100644 --- a/cmd/hotdog-cms/main.go +++ b/cmd/hotdog-cms/main.go @@ -654,6 +654,15 @@ func cmdPack(args []string) error { for _, f := range ref.Files { fmt.Println(" ", f) } + if len(ref.Seeded) > 0 { + fmt.Printf("forms, now the site's own (upgrading or removing the pack leaves them; set each one's to: address):\n") + for _, f := range ref.Seeded { + fmt.Println(" ", f) + } + } + for _, f := range ref.Kept { + fmt.Printf("kept the site's own %s; the pack's version wasn't copied\n", f) + } if len(ref.AddedCollections) > 0 { fmt.Printf("site.yaml: added collections settings for %s\n", strings.Join(ref.AddedCollections, ", ")) } @@ -696,6 +705,10 @@ func cmdPack(args []string) error { } fmt.Printf("%s %s: installs %d file(s)\n", m.Name, m.Version, len(files)) for _, f := range files { + if f.Seed { + fmt.Printf(" %s -> %s (a form: copied once, then the site's own)\n", f.From, f.To) + continue + } fmt.Printf(" %s -> %s\n", f.From, f.To) } default: diff --git a/docs/checks.md b/docs/checks.md index 0d36304..d209778 100644 --- a/docs/checks.md +++ b/docs/checks.md @@ -45,6 +45,7 @@ check: | `image-location` | error | A JPEG that carries the GPS location where it was taken: on a personal site, often the author's home. Pictures uploaded through the editor never do. | | `image-weight` | warning | A picture over 500 KB. | | `analytics-ungated` | warning | Visit statistics start on page view without asking (`analytics.gated: false`). | +| `form-placeholder` | warning | A form in `forms/` still sends to, or shows, a placeholder address such as you@example.org, as the starter's and a pack's forms do until you set your own. Messages sent with it would go nowhere. | | `look-contrast` | error | A pair the theme's `look.yaml` says must stay readable is under 4.5:1, in light or dark mode, with the site's look applied. | ## The Content-Security-Policy a site needs diff --git a/docs/forms.md b/docs/forms.md index 815ff6f..3fe79c1 100644 --- a/docs/forms.md +++ b/docs/forms.md @@ -31,6 +31,10 @@ starter's page layout renders it), or `{{ form "contact" }}` in any template. The build fails on a form that doesn't make sense: no recipient, a select with no options, an unknown key. +The contact-forms pack (`hotdog-cms pack add contact-forms`) brings three +more, a quote request, a booking request and a mailing list sign-up, and a +section that shows any form beside your contact details. + ## What the endpoint checks In this order, and a submission that fails any of them is not sent: diff --git a/docs/packs.md b/docs/packs.md index 2c8fb65..390bd7f 100644 --- a/docs/packs.md +++ b/docs/packs.md @@ -29,6 +29,11 @@ Content-Security-Policy as the site's own. - `list` also names the packs that come with HotDog CMS: - **calendar**: events, an upcoming-events section and a feed people subscribe to (see [events.md](events.md)); + - **changelog**: release notes, a page per release and all of them on + one page, a feed to follow and a "What's new" section; + - **contact-forms**: ready-made forms for a quote, a booking and a + mailing list, and a section that puts any form beside your email, + phone and address; - **docs**: a documentation section with a sidebar, part pages and previous/next links, in the order `data/docs-nav.yaml` gives; - **downloads**: files to download, with their type and size; @@ -53,6 +58,8 @@ Content-Security-Policy as the site's own. - **shop**: a product catalog with a page per product, each Buy button opening your payment provider's checkout (no cart); - **table-of-contents**: a long page's headings, linked, at its top; + - **tables**: tables from a spreadsheet saved as CSV (or YAML), with a + caption and row headings, that scroll on phones; - **team**: a page per person, a list of everyone and a section; - **testimonials**: quotes with a name and a role. - `-site` picks the site folder (default: the current one). @@ -120,6 +127,13 @@ What a pack can hold: - **Templates:** `.html` files directly in `sections/`, `partials/` or `layouts/`, installed at the same place in the site. Sections declare their fields the usual way (see [themes.md](themes.md)). +- **Forms:** `.yaml` files directly in `forms/` (see [forms.md](forms.md)). + A form is copied in once and is the site's own from then on, since the + site sets where it sends: upgrading or removing the pack leaves it alone, + and a site's own form of the same name is kept. A pack's form must send + to a placeholder address such as `you@example.org`, never one the pack's + author chose, and can't turn on Turnstile, which loads another site's + script. `hotdog-cms check` warns until the site sets its own address. - **Assets:** stylesheets, pictures (PNG, JPEG, WebP, GIF, AVIF) and fonts in `assets/`. They're installed under `assets/packs//`, so two packs never collide. Refer to them that way: diff --git a/docs/themes.md b/docs/themes.md index 116d40c..8096ee8 100644 --- a/docs/themes.md +++ b/docs/themes.md @@ -62,7 +62,7 @@ Each field has a `name`, and optionally a `type` (default `text`), a `label`, | `select` | one of `options: [a, b, c]` | | `list` | items with their own `fields`, or lines of text without them | | `group` | a set of `fields` | -| `data` | a file in `data/` | +| `data` | a file in `data/`: YAML, JSON, or CSV (a spreadsheet, read as a list of rows of cells) | | `collection` | a collection, such as `articles` | If the comment can't be read, the editor says why, in the section's card. diff --git a/internal/build/funcs.go b/internal/build/funcs.go index fc75df5..db0c9f2 100644 --- a/internal/build/funcs.go +++ b/internal/build/funcs.go @@ -85,7 +85,7 @@ func funcs(s *site.Site, a *Assets, md *site.Markdown, icons Icons) template.Fun "data": func(name string) (any, error) { v, ok := s.Data[name] if !ok { - return nil, fmt.Errorf("no data/%s.yaml or data/%s.json", name, name) + return nil, fmt.Errorf("no data/%s.yaml, data/%s.json or data/%s.csv", name, name, name) } return v, nil }, diff --git a/internal/check/check.go b/internal/check/check.go index a90a296..007a3fc 100644 --- a/internal/check/check.go +++ b/internal/check/check.go @@ -99,6 +99,7 @@ func Run(siteDir, out string, cfg *site.Config) (*Report, error) { c.sitewide(pages) c.images() c.look() + c.formAddresses() c.report.CSP = policy(pages) sort.SliceStable(c.report.Problems, func(i, j int) bool { a, b := c.report.Problems[i], c.report.Problems[j] @@ -161,7 +162,7 @@ func (c *checker) forbidden() error { func textFile(p string) bool { switch strings.ToLower(filepath.Ext(p)) { - case ".md", ".html", ".htm", ".css", ".js", ".json", ".yaml", ".yml", ".txt", ".xml", ".svg", ".webmanifest": + case ".md", ".html", ".htm", ".css", ".js", ".json", ".csv", ".yaml", ".yml", ".txt", ".xml", ".svg", ".webmanifest": return true } return false diff --git a/internal/check/check_test.go b/internal/check/check_test.go index a9471bc..054bc7e 100644 --- a/internal/check/check_test.go +++ b/internal/check/check_test.go @@ -192,3 +192,27 @@ func TestEveryRuleHasAFix(t *testing.T) { } } } + +func TestFormPlaceholder(t *testing.T) { + dir, out, cfg := mkSite(t, map[string]string{"index.html": "" + head + ""}, "") + os.MkdirAll(filepath.Join(dir, "forms"), 0o755) + os.WriteFile(filepath.Join(dir, "forms", "quote.yaml"), []byte("to: you@example.org\nfields: [{name: a}]\n"), 0o644) + os.WriteFile(filepath.Join(dir, "forms", "signup.yaml"), []byte("to: hello@b.co\nmailto: you@example.org\nfields: [{name: a}]\n"), 0o644) + os.WriteFile(filepath.Join(dir, "forms", "contact.yaml"), []byte("to: hello@b.co\nfields: [{name: a}]\n"), 0o644) + r, err := Run(dir, out, cfg) + if err != nil { + t.Fatal(err) + } + var found []string + for _, p := range r.Problems { + if p.Rule == "form-placeholder" { + if p.Level != Warning { + t.Errorf("%s is an %s", p.File, p.Level) + } + found = append(found, p.File) + } + } + if strings.Join(found, " ") != "forms/quote.yaml forms/signup.yaml" { + t.Errorf("form-placeholder on %v", found) + } +} diff --git a/internal/check/fixes.go b/internal/check/fixes.go index b098791..89749c3 100644 --- a/internal/check/fixes.go +++ b/internal/check/fixes.go @@ -32,4 +32,5 @@ var Fixes = map[string]string{ "image-weight": "Upload the picture through the editor, which resizes it and makes WebP copies, or shrink it before committing.", "analytics-ungated": "Remove gated: false from analytics: in site.yaml, so the consent banner asks first; if you keep it, say so in the privacy notice.", "look-contrast": "Pick colors further apart in the Look panel (it shows the ratio as you go); text needs 4.5:1.", + "form-placeholder": "Set the form's to: (and mailto:) to your own address, in forms/ or the editor's Forms page, and, if the endpoint lists recipients, add it there too.", } diff --git a/internal/check/rules.go b/internal/check/rules.go index c4202a3..744cae7 100644 --- a/internal/check/rules.go +++ b/internal/check/rules.go @@ -12,6 +12,7 @@ import ( "strings" "time" + "git.coffeylabs.org/coffey-labs/hotdog-cms/internal/forms" "git.coffeylabs.org/coffey-labs/hotdog-cms/internal/media" "git.coffeylabs.org/coffey-labs/hotdog-cms/internal/site" ) @@ -308,3 +309,26 @@ func (c *checker) look() { } } } + +// Forms that still send to a placeholder address, as the starter's and a +// pack's do until the site sets its own: the messages would go nowhere. +func (c *checker) formAddresses() { + all, err := forms.Load(c.siteDir) + if err != nil { + return // a broken form fails the build first + } + names := make([]string, 0, len(all)) + for name := range all { + names = append(names, name) + } + sort.Strings(names) + for _, name := range names { + f := all[name] + file := "forms/" + name + ".yaml" + if forms.Placeholder(f.To) { + c.add(Warning, "form-placeholder", file, "sends to %s, a placeholder: submissions would go nowhere", f.To) + } else if f.Mailto != "" && forms.Placeholder(f.Mailto) { + c.add(Warning, "form-placeholder", file, "shows %s, a placeholder, to visitors without JavaScript", f.Mailto) + } + } +} diff --git a/internal/editor/media.go b/internal/editor/media.go index a5a4ca5..d08ee55 100644 --- a/internal/editor/media.go +++ b/internal/editor/media.go @@ -161,7 +161,7 @@ func mediaLibrary(siteDir string) []*MediaItem { return nil } switch path.Ext(rel) { - case ".md", ".html", ".yaml", ".yml", ".json", ".toml", ".css", ".txt": + case ".md", ".html", ".yaml", ".yml", ".json", ".csv", ".toml", ".css", ".txt": default: return nil } diff --git a/internal/forms/forms.go b/internal/forms/forms.go index 3751846..a278662 100644 --- a/internal/forms/forms.go +++ b/internal/forms/forms.go @@ -184,7 +184,7 @@ func (f *Form) check() error { if f.Submit == "" { f.Submit = "Send" } - if f.Success != "" && !strings.HasPrefix(f.Success, "/") { + if f.Success != "" && (!strings.HasPrefix(f.Success, "/") || strings.HasPrefix(f.Success, "//") || strings.HasPrefix(f.Success, "/\\")) { return fmt.Errorf("success must be a path on this site, such as /contact/thanks/") } if f.Mailto != "" { @@ -195,6 +195,32 @@ func (f *Form) check() error { return nil } +// Placeholder reports whether an address is at a domain kept for examples +// (RFC 2606: example.org, example.com, example.net, and .example, .test, +// .invalid and .localhost names), so mail to it goes nowhere. Forms that +// come in a pack send there until the site sets its own address. +func Placeholder(addr string) bool { + a, err := mail.ParseAddress(addr) + if err != nil { + return false + } + _, domain, ok := strings.Cut(strings.ToLower(a.Address), "@") + if !ok { + return false + } + domain = strings.TrimSuffix(domain, ".") + switch domain { + case "example.org", "example.com", "example.net": + return true + } + for _, tld := range []string{".example", ".test", ".invalid", ".localhost"} { + if domain == tld[1:] || strings.HasSuffix(domain, tld) { + return true + } + } + return strings.HasSuffix(domain, ".example.org") || strings.HasSuffix(domain, ".example.com") || strings.HasSuffix(domain, ".example.net") +} + // Submission is a checked set of values, in the form's field order. type Submission struct { Form *Form diff --git a/internal/forms/forms_test.go b/internal/forms/forms_test.go index bdd4795..a9996df 100644 --- a/internal/forms/forms_test.go +++ b/internal/forms/forms_test.go @@ -71,6 +71,8 @@ func TestDefinitionErrors(t *testing.T) { "to: a@b.co\nfields: [{name: _t}]\n", "to: a@b.co\nreply_to: a\nfields: [{name: a}]\n", "to: a@b.co\nsuccess: https://evil.example/\nfields: [{name: a}]\n", + "to: a@b.co\nsuccess: //evil.example/\nfields: [{name: a}]\n", + "to: a@b.co\nsuccess: /\\evil.example/\nfields: [{name: a}]\n", "to: a@b.co\nfields: [{name: a}]\nunknown_key: 1\n", } for _, c := range cases { @@ -110,3 +112,25 @@ func TestSubjectIsPlain(t *testing.T) { t.Errorf("a plain subject was refused: %v", err) } } + +func TestPlaceholder(t *testing.T) { + for addr, want := range map[string]bool{ + "you@example.org": true, + "You@Example.COM": true, + "a@mail.example.net": true, + "a@shop.example": true, + "a@site.test": true, + "a@nowhere.invalid": true, + "Name ": true, + "hello@b.co": false, + "a@example.org.evil.co": false, + "a@notexample.org": false, + "not an address": false, + "a@examples.org": false, + "a@test.co": false, + } { + if got := Placeholder(addr); got != want { + t.Errorf("Placeholder(%q) = %v, want %v", addr, got, want) + } + } +} diff --git a/internal/packs/bundled_test.go b/internal/packs/bundled_test.go index 0520144..0a59040 100644 --- a/internal/packs/bundled_test.go +++ b/internal/packs/bundled_test.go @@ -164,6 +164,33 @@ func TestBundledPacksBuildAndPass(t *testing.T) { "products/kit/index.html": {`href="https://buy.stripe.com/test_1" rel="noopener">Buy`, "With a basket · $39.50", `alt="The card"`, `"@type":"Product"`, `"priceCurrency":"USD"`, `"price":"24.00"`, "InStock"}, "products/mug/index.html": {"Sold out", "OutOfStock"}, }}, + {"contact-forms", []page{ + {"content/quote.md", "---\ntitle: Get a quote\nsummary: Tell us what you need.\nsections:\n - contact-form:\n heading: Ask for a quote\n form: quote\n email: hello@example.org\n phone: (217) 555-0142\n address: |\n 12 Main Street\n Springfield\n note: We answer within **one** working day.\n---\n"}, + {"content/news.md", "---\ntitle: News\nsummary: Sign up.\nsections:\n - contact-form: { heading: Hear from us, form: signup }\n - contact-form: { form: booking }\n---\n"}, + }, map[string][]string{ + "quote/index.html": {"Ask for a quote", `action="/_hotdog/forms/quote"`, `name="service"`, "", ">Ask for a quote", `class="cf-details"`, `href="mailto:hello@example.org"`, "tel:%28217%29555-0142", "12 Main Street", "one", "packs/contact-forms/contact-forms."}, + "news/index.html": {"Hear from us", `action="/_hotdog/forms/signup"`, `type="checkbox" required`, "cf-grid cf-solo", `action="/_hotdog/forms/booking"`, ""}, + }}, + {"tables", []page{ + {"data/prices.csv", "\ufeffItem,Small,Large\nSourdough,$6,$8\n\"Rye, dark\",$5,$7\n[Gift card](/prices/),$25,\n"}, + {"data/staff.yaml", "- { name: Sam, role: Baker, start: 2019 }\n- { name: Ana, role: Front of house }\n"}, + {"content/prices.md", "---\ntitle: Prices\nsummary: What things cost.\nsections:\n - table:\n heading: Prices\n from: prices\n caption: Tax included.\n numbers: true\n row_headers: true\n note: Prices from **January**.\n - table:\n from: staff\n columns: [name, start]\n - table:\n no_header: true\n compact: true\n rows:\n - Monday | Closed\n - Tuesday | 7am to 6pm\n---\n"}, + }, map[string][]string{ + "prices/index.html": {"Tax included.", `Item`, `Large`, `Sourdough$6`, `Rye, dark`, `Gift card`, "$25", "tbl tbl-numbers tbl-rowheads", `aria-label="Tax included."`, "January", `namestart`, "Sam2019", "Ana", "tbl tbl-compact", "MondayClosed", "packs/tables/tables."}, + }}, + {"changelog", []page{ + {"content/changelog/_index.md", "---\ntitle: Release notes\nsummary: What changed, release by release.\n---\n"}, + {"content/changelog/1-0-0.md", "---\ntitle: \"1.0.0\"\ndate: 2026-09-01\nsummary: The first release.\n---\n### Added\n\n- Everything.\n"}, + {"content/changelog/1-1-0.md", "---\ntitle: \"1.1.0\"\ndate: 2026-10-01\nsummary: Faster.\nbreaking: true\n---\n### Changed\n\n- Faster builds.\n"}, + {"content/changelog/1-1-1.md", "---\ntitle: \"1.1.1\"\ndate: 2026-10-12\nsummary: A security fix.\nsecurity: true\n---\n### Security\n\n- Closed a hole.\n"}, + {"content/index.md", "---\ntitle: Home\nsummary: Software.\nlayout: landing\nsections:\n - changelog: { count: 2, notes: true }\n---\n"}, + }, map[string][]string{ + "changelog/index.html": {"Release notes", `id="1-1-1"`, `href="/changelog/1-0-0/">1.0.0`, "Security fix", "Breaking changes", "Follow new releases`, "October 12, 2026"}, + "changelog/1-1-0/index.html": {"

1.1.0

", "Breaking changes", `class="rel-older" href="/changelog/1-0-0/"`, `class="rel-newer" href="/changelog/1-1-1/"`, "What changed"}, + "changelog/1-1-1/index.html": {`class="rel-older" href="/changelog/1-1-0/"`, `class="rel-latest" href="/changelog/1-1-1/"`}, + "changelog/feed.xml": {"1.1.1", "1.0.0"}, + "index.html": {`href="/changelog/1-1-1/">1.1.1`, `href="/changelog/1-1-0/">1.1.0`, "Closed a hole.", "Every release"}, + }}, } for _, c := range cases { t.Run(c.pack, func(t *testing.T) { @@ -177,6 +204,11 @@ func TestBundledPacksBuildAndPass(t *testing.T) { os.MkdirAll(filepath.Join(dir, "static", "media"), 0o755) os.WriteFile(filepath.Join(dir, "static", "media", "a.png"), picture, 0o644) os.WriteFile(filepath.Join(dir, "static", "media", "b.png"), picture, 0o644) + if c.pack == "changelog" { + lp := filepath.Join(dir, "partials", "footer.html") + raw, _ := os.ReadFile(lp) + os.WriteFile(lp, []byte(strings.Replace(string(raw), "", `{{ template "latest-release" . }}`, 1)), 0o644) + } if c.pack == "related-posts" || c.pack == "table-of-contents" { lp := filepath.Join(dir, "layouts", "article.html") raw, _ := os.ReadFile(lp) diff --git a/internal/packs/packs.go b/internal/packs/packs.go index cf8f3a7..8868c06 100644 --- a/internal/packs/packs.go +++ b/internal/packs/packs.go @@ -18,6 +18,12 @@ // layouts/…, assets/…. Assets are installed under assets/packs//, so // two packs never collide; a pack's templates refer to them that way: // {{ asset "packs/faq/faq.css" }}. +// +// A pack can also bring forms (forms/.yaml). They're copied in once and +// then belong to the site, since the site sets where they send: upgrading or +// removing the pack leaves them alone. A pack's form must send to a +// placeholder address (example.org), so a pack can never route a site's +// submissions anywhere, and can't add Turnstile's script. package packs import ( @@ -34,6 +40,7 @@ import ( "gopkg.in/yaml.v3" + "git.coffeylabs.org/coffey-labs/hotdog-cms/internal/forms" "git.coffeylabs.org/coffey-labs/hotdog-cms/internal/markup" "git.coffeylabs.org/coffey-labs/hotdog-cms/internal/site" "git.coffeylabs.org/coffey-labs/hotdog-cms/internal/siteyaml" @@ -78,6 +85,9 @@ func dedupe(xs []string) []string { type File struct { From string // in the pack To string // in the site + // Seed marks a form: copied only if the site has no file there, and the + // site's own from then on (not in the pack's files in site.yaml). + Seed bool } // Check reads a pack and says what's wrong with it, or what it would install. @@ -149,6 +159,16 @@ func Check(dir string) (*Manifest, []File, error) { return nil } files = append(files, File{From: rel, To: rel}) + case top == "forms" && ext == ".yaml" && !strings.Contains(strings.TrimPrefix(rel, "forms/"), "/"): + src, err := os.ReadFile(p) + if err != nil { + return err + } + if problem := packForm(strings.TrimSuffix(path.Base(rel), ".yaml"), src); problem != "" { + problems = append(problems, rel+": "+problem) + return nil + } + files = append(files, File{From: rel, To: rel, Seed: true}) case top == "assets" && assetExt[ext]: files = append(files, File{From: rel, To: path.Join("assets", "packs", m.Name, strings.TrimPrefix(rel, "assets/"))}) case ext == ".js" || ext == ".mjs": @@ -156,7 +176,7 @@ func Check(dir string) (*Manifest, []File, error) { case ext == ".svg": problems = append(problems, rel+": SVG, which can carry scripts; use PNG or WebP") default: - problems = append(problems, rel+": not something a pack can install (sections/, partials/, layouts/ as .html; assets/ as stylesheets, pictures or fonts)") + problems = append(problems, rel+": not something a pack can install (sections/, partials/, layouts/ as .html; forms/ as .yaml; assets/ as stylesheets, pictures or fonts)") } return nil }) @@ -174,6 +194,27 @@ func Check(dir string) (*Manifest, []File, error) { return &m, files, nil } +// packForm says what's wrong with a form a pack brings, if anything. It must +// be a form the build accepts; it must send only to a placeholder address, +// for the site to replace, never to one the pack's author chose; and it +// can't load Turnstile, which is a script from another site. +func packForm(name string, raw []byte) string { + f, err := forms.Parse(name, raw) + if err != nil { + return err.Error() + } + if !forms.Placeholder(f.To) { + return fmt.Sprintf("sends to %s; a pack's form sends to a placeholder such as you@example.org, which the site replaces with its own", f.To) + } + if f.Mailto != "" && !forms.Placeholder(f.Mailto) { + return fmt.Sprintf("mailto %s; a pack's form shows a placeholder such as you@example.org, which the site replaces with its own", f.Mailto) + } + if f.Turnstile != "" { + return "turnstile_sitekey; a pack can't add another site's script (the site can add Turnstile itself)" + } + return "" +} + // Bundled says whether name is a pack that comes with HotDog CMS. func Bundled(name string) bool { if !nameRe.MatchString(name) { @@ -284,13 +325,16 @@ func Add(siteDir, src string, force bool) (*site.PackRef, error) { others = append(others, p) for _, f := range p.Files { for _, nf := range files { - if nf.To == f { + if nf.To == f && !nf.Seed { return nil, fmt.Errorf("%s is already installed by the %s pack", f, p.Name) } } } } for _, f := range files { + if f.Seed { + continue + } if _, err := os.Stat(filepath.Join(siteDir, filepath.FromSlash(f.To))); err == nil && !mine[f.To] && !force { return nil, fmt.Errorf("%s is already in the site (not from this pack); move it, or add with -force to replace it", f.To) } @@ -307,12 +351,22 @@ func Add(siteDir, src string, force bool) (*site.PackRef, error) { return nil, err } dst := filepath.Join(siteDir, filepath.FromSlash(f.To)) + if f.Seed { + if _, err := os.Lstat(dst); err == nil { + ref.Kept = append(ref.Kept, f.To) + continue + } + } if err := os.MkdirAll(filepath.Dir(dst), 0o755); err != nil { return nil, err } if err := os.WriteFile(dst, data, 0o644); err != nil { return nil, err } + if f.Seed { + ref.Seeded = append(ref.Seeded, f.To) + continue + } ref.Files = append(ref.Files, f.To) delete(mine, f.To) } diff --git a/internal/packs/packs_test.go b/internal/packs/packs_test.go index 64eda81..b31aea1 100644 --- a/internal/packs/packs_test.go +++ b/internal/packs/packs_test.go @@ -226,3 +226,67 @@ func TestMarkupTricks(t *testing.T) { } } } + +func TestPackForms(t *testing.T) { + form := "title: Quote\nto: you@example.org\nfields: [{name: details, type: textarea}]\nmailto: you@example.org\n" + pack := write(t, t.TempDir(), map[string]string{ + "pack.yaml": "name: quotes\nversion: 1.0.0\n", + "forms/quote.yaml": form, + "forms/note.yaml": form, + "sections/q.html": `
{{ form "quote" }}
`, + }) + if _, files, err := Check(pack); err != nil || len(files) != 3 || !files[0].Seed || files[2].Seed { + t.Fatalf("check: %v %+v", err, files) + } + + // A pack's form can't send anywhere but a placeholder, or load Turnstile. + for name, bad := range map[string]string{ + "its own address": "to: harvest@evil.co\nfields: [{name: a}]\n", + "its own mailto": "to: you@example.org\nmailto: harvest@evil.co\nfields: [{name: a}]\n", + "turnstile": "to: you@example.org\nturnstile_sitekey: 0x4AAA\nfields: [{name: a}]\n", + "a broken form": "to: you@example.org\nfields: []\n", + } { + p := write(t, t.TempDir(), map[string]string{"pack.yaml": "name: bad\nversion: 1.0.0\n", "forms/x.yaml": bad}) + if _, _, err := Check(p); err == nil || !strings.Contains(err.Error(), "forms/x.yaml") { + t.Errorf("%s: accepted (%v)", name, err) + } + } + nested := write(t, t.TempDir(), map[string]string{"pack.yaml": "name: bad\nversion: 1.0.0\n", "forms/sub/x.yaml": form}) + if _, _, err := Check(nested); err == nil { + t.Error("a form in a subfolder was accepted") + } + + // Installed once, then the site's: a site's own form of that name is + // kept, an upgrade doesn't reset the address, and removing leaves them. + dir := starterSite(t) + own := filepath.Join(dir, "forms", "note.yaml") + os.WriteFile(own, []byte("to: me@b.co\nfields: [{name: a}]\n"), 0o644) + ref, err := Add(dir, pack, false) + if err != nil { + t.Fatal(err) + } + if strings.Join(ref.Seeded, ",") != "forms/quote.yaml" || strings.Join(ref.Kept, ",") != "forms/note.yaml" || strings.Join(ref.Files, ",") != "sections/q.html" { + t.Fatalf("add: seeded %v kept %v files %v", ref.Seeded, ref.Kept, ref.Files) + } + if raw, _ := os.ReadFile(own); !strings.Contains(string(raw), "me@b.co") { + t.Error("the site's own form was replaced") + } + quote := filepath.Join(dir, "forms", "quote.yaml") + os.WriteFile(quote, []byte(strings.ReplaceAll(form, "you@example.org", "sales@b.co")), 0o644) + os.WriteFile(filepath.Join(pack, "pack.yaml"), []byte("name: quotes\nversion: 1.1.0\n"), 0o644) + if _, err := Add(dir, pack, false); err != nil { + t.Fatal(err) + } + if raw, _ := os.ReadFile(quote); !strings.Contains(string(raw), "sales@b.co") { + t.Error("an upgrade reset the form's address") + } + if err := Remove(dir, "quotes"); err != nil { + t.Fatal(err) + } + if _, err := os.Stat(quote); err != nil { + t.Error("removing the pack removed the site's form") + } + if _, err := os.Stat(filepath.Join(dir, "sections", "q.html")); err == nil { + t.Error("removing the pack left its section") + } +} diff --git a/internal/site/config.go b/internal/site/config.go index 70b77cf..8f67c39 100644 --- a/internal/site/config.go +++ b/internal/site/config.go @@ -442,4 +442,6 @@ type PackRef struct { // From the last install, for showing; never written to site.yaml. AddedCollections []string `yaml:"-" json:"-"` Notes string `yaml:"-" json:"-"` + Seeded []string `yaml:"-" json:"-"` // forms copied in, now the site's own + Kept []string `yaml:"-" json:"-"` // forms the site already had, left as they were } diff --git a/internal/site/load.go b/internal/site/load.go index b4f87ab..bf76a88 100644 --- a/internal/site/load.go +++ b/internal/site/load.go @@ -2,6 +2,7 @@ package site import ( "bytes" + "encoding/csv" "encoding/json" "fmt" "html" @@ -28,7 +29,7 @@ type Site struct { Collections map[string][]*Page // collection -> its pages, in the collection's order Lists map[string]*Page // collection -> its list page Taxonomies map[string]map[string][]*Page - Data map[string]any // data/*.yaml and data/*.json, by file name without extension + Data map[string]any // data/*.yaml, data/*.json and data/*.csv, by file name without extension bySource map[string]*Page // PageFrom's index, built on first use BuildTime time.Time @@ -613,6 +614,8 @@ func loadData(dir string) (map[string]any, error) { err = yaml.Unmarshal(raw, &v) case ".json": err = json.Unmarshal(raw, &v) + case ".csv": + v, err = readCSV(raw) default: continue } @@ -627,6 +630,27 @@ func loadData(dir string) (map[string]any, error) { return out, nil } +// readCSV reads a spreadsheet saved as CSV into a list of rows, each a list +// of cells, the way a YAML list of lists reads: the tables pack takes either. +// Every row must have as many cells as the first. A byte order mark, which +// Excel writes, is dropped. +func readCSV(raw []byte) (any, error) { + r := csv.NewReader(bytes.NewReader(bytes.TrimPrefix(raw, []byte("\xef\xbb\xbf")))) + records, err := r.ReadAll() + if err != nil { + return nil, err + } + rows := make([]any, len(records)) + for i, rec := range records { + cells := make([]any, len(rec)) + for j, c := range rec { + cells[j] = c + } + rows[i] = cells + } + return rows, nil +} + func sections(v any) ([]Section, error) { if v == nil { return nil, nil diff --git a/internal/site/load_test.go b/internal/site/load_test.go index 167f8b8..68589f1 100644 --- a/internal/site/load_test.go +++ b/internal/site/load_test.go @@ -88,3 +88,26 @@ func TestFediverseHandle(t *testing.T) { } } } + +func TestCSVData(t *testing.T) { + dir := t.TempDir() + os.WriteFile(filepath.Join(dir, "prices.csv"), []byte("\xef\xbb\xbfItem,Price\n\"Rye, dark\",$5\n"), 0o644) + data, err := loadData(dir) + if err != nil { + t.Fatal(err) + } + rows, ok := data["prices"].([]any) + if !ok || len(rows) != 2 { + t.Fatalf("prices: %#v", data["prices"]) + } + if head := rows[0].([]any); head[0] != "Item" || head[1] != "Price" { + t.Errorf("header (byte order mark kept?): %#v", head) + } + if row := rows[1].([]any); row[0] != "Rye, dark" || row[1] != "$5" { + t.Errorf("row: %#v", row) + } + os.WriteFile(filepath.Join(dir, "prices.csv"), []byte("a,b\nonly one\n"), 0o644) + if _, err := loadData(dir); err == nil || !strings.Contains(err.Error(), "data/prices.csv") { + t.Errorf("a row short of cells: %v", err) + } +} diff --git a/packs/changelog/LICENSE b/packs/changelog/LICENSE new file mode 100644 index 0000000..0e54f6b --- /dev/null +++ b/packs/changelog/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Coffey Labs LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packs/changelog/README.md b/packs/changelog/README.md new file mode 100644 index 0000000..f5efe9a --- /dev/null +++ b/packs/changelog/README.md @@ -0,0 +1,21 @@ +# Changelog pack + +Release notes for a HotDog CMS site: a page per release, every release on +one page, a feed people can follow, and a "What's new" section. + + hotdog-cms pack add changelog + +Each release is a page in `content/changelog/`, with its version as the +title, a date, a one-line summary and the notes in Markdown. Mark one +`security: true` or `breaking: true` and it says so wherever it's listed. + +- `/changelog/`: every release, newest first, with its notes, each at its own + anchor (`/changelog/#1-4-0`). +- `/changelog/1-4-0/`: one release, with links to the older and newer ones. +- `/changelog/feed.xml`: an Atom feed of new releases. +- **What's new** section: the latest few releases on any page. +- `{{ template "latest-release" . }}`: a "Latest 1.4.0" link for a hero or a + footer. + +Notes grouped under `### Added`, `### Changed`, `### Fixed` and so on (the +headings keepachangelog.com uses) show as labels. diff --git a/packs/changelog/assets/changelog.css b/packs/changelog/assets/changelog.css new file mode 100644 index 0000000..83c292b --- /dev/null +++ b/packs/changelog/assets/changelog.css @@ -0,0 +1,24 @@ +/* The changelog pack. Colors come from the theme's variables. */ +.rel-meta { margin: 4px 0 0; color: var(--muted); font-size: .92rem; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; } +.rel-tag { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 650; border: 1px solid var(--line); color: var(--text); } +.rel-security { background: var(--accent-soft); border-color: var(--accent); } +.rel-summary { font-size: 1.05rem; margin: 10px 0 0; } +.rel-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; } +.rel-notes { margin-top: 16px; } +.rel-notes h3 { display: inline-block; margin: 18px 0 4px; padding: 2px 10px; border-radius: 999px; background: var(--accent-soft); font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; } +.rel-notes h3 + ul { margin-top: 4px; } +.rel-follow { color: var(--muted); } +.rel-entry { padding: 28px 0; border-top: 1px solid var(--line); scroll-margin-top: 80px; } +.rel-entry h2 { margin: 0; } +.rel-entry h2 a { color: inherit; text-decoration: none; } +.rel-entry h2 a:hover { text-decoration: underline; } +.rel-none { color: var(--muted); } +.rel-nav { display: flex; justify-content: space-between; gap: 16px; margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--line); } +.rel-nav a { display: grid; gap: 2px; font-weight: 650; text-decoration: none; } +.rel-nav a span { color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; } +.rel-newer { margin-left: auto; text-align: right; } +.rel-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; max-width: 760px; } +.rel-item { padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); } +.rel-title { font-weight: 650; font-size: 1.1rem; } +.rel-latest { display: inline-flex; gap: 8px; align-items: baseline; padding: 4px 12px 4px 4px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-size: .9rem; text-decoration: none; color: var(--text); } +.rel-latest-label { padding: 1px 8px; border-radius: 999px; background: var(--accent); color: var(--accent-text, #fff); font-size: .75rem; font-weight: 700; } diff --git a/packs/changelog/layouts/release-list.html b/packs/changelog/layouts/release-list.html new file mode 100644 index 0000000..4a25f45 --- /dev/null +++ b/packs/changelog/layouts/release-list.html @@ -0,0 +1,20 @@ +{{ define "main" }} + +
+

{{ .Title }}

+ {{ with .Content }}
{{ . }}
{{ end }} + {{ $name := .Collection }}{{ with index .Site.Config.Collections $name }}{{ if .Feed }}{{ $feed := .FeedPath }}{{ if not $feed }}{{ $feed = printf "/%s/feed.xml" $name }}{{ end }} + + {{ end }}{{ end }} + {{ range collection $name }} +
+

{{ .Title }}

+ {{ template "release-tags" . }} + {{ with .Summary }}

{{ . }}

{{ end }} + {{ with .Content }}
{{ . }}
{{ end }} +
+ {{ else }} +

No releases yet.

+ {{ end }} +
+{{ end }} diff --git a/packs/changelog/layouts/release.html b/packs/changelog/layouts/release.html new file mode 100644 index 0000000..a159320 --- /dev/null +++ b/packs/changelog/layouts/release.html @@ -0,0 +1,19 @@ +{{ define "main" }} + +
+ {{ $list := index .Site.Lists .Collection }} + {{ with $list }}

{{ .Title }}

{{ end }} +

{{ .Title }}

+ {{ template "release-tags" . }} + {{ with .Summary }}

{{ . }}

{{ end }} + {{ with .Content }}

What changed

{{ . }}
{{ end }} + {{ $newer := false }}{{ $older := false }}{{ $last := false }}{{ $found := false }} + {{ range collection .Collection }}{{ if $found }}{{ if not $older }}{{ $older = . }}{{ end }}{{ else if eq .Path $.Path }}{{ $found = true }}{{ $newer = $last }}{{ else }}{{ $last = . }}{{ end }}{{ end }} + {{ if or $newer $older }} + + {{ end }} +
+{{ end }} diff --git a/packs/changelog/pack.yaml b/packs/changelog/pack.yaml new file mode 100644 index 0000000..9528185 --- /dev/null +++ b/packs/changelog/pack.yaml @@ -0,0 +1,39 @@ +name: changelog +version: 1.0.0 +title: Changelog +description: Release notes, a page per release and all of them on one page, with a feed people can follow and a "What's new" section for any page. +license: MIT +author: Coffey Labs LLC +collections: + changelog: + layout: release + list_layout: release-list + feed: true + paginate: 0 +notes: | + Add each release as content/changelog/.md, such as + content/changelog/1-4-0.md: + + --- + title: "1.4.0" + date: 2027-01-12 + summary: Faster pages and a new way to share them. + security: true # optional: it fixes a security problem + breaking: true # optional: something works differently now + --- + ### Added + - Share links on every article. + + ### Fixed + - Pages with long tables no longer scroll sideways. + + /changelog/ lists every release, newest first, with its notes, and + /changelog/feed.xml lets people follow new ones. Give the list a title + and an introduction in content/changelog/_index.md. + + The "What's new" section shows the latest releases on any page, and + {{ template "latest-release" . }} in a layout prints a link to the newest + one, for a hero or a footer. + + Group the notes under ### Added, Changed, Deprecated, Removed, Fixed and + Security (keepachangelog.com), or headings of your own. diff --git a/packs/changelog/partials/latest-release.html b/packs/changelog/partials/latest-release.html new file mode 100644 index 0000000..9bec57c --- /dev/null +++ b/packs/changelog/partials/latest-release.html @@ -0,0 +1,2 @@ +{{/* A link to the newest release in content/changelog/, for a hero or a footer. */}} +{{ range limit 1 (collection "changelog") }}Latest {{ .Title }}{{ if not .Date.IsZero }} · {{ end }}{{ end }} diff --git a/packs/changelog/partials/release-tags.html b/packs/changelog/partials/release-tags.html new file mode 100644 index 0000000..aacac31 --- /dev/null +++ b/packs/changelog/partials/release-tags.html @@ -0,0 +1,2 @@ +{{/* A release's date and what kind of release it is. */}} +

{{ if not .Date.IsZero }}{{ end }}{{ if .Params.security }} Security fix{{ end }}{{ if .Params.breaking }} Breaking changes{{ end }}

diff --git a/packs/changelog/sections/changelog.html b/packs/changelog/sections/changelog.html new file mode 100644 index 0000000..2d59bd9 --- /dev/null +++ b/packs/changelog/sections/changelog.html @@ -0,0 +1,27 @@ +{{/* section +label: What's new +about: The latest releases from the changelog, with a link to all of them. +fields: + - { name: heading, type: text, default: "What's new" } + - { name: collection, type: collection, default: changelog, label: Releases from } + - { name: count, type: number, default: 3, label: How many } + - { name: notes, type: bool, label: "Show each release's notes", help: Otherwise only its summary. } +*/}} +{{ $c := default "changelog" .Data.collection }}{{ $d := .Data }} + +
+
+ {{ with $d.heading }}

{{ . }}

{{ end }} +
    + {{ range limit (default 3 $d.count) (collection $c) }} +
  • + {{ .Title }} + {{ template "release-tags" . }} + {{ with .Summary }}

    {{ . }}

    {{ end }} + {{ if $d.notes }}{{ with .Content }}
    {{ . }}
    {{ end }}{{ end }} +
  • + {{ end }} +
+

Every release

+
+
diff --git a/packs/contact-forms/LICENSE b/packs/contact-forms/LICENSE new file mode 100644 index 0000000..0e54f6b --- /dev/null +++ b/packs/contact-forms/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Coffey Labs LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packs/contact-forms/README.md b/packs/contact-forms/README.md new file mode 100644 index 0000000..6791212 --- /dev/null +++ b/packs/contact-forms/README.md @@ -0,0 +1,24 @@ +# Contact forms pack + +Ready-made forms for a HotDog CMS site, and a section to put them on a page. + + hotdog-cms pack add contact-forms + +- `forms/quote.yaml`: a quote request (what, by when, budget, details). +- `forms/booking.yaml`: a booking request (day, time of day, how many). It + asks; you confirm by email. +- `forms/signup.yaml`: a mailing list sign-up, with a required "yes, email + me" box. +- The **Contact form** section shows any form in `forms/` beside your email, + phone, address and a note, such as your opening hours or how soon you + answer. It works with the contact form every site starts with, too. + +The forms are copied into the site once and are the site's own from then on: +upgrading or removing the pack leaves them alone. They send to +`you@example.org` until you set `to:` and `mailto:` to your own address, and +`hotdog-cms check` warns until you do. Forms are sent by the endpoint +(`hotdog-cms endpoint`), with its spam checks; see HotDog's `docs/forms.md`. + +A pack's forms always send to a placeholder address like that one, never to +an address the pack's author chose, and can't load another site's script, so +adding a pack can't send your visitors' messages anywhere you didn't pick. diff --git a/packs/contact-forms/assets/contact-forms.css b/packs/contact-forms/assets/contact-forms.css new file mode 100644 index 0000000..63b4e0b --- /dev/null +++ b/packs/contact-forms/assets/contact-forms.css @@ -0,0 +1,23 @@ +/* The contact forms pack. Colors come from the theme's variables. */ +.cf-grid { display: grid; gap: 28px 48px; grid-template-columns: minmax(0, 3fr) minmax(220px, 2fr); align-items: start; } +.cf-grid.cf-solo { grid-template-columns: minmax(0, 1fr); } +@media (max-width: 760px) { .cf-grid { grid-template-columns: minmax(0, 1fr); } } +.cf-form .hotdog-form { max-width: none; } +.cf-solo .cf-form .hotdog-form { max-width: 40rem; } +.cf-form .hotdog-field label { font-weight: 600; } +.cf-form .hotdog-field input:not([type="checkbox"]), .cf-form .hotdog-field textarea, .cf-form .hotdog-field select { border: 1px solid var(--line); border-radius: calc(var(--radius) * .6); background: var(--surface); } +.cf-form .hotdog-field input:focus-visible, .cf-form .hotdog-field textarea:focus-visible, .cf-form .hotdog-field select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); } +.cf-form .hotdog-field.cl-checkbox label { font-weight: 400; } +.cf-form .hotdog-field.cl-checkbox input { margin: 0 8px 0 0; } +.cf-form .hotdog-help { color: var(--muted); opacity: 1; } +.cf-form .hotdog-req { color: var(--accent); } +.cf-form button[type="submit"] { padding: 11px 22px; border-radius: 11px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text, #fff); font-weight: 650; } +.cf-form button[type="submit"]:hover { filter: brightness(1.05); } +.cf-form button[type="submit"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; } +.cf-details { padding: 20px 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); display: grid; gap: 14px; } +.cf-line { display: grid; gap: 2px; } +.cf-label { color: var(--muted); font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; } +.cf-line address { font-style: normal; white-space: pre-line; } +.cf-note { padding-top: 14px; border-top: 1px solid var(--line); } +.cf-note > :first-child { margin-top: 0; } +.cf-note > :last-child { margin-bottom: 0; } diff --git a/packs/contact-forms/forms/booking.yaml b/packs/contact-forms/forms/booking.yaml new file mode 100644 index 0000000..312a038 --- /dev/null +++ b/packs/contact-forms/forms/booking.yaml @@ -0,0 +1,22 @@ +# A booking request, from the contact-forms pack: a table, an appointment, a +# lesson. It asks; you confirm by email. It's this site's own form now: +# change it as you like. Before publishing, set to: and mailto: to your own +# address. +title: Booking request +to: you@example.org +subject: "Booking request from {{ .name }} for {{ .date }}" +reply_to: email +fields: + - { name: name, label: Your name, required: true, max: 120 } + - { name: email, type: email, label: Your email, required: true } + - { name: phone, type: tel, label: Phone } + - { name: date, type: text, label: "Which day?", required: true, placeholder: "Saturday, May 9", max: 80 } + - name: time + type: select + label: What time of day? + required: true + options: [Morning, Afternoon, Evening] + - { name: people, type: text, label: "How many people?", max: 40 } + - { name: notes, type: textarea, label: "Anything we should know?", max: 2000 } +submit: Send booking request +mailto: you@example.org diff --git a/packs/contact-forms/forms/quote.yaml b/packs/contact-forms/forms/quote.yaml new file mode 100644 index 0000000..f4ea033 --- /dev/null +++ b/packs/contact-forms/forms/quote.yaml @@ -0,0 +1,21 @@ +# A quote request, from the contact-forms pack. It's this site's own form +# now: change it as you like. Before publishing, set to: and mailto: to your +# own address. +title: Request a quote +to: you@example.org +subject: "Quote request from {{ .name }}: {{ .service }}" +reply_to: email +fields: + - { name: name, label: Your name, required: true, max: 120 } + - { name: email, type: email, label: Your email, required: true } + - { name: phone, type: tel, label: Phone, help: "If you'd rather we called." } + - name: service + type: select + label: What do you need? + required: true + options: [Something new, A change or repair, Something else] + - { name: when, type: text, label: "When do you need it by?", max: 120 } + - { name: budget, type: text, label: Your budget, help: "If you have one in mind.", max: 120 } + - { name: details, type: textarea, label: Tell us about it, required: true, max: 5000 } +submit: Ask for a quote +mailto: you@example.org diff --git a/packs/contact-forms/forms/signup.yaml b/packs/contact-forms/forms/signup.yaml new file mode 100644 index 0000000..d2af69e --- /dev/null +++ b/packs/contact-forms/forms/signup.yaml @@ -0,0 +1,17 @@ +# A mailing list sign-up, from the contact-forms pack. Each sign-up is +# emailed to you; set store: true (and give the endpoint a store folder) to +# keep them in a file too. It's this site's own form now: change it as you +# like. Before publishing, set to: and mailto: to your own address. +title: Join the mailing list +to: you@example.org +subject: "Mailing list sign-up: {{ .email }}" +reply_to: email +fields: + - { name: email, type: email, label: Your email, required: true } + - { name: name, label: Your name, help: "So we know what to call you.", max: 120 } + - name: agree + type: checkbox + label: Yes, email me news. I can unsubscribe at any time. + required: true +submit: Sign me up +mailto: you@example.org diff --git a/packs/contact-forms/pack.yaml b/packs/contact-forms/pack.yaml new file mode 100644 index 0000000..6070b48 --- /dev/null +++ b/packs/contact-forms/pack.yaml @@ -0,0 +1,31 @@ +name: contact-forms +version: 1.0.0 +title: Contact forms +description: Ready-made forms for a quote, a booking and a mailing list, and a section that puts any form beside your email, phone and address. +license: MIT +author: Coffey Labs LLC +notes: | + The forms are in forms/: quote.yaml, booking.yaml and signup.yaml. They're + your site's own now, so change them as you like (in the files, or the + editor's Forms page). First, set each one's to: and mailto: to your own + address. They send to you@example.org until you do, and hotdog-cms check + warns about it. + + Then add a "Contact form" section to a page, in the editor's section + library or in the page's front matter: + + sections: + - contact-form: + heading: Ask for a quote + form: quote + email: hello@example.org + phone: (217) 555-0142 + note: We answer within one working day. + + form: is the name of any form in forms/, including the contact form your + site started with. Forms are sent by the endpoint (hotdog-cms endpoint); + see docs/forms.md. + + The sign-up form emails you each new address. To keep a list in a file as + well, set store: true in forms/signup.yaml and give the endpoint a store + folder. Say in your privacy notice what you do with the addresses. diff --git a/packs/contact-forms/sections/contact-form.html b/packs/contact-forms/sections/contact-form.html new file mode 100644 index 0000000..d740024 --- /dev/null +++ b/packs/contact-forms/sections/contact-form.html @@ -0,0 +1,31 @@ +{{/* section +label: Contact form +about: A form from forms/ beside your email, phone, address and a note, such as when you answer. +fields: + - { name: heading, type: text, default: Get in touch } + - { name: intro, type: markdown } + - { name: form, type: text, default: contact, required: true, help: "The form's name: a file in forms/, such as contact, quote, booking or signup." } + - { name: email, type: text, label: Email } + - { name: phone, type: text, label: Phone } + - { name: address, type: textarea, label: Address } + - { name: note, type: markdown, label: Beside the form, help: "Opening hours, how soon you answer, or anything else." } +*/}} +{{ $d := .Data }}{{ $side := or $d.email $d.phone $d.address $d.note }} + +
+
+ {{ with $d.heading }}

{{ . }}

{{ end }} + {{ with $d.intro }}
{{ markdownify . }}
{{ end }} +
+
{{ form (default "contact" $d.form) }}
+ {{ if $side }} + + {{ end }} +
+
+
diff --git a/packs/packs.go b/packs/packs.go index 8dff950..5bb9379 100644 --- a/packs/packs.go +++ b/packs/packs.go @@ -5,5 +5,5 @@ package packs import "embed" -//go:embed all:calendar all:docs all:downloads all:faq all:gallery all:jobs all:location-and-hours all:menu-and-prices all:payment-links all:podcast all:portfolio all:recipes all:related-posts all:share-links all:shop all:table-of-contents all:team all:testimonials +//go:embed all:calendar all:changelog all:contact-forms all:docs all:downloads all:faq all:gallery all:jobs all:location-and-hours all:menu-and-prices all:payment-links all:podcast all:portfolio all:recipes all:related-posts all:share-links all:shop all:table-of-contents all:tables all:team all:testimonials var FS embed.FS diff --git a/packs/tables/LICENSE b/packs/tables/LICENSE new file mode 100644 index 0000000..0e54f6b --- /dev/null +++ b/packs/tables/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Coffey Labs LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packs/tables/README.md b/packs/tables/README.md new file mode 100644 index 0000000..d55b647 --- /dev/null +++ b/packs/tables/README.md @@ -0,0 +1,24 @@ +# Tables pack + +Tables for a HotDog CMS site, the way people keep them: in a spreadsheet. + + hotdog-cms pack add tables + +Save the sheet as CSV into `data/` (`data/prices.csv`), headings in the first +row, and add a **Table** section with `from: prices`. Update the table by +saving the sheet again. + +It also reads YAML or JSON from `data/`: a list of rows, each a list of +cells, or a list of records with `columns:` naming the keys to show, in +order. A short table can be typed into the section, one row per line with +cells split by `|`. + +- A caption, for everyone and for screen readers. +- Row headings (the first column names each row), numbers lined up on the + right, compact rows, and a note below. +- On a phone, a wide table scrolls sideways inside its frame instead of + stretching the page; it can be scrolled with the keyboard too. +- Cells can hold Markdown links and emphasis, and follow the site's Markdown + rules: HTML in a cell is left out unless the site allows HTML in pages. + +No sorting or filtering: those need a script, and packs carry none. diff --git a/packs/tables/assets/tables.css b/packs/tables/assets/tables.css new file mode 100644 index 0000000..fe69740 --- /dev/null +++ b/packs/tables/assets/tables.css @@ -0,0 +1,15 @@ +/* The tables pack. Colors come from the theme's variables. */ +.tbl-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); } +.tbl-scroll:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } +.tbl { border-collapse: collapse; width: 100%; font-size: .95rem; } +.tbl caption { caption-side: top; text-align: left; padding: 14px 16px 4px; color: var(--muted); font-size: .9rem; } +.tbl th, .tbl td { text-align: left; vertical-align: top; padding: 11px 16px; border-bottom: 1px solid var(--line); } +.tbl thead th { font-size: .82rem; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); white-space: nowrap; border-bottom-width: 2px; } +.tbl tbody tr:last-child > * { border-bottom: 0; } +.tbl tbody tr:nth-child(even) > * { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); } +.tbl-rowheads tbody th { font-weight: 650; } +.tbl-numbers th:not(:first-child), .tbl-numbers td:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; } +.tbl-compact th, .tbl-compact td { padding: 6px 12px; } +.tbl-note { margin-top: 10px; color: var(--muted); font-size: .9rem; } +.tbl-note > :first-child { margin-top: 0; } +.tbl-note > :last-child { margin-bottom: 0; } diff --git a/packs/tables/pack.yaml b/packs/tables/pack.yaml new file mode 100644 index 0000000..4d6db66 --- /dev/null +++ b/packs/tables/pack.yaml @@ -0,0 +1,24 @@ +name: tables +version: 1.0.0 +title: Tables +description: Tables from a spreadsheet saved as CSV, or from YAML, with a caption, row headings and a layout that scrolls on phones instead of breaking. +license: MIT +author: Coffey Labs LLC +notes: | + Save a spreadsheet as CSV into data/, such as data/prices.csv, with the + column headings in its first row. Then add a "Table" section to any page, + in the editor's section library or in the page's front matter: + + sections: + - table: + heading: Prices + from: prices + caption: Prices from January 2027, tax included. + numbers: true + + from: also takes a YAML or JSON file in data/: a list of rows, each a list + of cells; or a list of records with columns: naming the keys to show, in + order. A short table can be typed in the section itself as rows, one row + per line with the cells split by |. + + Cells can hold Markdown links and emphasis. diff --git a/packs/tables/sections/table.html b/packs/tables/sections/table.html new file mode 100644 index 0000000..83c1958 --- /dev/null +++ b/packs/tables/sections/table.html @@ -0,0 +1,41 @@ +{{/* section +label: Table +about: A table from a spreadsheet saved as CSV in data/, or rows typed here. +fields: + - { name: heading, type: text } + - { name: intro, type: markdown } + - { name: from, type: data, label: Table from, help: "A file in data/: a spreadsheet saved as CSV, or YAML or JSON. Leave empty to use the rows below." } + - { name: rows, type: list, label: Rows, help: "One row per line, cells split by |. The first row is the headings." } + - { name: columns, type: list, label: Columns, help: "For a file of records: the keys to show, in order. They're the headings too." } + - { name: caption, type: text, help: What the table shows, for everyone and for screen readers. } + - { name: no_header, type: bool, label: The first row is data, not headings } + - { name: row_headers, type: bool, label: The first column names each row } + - { name: numbers, type: bool, label: Line up numbers on the right, help: Every column but the first. } + - { name: compact, type: bool, label: Compact rows } + - { name: note, type: markdown, label: Below the table, help: Where the figures come from, or a footnote. } +*/}} +{{ $d := .Data }}{{ $rows := $d.rows }}{{ with $d.from }}{{ $rows = data . }}{{ end }} +{{ $grid := list }}{{ $records := false }} +{{ range $rows }}{{ if kindIs "list" . }}{{ $grid = append $grid . }}{{ else if kindIs "map" . }}{{ $records = true }}{{ $r := . }}{{ $cells := list }}{{ range $d.columns }}{{ $cells = append $cells (index $r .) }}{{ end }}{{ $grid = append $grid $cells }}{{ else }}{{ $grid = append $grid (split "|" .) }}{{ end }}{{ end }} +{{ $head := false }}{{ $body := $grid }} +{{ if $records }}{{ $head = $d.columns }}{{ else if and (not $d.no_header) $grid }}{{ $head = index $grid 0 }}{{ $body = slice $grid 1 }}{{ end }} + +
+
+ {{ with $d.heading }}

{{ . }}

{{ end }} + {{ with $d.intro }}
{{ markdownify . }}
{{ end }} + {{ if $grid }} +
+ + {{ with $d.caption }}{{ end }} + {{ with $head }}{{ range . }}{{ end }}{{ end }} + + {{ range $body }}{{ range $i, $c := . }}{{ if and $d.row_headers (eq $i 0) }}{{ else }}{{ end }}{{ end }} + {{ end }} + +
{{ . }}
{{ inline (default "" .) }}
{{ inline (default "" $c) }}{{ inline (default "" $c) }}
+
+ {{ end }} + {{ with $d.note }}
{{ markdownify . }}
{{ end }} +
+