Three packs: contact forms, tables and a changelog #26
No files matched your search
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 `[email protected]`, 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/<name>/`, so two packs
|
||||
never collide. Refer to them that way:
|
||||
|
||||
+1
-1
@@ -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.
|
||||
|
||||
@@ -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
|
||||
},
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -192,3 +192,27 @@ func TestEveryRuleHasAFix(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormPlaceholder(t *testing.T) {
|
||||
dir, out, cfg := mkSite(t, map[string]string{"index.html": "<html><head>" + head + "</head></html>"}, "")
|
||||
os.MkdirAll(filepath.Join(dir, "forms"), 0o755)
|
||||
os.WriteFile(filepath.Join(dir, "forms", "quote.yaml"), []byte("to: [email protected]\nfields: [{name: a}]\n"), 0o644)
|
||||
os.WriteFile(filepath.Join(dir, "forms", "signup.yaml"), []byte("to: [email protected]\nmailto: [email protected]\nfields: [{name: a}]\n"), 0o644)
|
||||
os.WriteFile(filepath.Join(dir, "forms", "contact.yaml"), []byte("to: [email protected]\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)
|
||||
}
|
||||
}
|
||||
@@ -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.",
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
+27
-1
@@ -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
|
||||
|
||||
@@ -71,6 +71,8 @@ func TestDefinitionErrors(t *testing.T) {
|
||||
"to: [email protected]\nfields: [{name: _t}]\n",
|
||||
"to: [email protected]\nreply_to: a\nfields: [{name: a}]\n",
|
||||
"to: [email protected]\nsuccess: https://evil.example/\nfields: [{name: a}]\n",
|
||||
"to: [email protected]\nsuccess: //evil.example/\nfields: [{name: a}]\n",
|
||||
"to: [email protected]\nsuccess: /\\evil.example/\nfields: [{name: a}]\n",
|
||||
"to: [email protected]\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{
|
||||
"[email protected]": true,
|
||||
"[email protected]": true,
|
||||
"[email protected]": true,
|
||||
"[email protected]": true,
|
||||
"[email protected]": true,
|
||||
"[email protected]": true,
|
||||
"Name <[email protected]>": true,
|
||||
"[email protected]": false,
|
||||
"[email protected]": false,
|
||||
"[email protected]": false,
|
||||
"not an address": false,
|
||||
"[email protected]": false,
|
||||
"[email protected]": false,
|
||||
} {
|
||||
if got := Placeholder(addr); got != want {
|
||||
t.Errorf("Placeholder(%q) = %v, want %v", addr, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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: [email protected]\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"`, "<option>A change or repair</option>", ">Ask for a quote</button>", `class="cf-details"`, `href="mailto:[email protected]"`, "tel:%28217%29555-0142", "12 Main Street", "<strong>one</strong>", "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"`, "<option>Evening</option>"},
|
||||
}},
|
||||
{"tables", []page{
|
||||
{"data/prices.csv", "\ufeffItem,Small,Large\nSourdough,$6,$8\n\"Rye, dark\",$5,$7\n[Gift card](/prices/),<b>$25</b>,\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": {"<caption>Tax included.</caption>", `<th scope="col">Item</th>`, `<th scope="col">Large</th>`, `<th scope="row">Sourdough</th><td>$6</td>`, `<th scope="row">Rye, dark</th>`, `<a href="/prices/">Gift card</a>`, "<td><!-- raw HTML omitted -->$25<!-- raw HTML omitted --></td>", "tbl tbl-numbers tbl-rowheads", `aria-label="Tax included."`, "<strong>January</strong>", `<th scope="col">name</th><th scope="col">start</th>`, "<td>Sam</td><td>2019</td>", "<td>Ana</td><td></td>", "tbl tbl-compact", "<td>Monday</td><td>Closed</td>", "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", "<h3", "Faster builds.", `href="/changelog/feed.xml">Follow new releases`, "October 12, 2026"},
|
||||
"changelog/1-1-0/index.html": {"<h1>1.1.0</h1>", "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), "</footer>", `{{ template "latest-release" . }}</footer>`, 1)), 0o644)
|
||||
}
|
||||
if c.pack == "related-posts" || c.pack == "table-of-contents" {
|
||||
lp := filepath.Join(dir, "layouts", "article.html")
|
||||
raw, _ := os.ReadFile(lp)
|
||||
|
||||
+56
-2
@@ -18,6 +18,12 @@
|
||||
// layouts/…, assets/…. Assets are installed under assets/packs/<name>/, 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/<name>.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 [email protected], 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 [email protected], 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)
|
||||
}
|
||||
|
||||
@@ -226,3 +226,67 @@ func TestMarkupTricks(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPackForms(t *testing.T) {
|
||||
form := "title: Quote\nto: [email protected]\nfields: [{name: details, type: textarea}]\nmailto: [email protected]\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": `<div>{{ form "quote" }}</div>`,
|
||||
})
|
||||
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: [email protected]\nfields: [{name: a}]\n",
|
||||
"its own mailto": "to: [email protected]\nmailto: [email protected]\nfields: [{name: a}]\n",
|
||||
"turnstile": "to: [email protected]\nturnstile_sitekey: 0x4AAA\nfields: [{name: a}]\n",
|
||||
"a broken form": "to: [email protected]\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: [email protected]\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), "[email protected]") {
|
||||
t.Error("the site's own form was replaced")
|
||||
}
|
||||
quote := filepath.Join(dir, "forms", "quote.yaml")
|
||||
os.WriteFile(quote, []byte(strings.ReplaceAll(form, "[email protected]", "[email protected]")), 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), "[email protected]") {
|
||||
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")
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
+25
-1
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
@@ -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.
|
||||
@@ -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; }
|
||||
@@ -0,0 +1,20 @@
|
||||
{{ define "main" }}
|
||||
<link rel="stylesheet" href="{{ asset "packs/changelog/changelog.css" }}">
|
||||
<section class="wrap page releases">
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ with .Content }}<div class="prose">{{ . }}</div>{{ end }}
|
||||
{{ $name := .Collection }}{{ with index .Site.Config.Collections $name }}{{ if .Feed }}{{ $feed := .FeedPath }}{{ if not $feed }}{{ $feed = printf "/%s/feed.xml" $name }}{{ end }}
|
||||
<p class="rel-follow"><a href="{{ $feed }}">Follow new releases</a> in a feed reader.</p>
|
||||
{{ end }}{{ end }}
|
||||
{{ range collection $name }}
|
||||
<article class="rel-entry" id="{{ slugify .Title }}">
|
||||
<h2><a href="{{ .Href }}">{{ .Title }}</a></h2>
|
||||
{{ template "release-tags" . }}
|
||||
{{ with .Summary }}<p class="rel-summary">{{ . }}</p>{{ end }}
|
||||
{{ with .Content }}<div class="prose rel-notes">{{ . }}</div>{{ end }}
|
||||
</article>
|
||||
{{ else }}
|
||||
<p class="rel-none">No releases yet.</p>
|
||||
{{ end }}
|
||||
</section>
|
||||
{{ end }}
|
||||
@@ -0,0 +1,19 @@
|
||||
{{ define "main" }}
|
||||
<link rel="stylesheet" href="{{ asset "packs/changelog/changelog.css" }}">
|
||||
<article class="wrap page release">
|
||||
{{ $list := index .Site.Lists .Collection }}
|
||||
{{ with $list }}<p class="eyebrow"><a href="{{ .Path }}">{{ .Title }}</a></p>{{ end }}
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ template "release-tags" . }}
|
||||
{{ with .Summary }}<p class="rel-summary">{{ . }}</p>{{ end }}
|
||||
{{ with .Content }}<h2 class="rel-hidden">What changed</h2><div class="prose rel-notes">{{ . }}</div>{{ 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 }}
|
||||
<nav class="rel-nav" aria-label="Other releases">
|
||||
{{ with $older }}<a class="rel-older" href="{{ .Href }}"><span>Older</span>{{ .Title }}</a>{{ end }}
|
||||
{{ with $newer }}<a class="rel-newer" href="{{ .Href }}"><span>Newer</span>{{ .Title }}</a>{{ end }}
|
||||
</nav>
|
||||
{{ end }}
|
||||
</article>
|
||||
{{ end }}
|
||||
@@ -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/<version>.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.
|
||||
@@ -0,0 +1,2 @@
|
||||
{{/* A link to the newest release in content/changelog/, for a hero or a footer. */}}
|
||||
{{ range limit 1 (collection "changelog") }}<a class="rel-latest" href="{{ .Href }}"><span class="rel-latest-label">Latest</span> {{ .Title }}{{ if not .Date.IsZero }} · <time datetime="{{ date "iso" .Date }}">{{ date "January 2, 2006" .Date }}</time>{{ end }}</a>{{ end }}
|
||||
@@ -0,0 +1,2 @@
|
||||
{{/* A release's date and what kind of release it is. */}}
|
||||
<p class="rel-meta">{{ if not .Date.IsZero }}<time datetime="{{ date "iso" .Date }}">{{ date "January 2, 2006" .Date }}</time>{{ end }}{{ if .Params.security }} <span class="rel-tag rel-security">Security fix</span>{{ end }}{{ if .Params.breaking }} <span class="rel-tag rel-breaking">Breaking changes</span>{{ end }}</p>
|
||||
@@ -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 }}
|
||||
<link rel="stylesheet" href="{{ asset "packs/changelog/changelog.css" }}">
|
||||
<section class="block changelog">
|
||||
<div class="wrap">
|
||||
{{ with $d.heading }}<h2>{{ . }}</h2>{{ end }}
|
||||
<ul class="rel-list">
|
||||
{{ range limit (default 3 $d.count) (collection $c) }}
|
||||
<li class="rel-item">
|
||||
<a class="rel-title" href="{{ .Href }}">{{ .Title }}</a>
|
||||
{{ template "release-tags" . }}
|
||||
{{ with .Summary }}<p class="rel-summary">{{ . }}</p>{{ end }}
|
||||
{{ if $d.notes }}{{ with .Content }}<div class="prose rel-notes">{{ . }}</div>{{ end }}{{ end }}
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
<p><a class="more" href="/{{ $c }}/">Every release</a></p>
|
||||
</div>
|
||||
</section>
|
||||
@@ -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.
|
||||
@@ -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
|
||||
`[email protected]` 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.
|
||||
@@ -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; }
|
||||
@@ -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: [email protected]
|
||||
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: [email protected]
|
||||
@@ -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: [email protected]
|
||||
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: [email protected]
|
||||
@@ -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: [email protected]
|
||||
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: [email protected]
|
||||
@@ -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 [email protected] 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: [email protected]
|
||||
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.
|
||||
@@ -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 }}
|
||||
<link rel="stylesheet" href="{{ asset "packs/contact-forms/contact-forms.css" }}">
|
||||
<section class="block contact-form">
|
||||
<div class="wrap">
|
||||
{{ with $d.heading }}<h2>{{ . }}</h2>{{ end }}
|
||||
{{ with $d.intro }}<div class="intro">{{ markdownify . }}</div>{{ end }}
|
||||
<div class="cf-grid{{ if not $side }} cf-solo{{ end }}">
|
||||
<div class="cf-form">{{ form (default "contact" $d.form) }}</div>
|
||||
{{ if $side }}
|
||||
<aside class="cf-details">
|
||||
{{ with $d.email }}<div class="cf-line"><span class="cf-label">Email</span>{{ emailOff }}<a href="mailto:{{ . }}">{{ . }}</a>{{ emailOffEnd }}</div>{{ end }}
|
||||
{{ with $d.phone }}<div class="cf-line"><span class="cf-label">Phone</span><a href="tel:{{ replace " " "" . }}">{{ . }}</a></div>{{ end }}
|
||||
{{ with $d.address }}<div class="cf-line"><span class="cf-label">Address</span><address>{{ . }}</address></div>{{ end }}
|
||||
{{ with $d.note }}<div class="cf-note">{{ markdownify . }}</div>{{ end }}
|
||||
</aside>
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
+1
-1
@@ -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
|
||||
@@ -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.
|
||||
@@ -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.
|
||||
@@ -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; }
|
||||
@@ -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.
|
||||
@@ -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 }}
|
||||
<link rel="stylesheet" href="{{ asset "packs/tables/tables.css" }}">
|
||||
<section class="block table-block">
|
||||
<div class="wrap">
|
||||
{{ with $d.heading }}<h2>{{ . }}</h2>{{ end }}
|
||||
{{ with $d.intro }}<div class="intro">{{ markdownify . }}</div>{{ end }}
|
||||
{{ if $grid }}
|
||||
<div class="tbl-scroll" role="region" tabindex="0" aria-label="{{ or $d.caption $d.heading "Table" }}">
|
||||
<table class="tbl{{ if $d.numbers }} tbl-numbers{{ end }}{{ if $d.compact }} tbl-compact{{ end }}{{ if $d.row_headers }} tbl-rowheads{{ end }}">
|
||||
{{ with $d.caption }}<caption>{{ . }}</caption>{{ end }}
|
||||
{{ with $head }}<thead><tr>{{ range . }}<th scope="col">{{ inline (default "" .) }}</th>{{ end }}</tr></thead>{{ end }}
|
||||
<tbody>
|
||||
{{ range $body }}<tr>{{ range $i, $c := . }}{{ if and $d.row_headers (eq $i 0) }}<th scope="row">{{ inline (default "" $c) }}</th>{{ else }}<td>{{ inline (default "" $c) }}</td>{{ end }}{{ end }}</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ with $d.note }}<div class="tbl-note">{{ markdownify . }}</div>{{ end }}
|
||||
</div>
|
||||
</section>
|
||||
Reference in new issue
Block a user