@backgold/template-kit 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-KOB36GSF.js → chunk-RJAVFRC6.js} +9 -4
- package/dist/{constants-DvTNj4JI.d-Batjcj3Z.d.ts → constants-BAIo_Q5U.d-lQbj1e1-.d.ts} +11 -1
- package/dist/{content-api-CYeY0vU8.d.ts → content-api-Cox1-wz5.d.ts} +250 -3
- package/dist/contract/content-api-examples.d.ts +17 -3
- package/dist/contract/content-api-examples.js +146 -3
- package/dist/contract/content-api.d.ts +2 -2
- package/dist/contract/content-api.js +1 -1
- package/dist/contract/site-templates.d.ts +4 -3
- package/dist/contract/site-templates.js +1 -1
- package/package.json +5 -5
- package/src/components/chrome/Brand.astro +23 -16
- package/src/components/sections/About/credentials.ts +0 -10
- package/src/components/sections/About/index.astro +6 -3
- package/src/components/sections/About/left.astro +6 -3
- package/src/components/sections/About/letter.astro +6 -3
- package/src/components/sections/About/portrait.astro +2 -2
- package/src/components/sections/ContentPost/lesson.ts +14 -7
- package/src/components/sections/ContentPost/prose.astro +80 -0
- package/src/components/sections/Hero/cover.astro +9 -3
- package/src/components/sections/Hero/donate.astro +3 -3
- package/src/components/sections/Hero/index.astro +2 -2
- package/src/components/sections/Hero/overlap.astro +3 -3
- package/src/components/sections/Hero/split.astro +9 -6
- package/src/components/sections/Hero/statement.astro +3 -3
- package/src/components/sections/Hero/video.astro +3 -3
- package/src/components/sections/VoterTools/Lookup.astro +43 -0
- package/src/components/sections/VoterTools/dates.astro +9 -5
- package/src/components/sections/VoterTools/index.astro +12 -9
- package/src/components/sections/VoterTools/polling.astro +9 -6
- package/src/components/sections/VoterTools/voter-tools.ts +5 -4
- package/src/components/sections/index.ts +3 -0
- package/src/components/sections/modules/ModuleFrame.astro +4 -2
- package/src/components/store/CollectionPage.astro +40 -0
- package/src/components/store/ProductCard.astro +32 -0
- package/src/components/store/ProductGrid.astro +16 -0
- package/src/components/store/ProductPage.astro +146 -0
- package/src/components/store/StorePage.astro +137 -0
- package/src/components/store/StoreScript.astro +572 -0
- package/src/components/volunteer/props.ts +1 -1
- package/src/index.js +0 -1
- package/src/layouts/Site.astro +19 -3
- package/src/lib/chrome.ts +6 -4
- package/src/lib/donate-frame.ts +44 -4
- package/src/lib/live.ts +6 -5
- package/src/lib/section.ts +11 -0
- package/src/lib/shifts.ts +2 -1
- package/src/lib/store.ts +521 -0
- package/src/routes/catch-all.astro +168 -19
- package/src/styles/site.css +71 -0
- package/src/styles/store.css +634 -0
- package/src/template.ts +1 -1
- package/src/routes/volunteer.astro +0 -37
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
---
|
|
2
|
-
// VoterTools, 'register' layout, the default (mock 02, A
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// registration link as the main call and the
|
|
7
|
-
// outline beside it (the polling link is the main
|
|
8
|
-
// registration link). The second, raised on the band's card colour, is the
|
|
2
|
+
// VoterTools, 'register' layout, the default (mock 02, A; the registration
|
|
3
|
+
// check is the official one the organization links to). Two cards side by
|
|
4
|
+
// side, stacked on a phone. The first asks: the kicker, the heading and the
|
|
5
|
+
// body, then BackGold's polling-place lookup when the section carries it
|
|
6
|
+
// (Lookup.astro), then the registration link as the main call and the
|
|
7
|
+
// polling-place link as an outline beside it (the polling link is the main
|
|
8
|
+
// call when there is no registration link). The second, raised on the band's card colour, is the
|
|
9
9
|
// visitor's plan: the election-day line in the display face, the early
|
|
10
10
|
// voting line under it, the ID note as a chip, then the key dates under
|
|
11
11
|
// `datesHeading`, each with its label, its day and its note; DaysLeft writes
|
|
@@ -17,6 +17,7 @@ import type { Section } from '@backgold/content'
|
|
|
17
17
|
import Band from '../Band.astro'
|
|
18
18
|
import Prose from '../../Prose.astro'
|
|
19
19
|
import DaysLeft from './DaysLeft.astro'
|
|
20
|
+
import Lookup from './Lookup.astro'
|
|
20
21
|
import { voterTools } from './voter-tools'
|
|
21
22
|
import { prose } from '../../../lib/format'
|
|
22
23
|
|
|
@@ -28,9 +29,10 @@ interface Props {
|
|
|
28
29
|
const { section } = Astro.props
|
|
29
30
|
const vt = voterTools(section)
|
|
30
31
|
const buttons = [vt.register, vt.polling].filter((link) => link !== null)
|
|
31
|
-
const
|
|
32
|
+
const lookup = !!section.embed
|
|
33
|
+
const asks = !!(vt.kicker || vt.heading || prose(section.copy.body) || buttons.length > 0 || lookup)
|
|
32
34
|
const plan = !!(vt.electionDay || vt.earlyVoting || vt.idNote || vt.dates.length > 0)
|
|
33
|
-
const shown = !!(vt.heading || buttons.length > 0 || vt.dates.length > 0)
|
|
35
|
+
const shown = !!(vt.heading || buttons.length > 0 || vt.dates.length > 0 || lookup)
|
|
34
36
|
---
|
|
35
37
|
{shown && (
|
|
36
38
|
<Band section={section} class="voter-tools vt-register">
|
|
@@ -40,6 +42,7 @@ const shown = !!(vt.heading || buttons.length > 0 || vt.dates.length > 0)
|
|
|
40
42
|
{vt.kicker && <p class="kicker">{vt.kicker}</p>}
|
|
41
43
|
{vt.heading && <h2>{vt.heading}</h2>}
|
|
42
44
|
<Prose value={section.copy.body} class="vt-body" />
|
|
45
|
+
{lookup && <Lookup section={section} />}
|
|
43
46
|
{buttons.length > 0 && (
|
|
44
47
|
<p class="actions vt-actions">
|
|
45
48
|
{buttons.map((link, i) => <a class:list={['button', i > 0 && 'button-quiet']} href={link.href} rel={link.rel}>{link.label}</a>)}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
---
|
|
2
|
-
// VoterTools, 'polling' layout (mock 02, B
|
|
3
|
-
// map: BackGold has no polling-place lookup of its own, so the finder is the
|
|
4
|
-
// official one the organization links to). The polling-place card leads,
|
|
2
|
+
// VoterTools, 'polling' layout (mock 02, B). The polling-place card leads,
|
|
5
3
|
// raised on the band's card colour: the kicker, the heading and the body,
|
|
6
|
-
//
|
|
4
|
+
// BackGold's polling-place lookup when the section carries it (Lookup.astro:
|
|
5
|
+
// the address search the mock drew, answered by BackGold), the official
|
|
6
|
+
// polling-place link as the main call, then under a rule the early
|
|
7
7
|
// voting line and the ID note as a chip. Beside it (under it on a phone) the
|
|
8
8
|
// election-day card: the election-day line large in the display face, with
|
|
9
9
|
// an accent rule over it, and the registration link as an outline (the main
|
|
@@ -15,6 +15,7 @@ import type { ComponentProps } from 'astro/types'
|
|
|
15
15
|
import Band from '../Band.astro'
|
|
16
16
|
import Prose from '../../Prose.astro'
|
|
17
17
|
import type Default from './index.astro'
|
|
18
|
+
import Lookup from './Lookup.astro'
|
|
18
19
|
import { voterTools } from './voter-tools'
|
|
19
20
|
import { prose } from '../../../lib/format'
|
|
20
21
|
|
|
@@ -22,9 +23,10 @@ type Props = ComponentProps<typeof Default>
|
|
|
22
23
|
|
|
23
24
|
const { section } = Astro.props
|
|
24
25
|
const vt = voterTools(section)
|
|
25
|
-
const
|
|
26
|
+
const lookup = !!section.embed
|
|
27
|
+
const place = !!(vt.kicker || vt.heading || prose(section.copy.body) || vt.polling || vt.earlyVoting || vt.idNote || lookup)
|
|
26
28
|
const day = !!(vt.electionDay || vt.register)
|
|
27
|
-
const shown = !!(vt.heading || vt.register || vt.polling || vt.dates.length > 0)
|
|
29
|
+
const shown = !!(vt.heading || vt.register || vt.polling || vt.dates.length > 0 || lookup)
|
|
28
30
|
---
|
|
29
31
|
{shown && (place || day) && (
|
|
30
32
|
<Band section={section} class="voter-tools vt-polling">
|
|
@@ -34,6 +36,7 @@ const shown = !!(vt.heading || vt.register || vt.polling || vt.dates.length > 0)
|
|
|
34
36
|
{vt.kicker && <p class="kicker">{vt.kicker}</p>}
|
|
35
37
|
{vt.heading && <h2>{vt.heading}</h2>}
|
|
36
38
|
<Prose value={section.copy.body} class="vt-body" />
|
|
39
|
+
{lookup && <Lookup section={section} />}
|
|
37
40
|
{vt.polling && (
|
|
38
41
|
<p class="actions vt-actions">
|
|
39
42
|
<a class="button" href={vt.polling.href} rel={vt.polling.rel}>{vt.polling.label}</a>
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// A VoterTools section as its layouts draw it: its words, its two links and
|
|
2
2
|
// its key dates. The links go to the official lookups the organization
|
|
3
|
-
// names (its state's registration check and polling-place finder)
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
3
|
+
// names (its state's registration check and polling-place finder). With the
|
|
4
|
+
// section's Polling place lookup on, the Content API also sends BackGold's
|
|
5
|
+
// own lookup as the section's embed, which each layout mounts (Lookup.astro)
|
|
6
|
+
// beside these. The Content API sends the links without their keys, so each
|
|
7
|
+
// is told apart by its label: the one labelled with `registerLabel` is the
|
|
7
8
|
// registration link, the one labelled with `pollingLabel` the polling link.
|
|
8
9
|
// A date row is drawn when it has a label; its `date` (YYYY-MM-DD, a
|
|
9
10
|
// calendar day) is kept only when it is one.
|
|
@@ -38,6 +38,7 @@ import ContentPost from './ContentPost/index.astro'
|
|
|
38
38
|
import ContentPostPlayer from './ContentPost/player.astro'
|
|
39
39
|
import ContentPostBanner from './ContentPost/banner.astro'
|
|
40
40
|
import ContentPostTheater from './ContentPost/theater.astro'
|
|
41
|
+
import ContentPostProse from './ContentPost/prose.astro'
|
|
41
42
|
import Countdown from './Countdown/index.astro'
|
|
42
43
|
import Course from './Course/index.astro'
|
|
43
44
|
import CourseOutline from './Course/outline.astro'
|
|
@@ -275,9 +276,11 @@ export const sections = {
|
|
|
275
276
|
'Collection:shelves': CollectionShelves,
|
|
276
277
|
'Collection:outline': CollectionOutline,
|
|
277
278
|
ContentPost,
|
|
279
|
+
'ContentPost:card': ContentPost,
|
|
278
280
|
'ContentPost:banner': ContentPostBanner,
|
|
279
281
|
'ContentPost:player': ContentPostPlayer,
|
|
280
282
|
'ContentPost:theater': ContentPostTheater,
|
|
283
|
+
'ContentPost:prose': ContentPostProse,
|
|
281
284
|
PlatformPlanks,
|
|
282
285
|
'PlatformPlanks:columns': PlatformPlanksColumns,
|
|
283
286
|
'PlatformPlanks:longread': PlatformPlanksLongread,
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
//
|
|
34
34
|
// A Donate frame also carries the page address's donate names (an ask
|
|
35
35
|
// amount, a donate place, `utm_*`, lib/donate-frame.ts) that its address from
|
|
36
|
-
// BackGold does not already name
|
|
36
|
+
// BackGold does not already name; a form frame carries the page's `pick`,
|
|
37
|
+
// the choice it opens on (lib/donate-frame.ts withPickQuery).
|
|
37
38
|
//
|
|
38
39
|
// A section BackGold sends with no embed has nothing to frame (no donation
|
|
39
40
|
// form for the organization, no petition picked, an event no longer public):
|
|
@@ -43,7 +44,7 @@
|
|
|
43
44
|
import type { SectionEmbed } from '@backgold/content'
|
|
44
45
|
import { Embed } from '@backgold/astro/components'
|
|
45
46
|
import { SECTION_BANDS, appearanceOf, moduleLook, type SectionBand } from '../../../lib/brand'
|
|
46
|
-
import { isDonateFrame, withDonateQuery } from '../../../lib/donate-frame'
|
|
47
|
+
import { isDonateFrame, isFormFrame, withDonateQuery, withPickQuery } from '../../../lib/donate-frame'
|
|
47
48
|
|
|
48
49
|
interface Props {
|
|
49
50
|
/** The section's (or the event page's) embed, as BackGold sends it. */
|
|
@@ -101,6 +102,7 @@ function framed(iframe: string | null): string | null {
|
|
|
101
102
|
return iframe
|
|
102
103
|
}
|
|
103
104
|
if (isDonateFrame(type)) withDonateQuery(url, Astro.url.searchParams)
|
|
105
|
+
if (isFormFrame(type)) withPickQuery(url, Astro.url.searchParams)
|
|
104
106
|
url.searchParams.set('layout', layout)
|
|
105
107
|
for (const [key, value] of Object.entries(moduleLook(brand, band, appearance, theme, Astro.locals.template?.frameColors ?? null))) url.searchParams.set(key, value)
|
|
106
108
|
url.searchParams.set('radius', String(radius))
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
// One collection at /collections/<slug> (board 06, "/collections/:slug"):
|
|
3
|
+
// its cover, "Collection · N items" over its title as the page's one <h1>,
|
|
4
|
+
// its intro, the grid in the collection's own order (a member that is not
|
|
5
|
+
// published is not in the answer, so it is simply absent), then a closing
|
|
6
|
+
// band with the collection's body and the page's one call, back to the
|
|
7
|
+
// whole store.
|
|
8
|
+
import type { CollectionDetail } from '@backgold/content'
|
|
9
|
+
import { renderMarkdown, safeSrc } from '@backgold/astro/server'
|
|
10
|
+
import ProductGrid from './ProductGrid.astro'
|
|
11
|
+
import { STORE_PATH } from '../../lib/store'
|
|
12
|
+
import '../../styles/store.css'
|
|
13
|
+
|
|
14
|
+
interface Props {
|
|
15
|
+
collection: CollectionDetail
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const { collection } = Astro.props
|
|
19
|
+
const cover = collection.cover ? safeSrc(collection.cover.url) : null
|
|
20
|
+
const count = collection.products.length
|
|
21
|
+
const body = collection.body.markdown.trim() ? renderMarkdown(collection.body.markdown) : ''
|
|
22
|
+
---
|
|
23
|
+
<div class="store-page collection-page">
|
|
24
|
+
<nav class="crumbs" aria-label="Breadcrumb">
|
|
25
|
+
<a href={STORE_PATH}>Store</a><span aria-hidden="true"> › </span><span>{collection.title}</span>
|
|
26
|
+
</nav>
|
|
27
|
+
{cover && <img class="collection-cover" src={cover} alt="" decoding="async" />}
|
|
28
|
+
<header class="store-head">
|
|
29
|
+
<p class="kicker">Collection · {count} {count === 1 ? 'item' : 'items'}</p>
|
|
30
|
+
<h1>{collection.title}</h1>
|
|
31
|
+
{collection.intro && <p class="lede">{collection.intro}</p>}
|
|
32
|
+
</header>
|
|
33
|
+
{count > 0 ? <ProductGrid products={collection.products} label={collection.title} /> : <p class="empty">Nothing in this collection yet.</p>}
|
|
34
|
+
<section class="store-band store-band-closing">
|
|
35
|
+
<div class="store-band-words">
|
|
36
|
+
{body && <div class="prose" set:html={body} />}
|
|
37
|
+
<p class="store-band-call"><a class="button" href={STORE_PATH}>See everything in the store</a></p>
|
|
38
|
+
</div>
|
|
39
|
+
</section>
|
|
40
|
+
</div>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
// One listing in a storefront grid (board 06): the whole card is the link to
|
|
3
|
+
// its page, with its first photo, its name, its price as built ("From $X"
|
|
4
|
+
// when its items differ) and its availability word; a listing that is few
|
|
5
|
+
// left or sold out says so on its photo. No button: the page's one call is
|
|
6
|
+
// elsewhere.
|
|
7
|
+
import type { ProductSummary } from '@backgold/content'
|
|
8
|
+
import { safeSrc } from '@backgold/astro/server'
|
|
9
|
+
import { AVAILABILITY_WORDS, priceLabel, productPath } from '../../lib/store'
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
product: ProductSummary
|
|
13
|
+
/** The card title's level: 2 under the page's h1, 3 under a section's h2. */
|
|
14
|
+
level?: 2 | 3
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const { product, level = 2 } = Astro.props
|
|
18
|
+
const Heading = level === 2 ? 'h2' : 'h3'
|
|
19
|
+
const photo = safeSrc(product.photos[0]?.url)
|
|
20
|
+
const flagged = product.availability === 'low' || product.availability === 'out'
|
|
21
|
+
---
|
|
22
|
+
<a class="product-card" href={productPath(product.slug)} data-availability={product.availability}>
|
|
23
|
+
<span class="product-card-photo">
|
|
24
|
+
{photo ? <img src={photo} alt="" loading="lazy" decoding="async" /> : <span class="product-card-blank" aria-hidden="true"></span>}
|
|
25
|
+
{flagged && <span class="product-card-flag">{AVAILABILITY_WORDS[product.availability]}</span>}
|
|
26
|
+
</span>
|
|
27
|
+
<span class="product-card-body">
|
|
28
|
+
<Heading class="product-card-name">{product.name}</Heading>
|
|
29
|
+
<span class="product-card-price">{priceLabel(product)}</span>
|
|
30
|
+
{!flagged && <span class="product-card-word">{AVAILABILITY_WORDS[product.availability]}</span>}
|
|
31
|
+
</span>
|
|
32
|
+
</a>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
// A grid of listing cards (ProductCard), as a list.
|
|
3
|
+
import type { ProductSummary } from '@backgold/content'
|
|
4
|
+
import ProductCard from './ProductCard.astro'
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
products: ProductSummary[]
|
|
8
|
+
level?: 2 | 3
|
|
9
|
+
label?: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const { products, level = 2, label } = Astro.props
|
|
13
|
+
---
|
|
14
|
+
<ul class="product-grid" role="list" aria-label={label}>
|
|
15
|
+
{products.map((product) => <li><ProductCard product={product} level={level} /></li>)}
|
|
16
|
+
</ul>
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
---
|
|
2
|
+
// One listing's page at /store/<slug> (board 06, "Product page"): the path
|
|
3
|
+
// back through the store and the listing's department (a department whose
|
|
4
|
+
// storefront page is off, `category_page: false`, named without a link, as
|
|
5
|
+
// is the listing's own department at the end), the gallery, the
|
|
6
|
+
// manufacturer over the title (the page's one <h1>) and its short line, the
|
|
7
|
+
// island, the long copy,
|
|
8
|
+
// the details table from the department's attribute definitions in their
|
|
9
|
+
// order (a value left blank leaves its row out), and the related listings
|
|
10
|
+
// under the collection each shares with this one.
|
|
11
|
+
//
|
|
12
|
+
// The island as built reads with scripts off: the build's price (struck
|
|
13
|
+
// against a compare-at price above it), when the build read it, the
|
|
14
|
+
// availability word, where the order goes (one line: a pickup, a licensed
|
|
15
|
+
// dealer, or shipped to the buyer), the items by name, for a listing that
|
|
16
|
+
// counts as a political contribution the sentence that says so, right
|
|
17
|
+
// above Add to cart, and Add to cart as a link to the
|
|
18
|
+
// listing's page on BackGold, where the cart works without this site's
|
|
19
|
+
// script. With scripts on, StoreScript reads GET /products/live on view and
|
|
20
|
+
// redraws it as one of five states (in stock, few left, sold out, the price
|
|
21
|
+
// moved since the build, the read failed), with the item choice, a quantity,
|
|
22
|
+
// the questions the line asks (each per-unit question once per unit) and
|
|
23
|
+
// Add to cart as the page's one call.
|
|
24
|
+
import type { ProductDetail } from '@backgold/content'
|
|
25
|
+
import { safeHref, safeSrc, sanitizeRichText } from '@backgold/astro/server'
|
|
26
|
+
import ProductGrid from './ProductGrid.astro'
|
|
27
|
+
import { formatDay } from '../../lib/format'
|
|
28
|
+
import { AVAILABILITY_CHIPS, AVAILABILITY_WORDS, STORE_PATH, attributeText, contributionLine, departmentPath, firstBuyable, islandProduct, money, relatedGroups, shipLine } from '../../lib/store'
|
|
29
|
+
import '../../styles/store.css'
|
|
30
|
+
|
|
31
|
+
interface Props {
|
|
32
|
+
product: ProductDetail
|
|
33
|
+
/** The site's name, for the contribution sentence. */
|
|
34
|
+
siteName: string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const { product, siteName } = Astro.props
|
|
38
|
+
const ship = shipLine(product)
|
|
39
|
+
const photos = product.photos.map((p) => safeSrc(p.url)).filter((u): u is string => u !== null)
|
|
40
|
+
const [cover, ...more] = photos
|
|
41
|
+
const item = firstBuyable(product.items)
|
|
42
|
+
const built = formatDay(product.updated_at)
|
|
43
|
+
const description = product.description_html.trim() ? sanitizeRichText(product.description_html) : ''
|
|
44
|
+
const details = product.attributes.map((a) => ({ label: a.label, kind: a.kind, text: attributeText(a.value) })).filter((a) => a.text !== null)
|
|
45
|
+
const groups = relatedGroups(product)
|
|
46
|
+
const struck = item && item.compare_at_cents !== null && item.compare_at_cents > item.price_cents ? item.compare_at_cents : null
|
|
47
|
+
const buyHref = safeHref(product.buy_url)
|
|
48
|
+
---
|
|
49
|
+
<div class="store-page product-page">
|
|
50
|
+
<nav class="crumbs" aria-label="Breadcrumb">
|
|
51
|
+
<a href={STORE_PATH}>Store</a>
|
|
52
|
+
{product.department.map((d, i) => (
|
|
53
|
+
<>
|
|
54
|
+
<span aria-hidden="true"> › </span>
|
|
55
|
+
{i === product.department.length - 1 || d.category_page === false ? <span>{d.label}</span> : <a href={departmentPath(d.slug)}>{d.label}</a>}
|
|
56
|
+
</>
|
|
57
|
+
))}
|
|
58
|
+
</nav>
|
|
59
|
+
|
|
60
|
+
<div class="product-top">
|
|
61
|
+
<div class="product-gallery" data-bg-gallery>
|
|
62
|
+
{cover ? <img class="product-photo" src={cover} alt={product.name} data-bg-gallery-main /> : <span class="product-photo product-card-blank" aria-hidden="true"></span>}
|
|
63
|
+
{more.length > 0 && (
|
|
64
|
+
<ul class="product-thumbs" role="list" aria-label="More photos">
|
|
65
|
+
{[cover!, ...more].map((src, i) => (
|
|
66
|
+
<li><a href={src} data-bg-gallery-thumb aria-current={i === 0 ? 'true' : undefined}><img src={src} alt={`Photo ${i + 1} of ${photos.length}`} loading="lazy" decoding="async" /></a></li>
|
|
67
|
+
))}
|
|
68
|
+
</ul>
|
|
69
|
+
)}
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
<div class="product-words">
|
|
73
|
+
{product.manufacturer && <p class="kicker product-maker">{product.manufacturer.name}</p>}
|
|
74
|
+
<h1>{product.name}</h1>
|
|
75
|
+
{product.short_description && <p class="lede">{product.short_description}</p>}
|
|
76
|
+
|
|
77
|
+
<section class="island" data-bg-island aria-label="Price and availability">
|
|
78
|
+
<p class="island-price">
|
|
79
|
+
<span class="island-now" data-bg-price>{item ? money(item.price_cents) : ''}</span>
|
|
80
|
+
<s class="island-was" data-bg-was hidden={struck === null}>{struck !== null ? money(struck) : ''}</s>
|
|
81
|
+
</p>
|
|
82
|
+
<p class="island-line" data-bg-line>{built ? `As of the last build, ${built}.` : 'As of the last build.'}</p>
|
|
83
|
+
{item && <p class="island-word"><span class:list={['chip', AVAILABILITY_CHIPS[item.availability]]} data-bg-word>{AVAILABILITY_WORDS[item.availability]}</span></p>}
|
|
84
|
+
{ship && <p class="island-ship">{ship}</p>}
|
|
85
|
+
{product.items.length > 1 && (
|
|
86
|
+
<fieldset class="island-items">
|
|
87
|
+
<legend>Choose one</legend>
|
|
88
|
+
{product.items.map((option) => (
|
|
89
|
+
<label class="island-item">
|
|
90
|
+
<input type="radio" name="item" value={option.id} checked={option.id === item?.id} disabled data-bg-item />
|
|
91
|
+
<span>{option.name}</span>
|
|
92
|
+
</label>
|
|
93
|
+
))}
|
|
94
|
+
</fieldset>
|
|
95
|
+
)}
|
|
96
|
+
{product.counts_as_contribution && <p class="island-contribution" data-bg-contribution>{contributionLine(siteName)}</p>}
|
|
97
|
+
{buyHref && <a class="button island-fallback" href={buyHref} data-bg-fallback>Add to cart</a>}
|
|
98
|
+
<form class="island-form" data-bg-form hidden novalidate>
|
|
99
|
+
<div class="island-qty-row">
|
|
100
|
+
<div class="island-qty" role="group" aria-label="Quantity">
|
|
101
|
+
<button type="button" class="island-step" data-bg-step="-1" aria-label="One fewer">−</button>
|
|
102
|
+
<input type="number" name="quantity" value="1" min="1" max="99" inputmode="numeric" aria-label="Quantity" data-bg-qty />
|
|
103
|
+
<button type="button" class="island-step" data-bg-step="1" aria-label="One more">+</button>
|
|
104
|
+
</div>
|
|
105
|
+
<span class="island-note" data-bg-unit-note hidden>One answer per unit</span>
|
|
106
|
+
</div>
|
|
107
|
+
<div class="island-questions" data-bg-questions></div>
|
|
108
|
+
<button type="submit" class="button island-add" data-bg-add disabled>Checking the price…</button>
|
|
109
|
+
<button type="button" class="button button-quiet island-retry" data-bg-retry hidden>Try again</button>
|
|
110
|
+
<p class="island-status" data-bg-status role="status" aria-live="polite"></p>
|
|
111
|
+
</form>
|
|
112
|
+
</section>
|
|
113
|
+
<script is:inline type="application/json" data-bg-island-product set:html={JSON.stringify(islandProduct(product)).replace(/</g, '\\u003c')} />
|
|
114
|
+
</div>
|
|
115
|
+
</div>
|
|
116
|
+
|
|
117
|
+
{(description || details.length > 0) && (
|
|
118
|
+
<div class="product-more">
|
|
119
|
+
{description && (
|
|
120
|
+
<section class="product-about">
|
|
121
|
+
<h2>About this item</h2>
|
|
122
|
+
<div class="prose" set:html={description} />
|
|
123
|
+
</section>
|
|
124
|
+
)}
|
|
125
|
+
{details.length > 0 && (
|
|
126
|
+
<section class="product-details">
|
|
127
|
+
<h2>Details</h2>
|
|
128
|
+
<table class="product-attributes">
|
|
129
|
+
<tbody>
|
|
130
|
+
{details.map((d) => (
|
|
131
|
+
<tr><th scope="row">{d.label}</th><td>{d.kind === 'date' ? (formatDay(d.text) ?? d.text) : d.text}</td></tr>
|
|
132
|
+
))}
|
|
133
|
+
</tbody>
|
|
134
|
+
</table>
|
|
135
|
+
</section>
|
|
136
|
+
)}
|
|
137
|
+
</div>
|
|
138
|
+
)}
|
|
139
|
+
|
|
140
|
+
{groups.map((group) => (
|
|
141
|
+
<section class="product-related">
|
|
142
|
+
<h2>{group.href ? <>From <a href={group.href}>{group.title}</a></> : group.title}</h2>
|
|
143
|
+
<ProductGrid products={group.products} level={3} />
|
|
144
|
+
</section>
|
|
145
|
+
))}
|
|
146
|
+
</div>
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
---
|
|
2
|
+
// The shop at /store, and a department's at /store/departments/<slug>
|
|
3
|
+
// (board 06, "/store"): its opening, then the departments rail beside the
|
|
4
|
+
// grid (above it on a phone) and, on the shop's first page, a collection
|
|
5
|
+
// band with the page's one call.
|
|
6
|
+
//
|
|
7
|
+
// The opening is the published page at /store when there is one (its
|
|
8
|
+
// sections, a Store section among them left out: the grid below is the
|
|
9
|
+
// store), else the site's name over "Store" as the page's one <h1>; a
|
|
10
|
+
// department's page is headed by the department. Under the opening, when a
|
|
11
|
+
// listing on the page counts as a political contribution, one sentence says
|
|
12
|
+
// so (DS §18.1); never on a page where none does. The rail lists every
|
|
13
|
+
// top-level department with something published in it, counted with what
|
|
14
|
+
// is under it, "All" first with the shop's count; on a department's page
|
|
15
|
+
// the departments under it follow it. The site's collections are listed
|
|
16
|
+
// under the departments. On a department's page the filter panel follows:
|
|
17
|
+
// a group per facet the api sends, headed like the rail's lists, each value
|
|
18
|
+
// a link that toggles it in the page's `?attr=` filters (its count beside
|
|
19
|
+
// it, a chosen one current), with "Clear filters" above the groups once one
|
|
20
|
+
// is chosen. Links only, so it reads with scripts off; a filtered page with
|
|
21
|
+
// nothing in it says so and offers Clear filters. The grid is a page of up
|
|
22
|
+
// to STORE_PAGE_SIZE listings, newest first; "More" asks for the next page
|
|
23
|
+
// (`?cursor=`) and "Back to the first page" returns, both under the filters. The band is the site's first collection
|
|
24
|
+
// with something in it: its cover, its title and intro, and "Shop <title>".
|
|
25
|
+
import type { PageResponse, ProductDepartment, ProductsResponse } from '@backgold/content'
|
|
26
|
+
import { safeSrc } from '@backgold/astro/server'
|
|
27
|
+
import PageSections from '../PageSections.astro'
|
|
28
|
+
import ProductGrid from './ProductGrid.astro'
|
|
29
|
+
import { STORE_PATH, collectionPath, contributionLine, departmentRail, departmentPath, facetGroups, shopCount, type StoreFilters } from '../../lib/store'
|
|
30
|
+
import '../../styles/store.css'
|
|
31
|
+
import type { TemplateConfig } from '../../template'
|
|
32
|
+
|
|
33
|
+
interface Props {
|
|
34
|
+
template: TemplateConfig
|
|
35
|
+
siteName: string
|
|
36
|
+
/** The page of listings, with the whole department tree and the site's collections (the api sends both on every page). */
|
|
37
|
+
shop: ProductsResponse
|
|
38
|
+
department: ProductDepartment | null
|
|
39
|
+
intro: PageResponse | null
|
|
40
|
+
/** The address of the next page, and of the first, when this is not it. */
|
|
41
|
+
pager: { more: string | null; first: string | null }
|
|
42
|
+
/** The `?attr=` filters the page is under (none on the shop's root). */
|
|
43
|
+
filters: StoreFilters
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const { template, siteName, shop, department, intro, pager, filters } = Astro.props
|
|
47
|
+
const rail = departmentRail(shop.departments, department?.slug ?? null)
|
|
48
|
+
const collections = shop.collections.filter((c) => c.count > 0)
|
|
49
|
+
const band = department === null && pager.first === null ? (collections[0] ?? null) : null
|
|
50
|
+
const bandCover = band?.cover ? safeSrc(band.cover.url) : null
|
|
51
|
+
const opening = intro && department === null ? { ...intro, sections: intro.sections.filter((s) => s.type !== 'Store') } : null
|
|
52
|
+
const drawsOpening = opening !== null && opening.sections.length > 0
|
|
53
|
+
const here = department ? departmentPath(department.slug) : STORE_PATH
|
|
54
|
+
const contributes = shop.products.some((p) => p.counts_as_contribution)
|
|
55
|
+
const groups = department ? facetGroups(shop.facets ?? [], filters, here) : []
|
|
56
|
+
const filtered = department !== null && filters.length > 0
|
|
57
|
+
---
|
|
58
|
+
<div class="store-page store-home">
|
|
59
|
+
{drawsOpening ? (
|
|
60
|
+
<PageSections template={template} page={opening!} siteName={siteName} />
|
|
61
|
+
) : (
|
|
62
|
+
<header class="store-head">
|
|
63
|
+
<p class="kicker">{department ? 'Store' : siteName}</p>
|
|
64
|
+
<h1>{department ? department.label : 'Store'}</h1>
|
|
65
|
+
</header>
|
|
66
|
+
)}
|
|
67
|
+
|
|
68
|
+
{contributes && <p class="store-contribution">{contributionLine(siteName)}</p>}
|
|
69
|
+
|
|
70
|
+
<div class="store-cols">
|
|
71
|
+
<nav class="store-rail" aria-label="Store">
|
|
72
|
+
{rail.length > 0 && (
|
|
73
|
+
<>
|
|
74
|
+
<p class="store-rail-head">Departments</p>
|
|
75
|
+
<ul role="list">
|
|
76
|
+
<li><a href={STORE_PATH} aria-current={department === null ? 'page' : undefined}>All <span>{shopCount(shop)}</span></a></li>
|
|
77
|
+
{rail.map((link) => (
|
|
78
|
+
<li class:list={[link.depth === 1 && 'store-rail-sub']}>
|
|
79
|
+
<a href={link.href} aria-current={link.href === here ? 'page' : link.current ? 'true' : undefined}>{link.label} <span>{link.count}</span></a>
|
|
80
|
+
</li>
|
|
81
|
+
))}
|
|
82
|
+
</ul>
|
|
83
|
+
</>
|
|
84
|
+
)}
|
|
85
|
+
{collections.length > 0 && (
|
|
86
|
+
<>
|
|
87
|
+
<p class="store-rail-head">Collections</p>
|
|
88
|
+
<ul role="list">
|
|
89
|
+
{collections.map((c) => <li><a href={collectionPath(c.slug)}>{c.title} <span>{c.count}</span></a></li>)}
|
|
90
|
+
</ul>
|
|
91
|
+
</>
|
|
92
|
+
)}
|
|
93
|
+
{(groups.length > 0 || filtered) && (
|
|
94
|
+
<div class="store-filters">
|
|
95
|
+
{filtered && <p class="store-filters-clear"><a class="text-link" href={here}>Clear filters</a></p>}
|
|
96
|
+
{groups.map((group) => (
|
|
97
|
+
<>
|
|
98
|
+
<p class="store-rail-head" id={`store-filter-${group.key}`}>{group.label}</p>
|
|
99
|
+
<ul role="list" aria-labelledby={`store-filter-${group.key}`}>
|
|
100
|
+
{group.links.map((link) => (
|
|
101
|
+
<li><a href={link.href} rel="nofollow" aria-current={link.chosen ? 'true' : undefined}>{link.label} <span>{link.count}</span></a></li>
|
|
102
|
+
))}
|
|
103
|
+
</ul>
|
|
104
|
+
</>
|
|
105
|
+
))}
|
|
106
|
+
</div>
|
|
107
|
+
)}
|
|
108
|
+
</nav>
|
|
109
|
+
|
|
110
|
+
<div class="store-main">
|
|
111
|
+
{shop.products.length > 0 ? (
|
|
112
|
+
<ProductGrid products={shop.products} label={department ? department.label : 'Everything in the store'} />
|
|
113
|
+
) : filtered ? (
|
|
114
|
+
<p class="empty">Nothing in {department!.label} matches the filters. <a class="text-link store-empty-clear" href={here}>Clear filters</a></p>
|
|
115
|
+
) : (
|
|
116
|
+
<p class="empty">Nothing here yet.</p>
|
|
117
|
+
)}
|
|
118
|
+
{(pager.more || pager.first) && (
|
|
119
|
+
<nav class="store-pager" aria-label="More of the store">
|
|
120
|
+
{pager.first && <a class="text-link" href={pager.first}>Back to the first page</a>}
|
|
121
|
+
{pager.more && <a class="text-link" href={pager.more}>More</a>}
|
|
122
|
+
</nav>
|
|
123
|
+
)}
|
|
124
|
+
{band && (
|
|
125
|
+
<section class="store-band">
|
|
126
|
+
{bandCover && <img class="store-band-cover" src={bandCover} alt="" loading="lazy" decoding="async" />}
|
|
127
|
+
<div class="store-band-words">
|
|
128
|
+
<p class="kicker">Collection</p>
|
|
129
|
+
<h2>{band.title}</h2>
|
|
130
|
+
{band.intro && <p>{band.intro}</p>}
|
|
131
|
+
<p class="store-band-call"><a class="button" href={collectionPath(band.slug)}>Shop {band.title}</a></p>
|
|
132
|
+
</div>
|
|
133
|
+
</section>
|
|
134
|
+
)}
|
|
135
|
+
</div>
|
|
136
|
+
</div>
|
|
137
|
+
</div>
|