Tests and comments: neutral examples for the shop #36

Merged
jcoffey-dev merged 2 commits from tests/neutral-examples into main 2026-10-17 01:26:58 +00:00
4 changed files with 21 additions and 21 deletions

No files matched your search

+4 -4
View File
@@ -194,11 +194,11 @@ 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 "tags" "Garden" -> that term's page (nil if there is none), with
// what content/tags/garden.md says about it.
"term": s.TermPage,
// tagged "tags" "Linux" (collection "products"): the products tagged
// Linux, in the collection's order.
// tagged "tags" "Garden" (collection "products"): the products tagged
// Garden, in the collection's order.
"tagged": s.Tagged,
// isExternal: an absolute link to another site.
"isExternal": md.External,
+2 -2
View File
@@ -68,8 +68,8 @@ func TestShortSummary(t *testing.T) {
if got := shortSummary(one); len([]rune(got)) > 160 || !strings.HasSuffix(got, "word…") {
t.Errorf("one long sentence: %q (%d)", got, len([]rune(got)))
}
dotted := "A black heavyweight tee with the kitten on it. A small mark sits on the left chest. The full mark and example.org run across the back. Sizes S to 4XL, printed to order."
if got := shortSummary(dotted); got != "A black heavyweight tee with the kitten on it. A small mark sits on the left chest. The full mark and example.org run across the back." {
dotted := "A green canvas apron with a deep pocket for your garden tools. A small logo sits on the chest. The full logo and example.org run across the back. Sizes S to XL, made to order."
if got := shortSummary(dotted); got != "A green canvas apron with a deep pocket for your garden tools. A small logo sits on the chest. The full logo and example.org run across the back." {
t.Errorf("a full stop inside a word: %q", got)
}
if got := shortSummary("Short and sweet."); got != "Short and sweet." {
+10 -10
View File
@@ -160,23 +160,23 @@ 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/hoodie.md", "---\ntitle: Hoodie\nprice: 40\ncurrency: USD\nweight: 4\nphotos:\n - { image: /media/a.png, alt: Hoodie in red, group: Red }\n - { image: /media/b.png, alt: Hoodie in blue, group: Blue }\nchoose: Size\nvariants:\n - { group: Red, name: S, price: 40, id: r1 }\n - { group: Red, name: M, price: 40, id: r2 }\n - { group: Blue, name: S, price: 40, id: b1 }\ncheckout: { action: \"https://shop.example/cart/checkout\", field: products, item: \"{id}:{qty}\" }\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\ntags: [linux]\nvariants:\n - { group: Black, name: One size, price: 20, value: \"c1:1\" }\ncheckout: { action: \"https://shop.example/cart/checkout\" }\n---\n"},
{"content/products/tee.md", "---\ntitle: Tee\nsummary: A tee.\nprice: 24\nprice_from: true\ncurrency: USD\nweight: 3\ntags: [Garden, 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\ntags: [garden]\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/garden.md", "---\ntitle: Garden things\nlayout: shelf\n---\nFor people with dirt under their nails.\n"},
{"content/tags/kitchen.md", "---\ntitle: Kitchen\n---\nComing soon.\n"},
{"content/tags/shirts.md", "---\ntitle: Shirts\nsummary: Cotton, mostly.\nlayout: shelf\n---\n"},
{"content/picks.md", "---\ntitle: Picks\nsummary: Picks.\nsections:\n - products: { heading: Penguin picks, tag: Linux, more: All Linux things }\n---\n"},
{"content/picks.md", "---\ntitle: Picks\nsummary: Picks.\nsections:\n - products: { heading: Gardener's picks, tag: Garden, more: All garden 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": {`<form class="product-form" method="get" action="https://shop.example/cart/checkout" data-cart data-field="products" data-item="{id}:{qty}" data-join="," data-title="Tee" data-href="/products/tee/" data-currency="USD" data-image="/media/a.png">`, `<input type="hidden" name="currency" value="USD">`, "<legend>Size</legend>", `name="products" value="v1:1" required data-option="S" data-cart-variant data-id="v1" data-name="S" data-price="24">`, "2XL <small>$26.00</small>", `value="v3:1" required disabled data-option="3XL" data-cart-variant`, "<span>3XL <small>sold out</small>", `data-cart-add hidden>Add to cart</button>`, `product-buy-button" type="submit">Buy now</button>`, `<script src="/hotdog-cart.`, `data-page="/cart/"`, `<a class="cart-link" href="/cart/" data-cart-link hidden>`, `<span class="product-from">From</span> $24.00`, `"@type":"AggregateOffer"`, `"lowPrice":"24.00"`, `"highPrice":"28.00"`, `"offerCount":3`},
"products/cap/index.html": {`<input type="hidden" name="products" value="c1:1" data-cart-variant data-id="c1:1" data-name="Black · One size" data-price="20">`, ">Buy now</button>"},
"cart/index.html": {`<div class="cart-view" data-cart-view data-shop="/products/">`, "The cart needs JavaScript.", `data-cart-suggest data-count="3" hidden>`, `<li class="shop-card" data-product="/products/tee/" data-tags="Linux,Shirts">`},
"cart/index.html": {`<div class="cart-view" data-cart-view data-shop="/products/">`, "The cart needs JavaScript.", `data-cart-suggest data-count="3" hidden>`, `<li class="shop-card" data-product="/products/tee/" data-tags="Garden,Shirts">`},
"privacy/index.html": {"What you put in your cart"},
"tags/linux/index.html": {"<h1>Linux things</h1>", "For the penguin people.", `class="wrap page shop shelf"`, `data-product="/products/tee/"`, `data-product="/products/cap/"`},
"tags/garden/index.html": {"<h1>Garden things</h1>", "For people with dirt under their nails.", `class="wrap page shop shelf"`, `data-product="/products/tee/"`, `data-product="/products/cap/"`},
"tags/kitchen/index.html": {"Kitchen", "Coming soon."},
"tags/shirts/index.html": {`<p class="shelf-summary">Cotton, mostly.</p>`, `data-product="/products/tee/"`},
"picks/index.html": {"Penguin picks", `data-product="/products/tee/"`, `data-product="/products/cap/"`, `href="/tags/linux/">All Linux things`},
"picks/index.html": {"Gardener&#39;s picks", `data-product="/products/tee/"`, `data-product="/products/cap/"`, `href="/tags/garden/">All garden things`},
"products/print/index.html": {`href="https://buy.stripe.com/a4" rel="noopener">Matte · A4 · $30.00`, `<span class="btn variant-sold">Matte · A3 · sold out</span>`},
"products/index.html": {`href="/products/kit/"`, "$24.00", "€12.00 · <em>Sold out</em>"},
"products/hoodie/index.html": {`<label class="variant-group" data-group-pick hidden><span>Color</span>`, `<select data-group-select data-choose="Size"><option>Red</option><option>Blue</option></select>`, `<script src="/hotdog-variants.`, `<fieldset class="variants" data-group="Blue"><legend>Blue</legend>`, `<div class="photo-slide" data-group="Blue">`, `<label class="photo-pick" data-group="Red">`},
@@ -312,9 +312,9 @@ func TestBundledPacksBuildAndPass(t *testing.T) {
"link-in-bio": {"links/index.html": {`<header class="top">`}},
"coming-soon": {"soon/index.html": {`<header class="top">`}},
"shop": {
"tags/linux/index.html": {`data-product="/products/kit/"`},
"picks/index.html": {`data-product="/products/kit/"`},
"tags/index.html": {"/tags/kitchen/"},
"tags/garden/index.html": {`data-product="/products/kit/"`},
"picks/index.html": {`data-product="/products/kit/"`},
"tags/index.html": {"/tags/kitchen/"},
},
}
for _, c := range cases {
+5 -5
View File
@@ -65,8 +65,8 @@ func mostUsed(counts map[string]int, seen []string) string {
}
// A folder in content/ named for a taxonomy describes its terms instead of
// being a collection: content/tags/linux.md (or tags/linux/index.md) gives
// /tags/linux/ a title, words, a picture, a layout and any other front
// being a collection: content/tags/garden.md (or tags/garden/index.md) gives
// /tags/garden/ a title, words, a picture, a layout and any other front
// matter, and content/tags/_index.md does the same for /tags/. The term's
// pages are still listed by the taxonomy.
func (s *Site) takeTermDocs() {
@@ -245,8 +245,8 @@ func (s *Site) Terms(tax string) []TermInfo {
}
// TermPage is the page of the term a spelling belongs to, or nil if there is
// none: term "tags" "Linux" has the title, words and front matter of
// content/tags/linux.md, when there is one, and the pages tagged Linux.
// none: term "tags" "Garden" has the title, words and front matter of
// content/tags/garden.md, when there is one, and the pages tagged Garden.
func (s *Site) TermPage(tax, v string) *Page {
ti := s.terms[tax]
if ti == nil {
@@ -259,7 +259,7 @@ func (s *Site) TermPage(tax, v string) *Page {
}
// Tagged keeps the pages that carry a term, in the order given: tagged
// "tags" "Linux" (collection "products") is the products tagged Linux, in
// "tags" "Garden" (collection "products") is the products tagged Garden, in
// the shop's order. Any spelling of the term matches, as on its page.
func (s *Site) Tagged(tax, v string, pages []*Page) []*Page {
ti := s.terms[tax]