From 1affc685f1a1d736cce58731c53936788f9f4cba Mon Sep 17 00:00:00 2001 From: John Coffey Date: Fri, 16 Oct 2026 15:59:11 -0700 Subject: [PATCH 1/3] Shelves: tag pages with words of their own, and tagged products A file in content// now describes a term instead of becoming a collection: content/tags/linux.md gives /tags/linux/ its title, words, picture, layout and front matter. The term and tagged template functions find a term's page and keep the pages carrying a term, in the order given. Shop pack 1.3.0: a shelf layout for tag pages, and a tag field on the Products section. --- internal/build/funcs.go | 6 ++ internal/editor/quick.go | 6 +- internal/packs/bundled_test.go | 13 +++- internal/site/load.go | 2 + internal/site/taxonomy.go | 99 +++++++++++++++++++++++++++++++ internal/site/taxonomy_test.go | 68 +++++++++++++++++++++ packs/shop/README.md | 10 +++- packs/shop/layouts/shelf.html | 13 ++++ packs/shop/pack.yaml | 15 ++++- packs/shop/sections/products.html | 13 ++-- 10 files changed, 234 insertions(+), 11 deletions(-) create mode 100644 internal/site/taxonomy_test.go create mode 100644 packs/shop/layouts/shelf.html diff --git a/internal/build/funcs.go b/internal/build/funcs.go index 1503138..f30aab8 100644 --- a/internal/build/funcs.go +++ b/internal/build/funcs.go @@ -194,6 +194,12 @@ func funcs(s *site.Site, a *Assets, md *site.Markdown, icons Icons) template.Fun "excerpt": func(n int, v any) string { return site.Excerpt(n, fmt.Sprint(v)) }, // termURL "tags" "Open Source" -> /tags/open-source/ (or "" if it has none). "termURL": s.TermURL, + // term "tags" "Linux" -> that term's page (nil if there is none), with + // what content/tags/linux.md says about it. + "term": s.TermPage, + // tagged "tags" "Linux" (collection "products"): the products tagged + // Linux, in the collection's order. + "tagged": s.Tagged, // isExternal: an absolute link to another site. "isExternal": md.External, // Cloudflare's markers that turn Email Address Obfuscation off for a diff --git a/internal/editor/quick.go b/internal/editor/quick.go index 34144a1..9f65a58 100644 --- a/internal/editor/quick.go +++ b/internal/editor/quick.go @@ -8,6 +8,7 @@ import ( "path" "path/filepath" "regexp" + "slices" "sort" "strings" "time" @@ -79,7 +80,8 @@ func (s *Server) apiQuick(w http.ResponseWriter, r *http.Request, sess *Session, } // collectionNames lists the site's collections: folders in content/, and -// any configured in site.yaml. +// any configured in site.yaml. A folder named for a taxonomy (content/tags/) +// describes its terms and isn't one. func collectionNames(siteDir string, cfg *site.Config) []string { seen := map[string]bool{} entries, _ := os.ReadDir(filepath.Join(siteDir, "content")) @@ -93,7 +95,7 @@ func collectionNames(siteDir string, cfg *site.Config) []string { } var out []string for name := range seen { - if slug(name) == name { + if slug(name) == name && !slices.Contains(cfg.Taxonomies, name) { out = append(out, name) } } diff --git a/internal/packs/bundled_test.go b/internal/packs/bundled_test.go index 6ba227d..9689131 100644 --- a/internal/packs/bundled_test.go +++ b/internal/packs/bundled_test.go @@ -160,14 +160,20 @@ func TestBundledPacksBuildAndPass(t *testing.T) { {"content/products/kit.md", "---\ntitle: Starter kit\nsummary: A jar of starter.\nprice: 24\ncurrency: USD\nweight: 1\nphotos:\n - { image: /media/a.png, alt: A jar }\n - { image: /media/b.png, alt: The card }\nbuy: \"https://buy.stripe.com/test_1\"\noptions:\n - { name: With a basket, price: 39.5, buy: \"https://buy.stripe.com/test_2\" }\n---\nWhat's in the box.\n"}, {"content/products/mug.md", "---\ntitle: Mug\nsummary: A mug.\nprice: 12\ncurrency: EUR\nweight: 2\nsold_out: true\n---\n"}, {"content/products/tee.md", "---\ntitle: Tee\nsummary: A tee.\nprice: 24\nprice_from: true\ncurrency: USD\nweight: 3\ntags: [Linux, Shirts]\nphotos:\n - { image: /media/a.png, alt: The tee }\nchoose: Size\nvariants:\n - { name: S, price: 24, id: v1 }\n - { name: 2XL, price: 26, id: v2 }\n - { name: 3XL, price: 28, id: v3, sold_out: true }\ncheckout: { action: \"https://shop.example/cart/checkout\", field: products, item: \"{id}:{qty}\", join: \",\", fields: { currency: USD } }\n---\n"}, - {"content/products/cap.md", "---\ntitle: Cap\nsummary: A cap.\nprice: 20\ncurrency: USD\nweight: 4\nvariants:\n - { group: Black, name: One size, price: 20, value: \"c1:1\" }\ncheckout: { action: \"https://shop.example/cart/checkout\" }\n---\n"}, + {"content/products/cap.md", "---\ntitle: Cap\nsummary: A cap.\nprice: 20\ncurrency: USD\nweight: 4\ntags: [linux]\nvariants:\n - { group: Black, name: One size, price: 20, value: \"c1:1\" }\ncheckout: { action: \"https://shop.example/cart/checkout\" }\n---\n"}, {"content/cart.md", "---\ntitle: Your cart\nlayout: cart\nsuggest: 3\n---\n"}, + {"content/tags/linux.md", "---\ntitle: Linux things\nlayout: shelf\n---\nFor the penguin people.\n"}, + {"content/tags/kitchen.md", "---\ntitle: Kitchen\n---\nComing soon.\n"}, + {"content/picks.md", "---\ntitle: Picks\nsummary: Picks.\nsections:\n - products: { heading: Penguin picks, tag: Linux, more: All Linux things }\n---\n"}, {"content/products/print.md", "---\ntitle: Print\nsummary: A print.\nprice: 30\ncurrency: USD\nweight: 5\nvariants:\n - { group: Matte, name: A4, price: 30, buy: \"https://buy.stripe.com/a4\" }\n - { group: Matte, name: A3, price: 40, buy: \"https://buy.stripe.com/a3\", sold_out: true }\n---\n"}, }, map[string][]string{ "products/tee/index.html": {`
`, ``, "Size", `name="products" value="v1:1" required data-cart-variant data-id="v1" data-name="S" data-price="24">`, "2XL $26.00", `value="v3:1" required disabled data-cart-variant`, "3XL sold out", `data-cart-add hidden>Add to cart`, `product-buy-button" type="submit">Buy now`, `