Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions backend/src/piece-page.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// styles and scripts of every page): the piece replaces [[piece]] in <main>, its title replaces the
// shell's, and its head tags go before </head>. Without a shell it is a plain page that search
// engines are asked not to list, so a passing failure is never what they keep.
import { labelDollars } from "./shipping.mjs";

const SITE_NAME = "Updraft Pottery Studio";
const esc = (s = "") => String(s).replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[c]);
Expand Down Expand Up @@ -78,12 +79,49 @@ function picture(url, { alt, sizes, widths, eager }) {
);
}

/** OfferShippingDetails for one parcel of billed weight shipLb (WA state + US ceiling), or null when unpriced. */
function shippingDetailsFor(shipLb) {
if (!(shipLb > 0)) return null;
const maxForZone = (zone) => {
const ups = labelDollars("ups", zone, shipLb);
if (ups === null) return null;
return Math.ceil(Math.max(ups, labelDollars("usps", zone, shipLb) ?? 0));
};
const wa = maxForZone(3);
const us = maxForZone(8);
if (wa === null || us === null) return null;
const handlingTime = { "@type": "QuantitativeValue", minValue: 1, maxValue: 2, unitCode: "DAY" };
return [
{
"@type": "OfferShippingDetails",
shippingRate: { "@type": "MonetaryAmount", value: wa.toFixed(2), currency: "USD" },
shippingDestination: { "@type": "DefinedRegion", addressCountry: "US", addressRegion: "WA" },
deliveryTime: {
"@type": "ShippingDeliveryTime",
handlingTime,
transitTime: { "@type": "QuantitativeValue", minValue: 1, maxValue: 3, unitCode: "DAY" },
},
},
{
"@type": "OfferShippingDetails",
shippingRate: { "@type": "MonetaryAmount", value: us.toFixed(2), currency: "USD" },
shippingDestination: { "@type": "DefinedRegion", addressCountry: "US" },
deliveryTime: {
"@type": "ShippingDeliveryTime",
handlingTime,
transitTime: { "@type": "QuantitativeValue", minValue: 1, maxValue: 6, unitCode: "DAY" },
},
},
];
}

/** schema.org data: the Product with an Offer per option, and where it sits in the shop. */
export function structuredData(item, site) {
const url = `${site}/p/${item.id}`;
const many = item.variations.length > 1;
const delivery =
item.shipLb > 0 ? ["https://schema.org/OnSitePickup", "https://schema.org/ParcelService"] : ["https://schema.org/OnSitePickup"];
const shippingDetails = shippingDetailsFor(item.shipLb);
const crumbs = [
{ name: "Home", item: `${site}/` },
{ name: "Shop", item: `${site}/shop.html` },
Expand Down Expand Up @@ -123,6 +161,7 @@ export function structuredData(item, site) {
applicableCountry: "US",
returnPolicyCategory: "https://schema.org/MerchantReturnNotPermitted",
},
...(shippingDetails ? { shippingDetails } : {}),
})),
},
{
Expand Down
13 changes: 13 additions & 0 deletions backend/test/shop-pages.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,19 @@ test("a piece's page has its name, price, photos, words and product data, and no
assert.equal(product.offers[0].price, "65.00");
assert.equal(product.offers[0].availability, "https://schema.org/InStock");
assert.deepEqual(product.offers[0].availableDeliveryMethod, ["https://schema.org/OnSitePickup", "https://schema.org/ParcelService"]);
assert.deepEqual(
product.offers[0].shippingDetails.map((s) => [s.shippingDestination.addressRegion ?? "US", s.shippingRate.value]),
[
["WA", "33.00"],
["US", "52.00"],
],
);
assert.equal(
structuredData({ id: "P", name: "Pot", variations: [{ id: "V", name: "R", price: 1000, stock: 1 }] }, "")["@graph"][0].offers[0]
.shippingDetails,
undefined,
"pickup-only or unweighted items omit parcel shippingDetails",
);
assert.equal(product.image.length, 2);
assert.deepEqual(
crumbs.itemListElement.map((c) => c.name),
Expand Down
14 changes: 12 additions & 2 deletions e2e/home.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,18 @@ test("the page runs in the planned order, with the full story on the About page"
els.map((e) => e.id || e.className.split(" ").find((c) => ["hero", "studio", "signup", "trust"].includes(c)) || e.tagName),
);
expect(order).toEqual(["hero", "available", "about", "work", "signup", "trust"]);
await expect(page.locator(".studio").getByRole("link", { name: "Read the full story →" })).toHaveAttribute("href", "/about.html");
await expect(page.locator(".studio").getByRole("link", { name: "See the kilns →" })).toHaveAttribute("href", "/kilns.html");
await expect(page.locator(".studio").getByRole("link", { name: "More about Aaron and the studio →" })).toHaveAttribute(
"href",
"/about.html",
);
await expect(page.locator(".studio").getByRole("link", { name: "See the soda and propane kilns →" })).toHaveAttribute(
"href",
"/kilns.html",
);
await expect(page.locator("#work").getByRole("link", { name: "See earlier pottery in the archive →" })).toHaveAttribute(
"href",
"/past-work.html",
);
await expect(page.locator(".trust")).toContainText("Orders ship in 1–2 business days.");
await page.goto("/about.html");
await expect(page.locator("h1")).toHaveText("About the studio");
Expand Down
1 change: 1 addition & 0 deletions e2e/piece-page.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ test("a piece's page has its name, price, product data and its own address", asy
"65.00",
14,
]);
expect(product.offers[0].shippingDetails.map((s) => s.shippingRate.value)).toEqual(["33.00", "52.00"]);
await expect(page.locator(".crumbs li")).toHaveText(["Home", "Shop", "Bowls", "Celadon footed bowl"]);
expect(crumbs.itemListElement.map((c) => c.name)).toEqual(["Home", "Shop", "Bowls", "Celadon footed bowl"]);
// Other pieces still for sale, each by its own page; the sold jar isn't among them.
Expand Down
1 change: 1 addition & 0 deletions e2e/seo.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ for (const [path, type, crumbs] of expectedTypes) {
expect(schema["@graph"][0]["@type"]).toBe(type);
if (!crumbs) {
await expect(page.locator("nav.crumbs")).toHaveCount(0);
expect(schema["@graph"][0].areaServed.map((a) => a.name)).toContain("Tacoma");
} else {
await expect(page.locator("nav.crumbs li")).toHaveText(crumbs);
await expect(page.locator("nav.crumbs [aria-current='page']")).toHaveText(crumbs.at(-1));
Expand Down
7 changes: 6 additions & 1 deletion scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,12 @@ function pageSchema(name, html, { ogs, icon512, email, meta, archive, terms }) {
...(email ? { email } : {}),
founder: { "@type": "Person", "@id": personId, name: "Aaron Filson", url: pageUrl("about.html") },
address: { "@type": "PostalAddress", addressLocality: "Tacoma", addressRegion: "WA", addressCountry: "US" },
areaServed: { "@type": "Country", name: "US" },
areaServed: [
{ "@type": "City", name: "Tacoma", containedInPlace: { "@type": "State", name: "Washington" } },
{ "@type": "AdministrativeArea", name: "Pierce County, WA" },
{ "@type": "Place", name: "Seattle-Tacoma metropolitan area" },
{ "@type": "Country", name: "US" },
],
sameAs: SAME_AS,
hasMerchantReturnPolicy: {
"@type": "MerchantReturnPolicy",
Expand Down
4 changes: 2 additions & 2 deletions site/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ section { padding-block: clamp(2.5rem, 7vw, 5rem); }
.chip { font: inherit; font-size: .95rem; min-height: 44px; padding: .4rem 1rem; border-radius: 99px; border: 1.5px solid var(--control); background: var(--surface); color: var(--ink); cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.card-body { padding: 1rem 1.1rem 1.2rem; display: flex; flex-direction: column; gap: .5rem; flex: 1; }
.card-body h3 { font-size: 1.25rem; margin: 0 0 .3em; }
.card-body :is(h3, .ph-title) { font-size: 1.25rem; line-height: 1.15; margin: 0 0 .3em; }
.card-body p { margin: 0; color: var(--muted); font-size: .95rem; }
.price { font-weight: 600; }
.product-strip { grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); }
Expand All @@ -135,7 +135,7 @@ section { padding-block: clamp(2.5rem, 7vw, 5rem); }
@media (max-width: 599px) {
:is(.products, .product-strip) { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
:is(.products, .product-strip) .card-body { padding: .7rem .75rem .85rem; }
:is(.products, .product-strip) .card-body h3 { font-size: 1.05rem; }
:is(.products, .product-strip) .card-body :is(h3, .ph-title) { font-size: 1.05rem; }
.products .row { flex-direction: column; align-items: stretch; gap: .4rem; }
.products .row .btn { padding-inline: .5rem; }
}
Expand Down
14 changes: 7 additions & 7 deletions site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ <h1>Pottery shaped by hand,<br> fired in Tacoma.</h1>
<div class="wrap">
<h2 id="available-title">Available now</h2>
<div class="grid product-strip" id="available-list">
<div class="card" aria-hidden="true"><div class="ph"></div><div class="card-body"><h3>&nbsp;</h3><span class="price">&nbsp;</span></div></div>
<div class="card" aria-hidden="true"><div class="ph"></div><div class="card-body"><h3>&nbsp;</h3><span class="price">&nbsp;</span></div></div>
<div class="card" aria-hidden="true"><div class="ph"></div><div class="card-body"><h3>&nbsp;</h3><span class="price">&nbsp;</span></div></div>
<div class="card" aria-hidden="true"><div class="ph"></div><div class="card-body"><h3>&nbsp;</h3><span class="price">&nbsp;</span></div></div>
<div class="card" aria-hidden="true"><div class="ph"></div><div class="card-body"><span class="ph-title">&nbsp;</span><span class="price">&nbsp;</span></div></div>
<div class="card" aria-hidden="true"><div class="ph"></div><div class="card-body"><span class="ph-title">&nbsp;</span><span class="price">&nbsp;</span></div></div>
<div class="card" aria-hidden="true"><div class="ph"></div><div class="card-body"><span class="ph-title">&nbsp;</span><span class="price">&nbsp;</span></div></div>
<div class="card" aria-hidden="true"><div class="ph"></div><div class="card-body"><span class="ph-title">&nbsp;</span><span class="price">&nbsp;</span></div></div>
</div>
<p class="more"><a href="/shop.html">Shop all pieces →</a></p>
</div>
Expand All @@ -49,7 +49,7 @@ <h2>Meet the potter</h2>
I'm Aaron Filson. I discovered pottery in my last semester at the University of Puget Sound, drawn in by the
wheel and the tangible results. Updraft Pottery Studio is my studio in Tacoma.
</p>
<p><a href="/about.html">Read the full story →</a></p>
<p><a href="/about.html">More about Aaron and the studio →</a></p>
</div>
</div>
<div class="studio-card">
Expand All @@ -62,7 +62,7 @@ <h2>Kiln projects</h2>
and my evolving propane kiln at my
studio in Tacoma.
</p>
<p><a href="/kilns.html">See the kilns →</a></p>
<p><a href="/kilns.html">See the soda and propane kilns →</a></p>
</div>
</div>
</div>
Expand All @@ -72,7 +72,7 @@ <h2>Kiln projects</h2>
<div class="wrap">
<h2>Recent work</h2>
<!--work-->
<p class="more"><a href="/past-work.html">See earlier work →</a></p>
<p class="more"><a href="/past-work.html">See earlier pottery in the archive →</a></p>
</div>
</section>

Expand Down
9 changes: 9 additions & 0 deletions site/js/test/seo.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ test("every indexable page has one h1, a title <= 60 chars, and a 70-160 char de
const desc = (html.match(/<meta name="description" content="([^"]*)"/)?.[1] ?? "").replaceAll("&amp;", "&");
const h1s = html.match(/<h1\b/g) ?? [];
assert.equal(h1s.length, 1, `${name}: expected one <h1>`);
for (const [tag, , inner] of html.matchAll(/<h([1-6])(?:\s[^>]*)?>([\s\S]*?)<\/h\1>/g)) {
const text = inner
.split("<")
.map((part, i) => (i === 0 ? part : part.slice(part.indexOf(">") + 1)))
.join("")
.replaceAll("&nbsp;", "")
.trim();
assert.ok(text.length > 0, `${name}: empty heading ${tag}`);
}
assert.ok(title.length >= 20 && title.length <= 60, `${name}: title length ${title.length} ("${title}")`);
assert.ok(desc.length >= 70 && desc.length <= 160, `${name}: description length ${desc.length}`);
if (name !== "index.html") assert.ok(html.includes("<!--crumbs-->"), `${name}: missing <!--crumbs--> placeholder`);
Expand Down
4 changes: 4 additions & 0 deletions site/partials/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<p>Updraft Pottery Studio · Tacoma, WA{{contactLine}}</p>
<ul class="footer-links">
<li><a href="/shop.html">Shop</a></li>
<li><a href="/past-work.html">Past work</a></li>
<li><a href="/about.html">About</a></li>
<li><a href="/kilns.html">Kilns</a></li>
<li><a href="/terms.html">Ceramic terms</a></li>
<li><a href="/care.html">Care &amp; use</a></li>
{{policiesItem}}
<li><a href="https://www.instagram.com/aaronmakespottery/">Instagram</a></li>
Expand Down
8 changes: 4 additions & 4 deletions site/shop.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ <h2 class="vh">Pieces for sale</h2><!-- keeps headings in order: h1 Shop > h2 >
cart below doesn't jump on phones (it did: layout shift 0.3). -->
<div id="products" class="grid products" aria-busy="true">
<p class="vh">Loading pieces…</p>
<div class="card ph-card" aria-hidden="true"><div class="ph"></div><div class="card-body"><h3>&nbsp;</h3><span class="price">&nbsp;</span></div></div>
<div class="card ph-card" aria-hidden="true"><div class="ph"></div><div class="card-body"><h3>&nbsp;</h3><span class="price">&nbsp;</span></div></div>
<div class="card ph-card" aria-hidden="true"><div class="ph"></div><div class="card-body"><h3>&nbsp;</h3><span class="price">&nbsp;</span></div></div>
<div class="card ph-card" aria-hidden="true"><div class="ph"></div><div class="card-body"><h3>&nbsp;</h3><span class="price">&nbsp;</span></div></div>
<div class="card ph-card" aria-hidden="true"><div class="ph"></div><div class="card-body"><span class="ph-title">&nbsp;</span><span class="price">&nbsp;</span></div></div>
<div class="card ph-card" aria-hidden="true"><div class="ph"></div><div class="card-body"><span class="ph-title">&nbsp;</span><span class="price">&nbsp;</span></div></div>
<div class="card ph-card" aria-hidden="true"><div class="ph"></div><div class="card-body"><span class="ph-title">&nbsp;</span><span class="price">&nbsp;</span></div></div>
<div class="card ph-card" aria-hidden="true"><div class="ph"></div><div class="card-body"><span class="ph-title">&nbsp;</span><span class="price">&nbsp;</span></div></div>
<noscript><p class="empty">The shop needs JavaScript turned on. You can still browse <a href="/#work">recent work</a> and <a href="/past-work.html">past work</a>.</p></noscript>
</div>
</div>
Expand Down
Loading