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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ The build:

Products come straight from your Square catalog. Add items in Square Dashboard > Items & services, with a price and a photo. They appear on the shop within a minute. Shop prices and tax are always calculated by Square on the server.

**Naming & descriptions for search:** Square item names become `/p/<id>` `<h1>` headings and `<title>` tags, and the first line of the Square description becomes the spec line and search snippet. Favor specific, plain-language names (e.g. `"Celadon porcelain mug, 12 oz"` or `"Soda-fired stoneware vase"`) and put clay body, glaze, and dimensions on line 1 (`"Cone 10 stoneware · Tacoma crackle 26 · 9½″ × 3¾″"`). Batch files for `scripts/load-items.mjs` accept optional `clay`, `glaze`, and `description` fields at both the batch and item level.

**Shipping** is priced per piece, from the delivery ZIP: one double-boxed parcel per piece, at the published label price for its billed weight and zone from Tacoma, rounded up to whole dollars (`backend/src/shipping.mjs`). UPS Ground carries everything it can; USPS Ground Advantage takes PO boxes, military addresses, Alaska, Hawaii and the territories. Each item needs a **Ship weight (lb)** custom attribute in Square: the billed weight of the packed box (the larger of actual and dimensional weight, from the pack-and-ship planner). An item without one can be picked up but not shipped. Rates and zones live in `backend/src/shipping-rates.json`; update it when UPS or USPS change prices (USPS holiday prices end 2027-01-17; the UPS fuel surcharge changes weekly).

## Email signup
Expand Down
50 changes: 27 additions & 23 deletions backend/src/catalog.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,33 @@ export async function loadCatalog() {
const items = objects
.filter((o) => o.type === "ITEM" && !o.isDeleted && o.itemData?.productType !== "APPOINTMENTS_SERVICE")
.filter((o) => !o.itemData.isArchived)
.map((o) => ({
id: o.id,
name: o.itemData.name,
description: o.itemData.descriptionPlaintext ?? o.itemData.description ?? "",
image: images.get(o.itemData.imageIds?.[0]) ?? null,
images: (o.itemData.imageIds ?? []).map((id) => images.get(id)).filter(Boolean), // in the order set in Square
category: categoryOf(o.itemData),
updatedAt: o.updatedAt ?? null, // the pieces' sitemap (piece-page.mjs)
variations: (o.itemData.variations ?? [])
.filter((v) => v.itemVariationData?.priceMoney)
.map((v) => {
const d = v.itemVariationData;
const here = d.locationOverrides?.find((x) => x.locationId === SQUARE_LOCATION_ID);
const name = o.itemData.variations.length > 1 ? `${o.itemData.name} (${d.name})` : o.itemData.name;
info.set(v.id, {
name,
tracked: Boolean(here?.trackInventory ?? d.trackInventory),
soldOut: Boolean(here?.soldOut),
shipLb: shipLbOf(o),
});
return { id: v.id, name: d.name, price: Number(d.priceMoney.amount), currency: d.priceMoney.currency };
}),
}))
.map((o) => {
const shipLb = shipLbOf(o);
return {
id: o.id,
name: o.itemData.name,
description: o.itemData.descriptionPlaintext ?? o.itemData.description ?? "",
image: images.get(o.itemData.imageIds?.[0]) ?? null,
images: (o.itemData.imageIds ?? []).map((id) => images.get(id)).filter(Boolean), // in the order set in Square
category: categoryOf(o.itemData),
...(shipLb ? { shipLb } : {}),
updatedAt: o.updatedAt ?? null, // the pieces' sitemap (piece-page.mjs)
variations: (o.itemData.variations ?? [])
.filter((v) => v.itemVariationData?.priceMoney)
.map((v) => {
const d = v.itemVariationData;
const here = d.locationOverrides?.find((x) => x.locationId === SQUARE_LOCATION_ID);
const name = o.itemData.variations.length > 1 ? `${o.itemData.name} (${d.name})` : o.itemData.name;
info.set(v.id, {
name,
tracked: Boolean(here?.trackInventory ?? d.trackInventory),
soldOut: Boolean(here?.soldOut),
shipLb,
});
return { id: v.id, name: d.name, price: Number(d.priceMoney.amount), currency: d.priceMoney.currency };
}),
};
})
.filter((i) => i.variations.length);

const counts = await liveStock([...info].filter(([, v]) => v.tracked).map(([id]) => id));
Expand Down
60 changes: 51 additions & 9 deletions backend/src/piece-page.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,29 @@ export function metaDescription(item) {
return spec ? `${spec}. Handmade in Tacoma by ${SITE_NAME}.` : `Handmade in Tacoma by ${SITE_NAME}.`;
}

/** Page <title>, adding "Handmade pottery" when the piece name has room (<= 60 characters). */
export function pieceTitle(item) {
const name = String(item.name ?? "").trim();
if (!/pottery|ceramic/i.test(name)) {
const rich = `${name} – Handmade pottery | ${SITE_NAME}`;
if (rich.length <= 60) return rich;
}
return `${name} | ${SITE_NAME}`;
}

function materialOf(item) {
const text = `${item.name ?? ""} ${item.description ?? ""}`;
if (/porcelain/i.test(text) && /stoneware/i.test(text)) return "Porcelain and stoneware";
if (/porcelain/i.test(text)) return "Porcelain";
if (/stoneware/i.test(text)) return "Stoneware";
return "Ceramic";
}

function photoAlt(item, i) {
const spec = specLine(item.description);
return i === 0 && spec ? `${item.name} — ${spec}` : `${item.name}, photo ${i + 1}`;
}

function picture(url, { alt, sizes, widths, eager }) {
const set = (f) => widths.map((w) => `${sized(url, w, f)} ${w}w`).join(", ");
// data-original: Square's full-size photo, which piece-page.js shows if the resized one can't load.
Expand All @@ -59,10 +82,13 @@ function picture(url, { alt, sizes, widths, eager }) {
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 crumbs = [
{ name: "Home", item: `${site}/` },
{ name: "Shop", item: `${site}/shop.html` },
...(item.category ? [{ name: item.category, item: `${site}/shop.html?type=${encodeURIComponent(item.category)}` }] : []),
{ name: item.name, item: url },
{ name: item.name },
];
return {
"@context": "https://schema.org",
Expand All @@ -76,6 +102,10 @@ export function structuredData(item, site) {
sku: item.id,
image: photosOf(item).map((p) => site + sized(p, 1200, "jpeg")),
...(item.category ? { category: item.category } : {}),
material: materialOf(item),
countryOfOrigin: "US",
...(item.shipLb > 0 ? { weight: { "@type": "QuantitativeValue", value: item.shipLb, unitCode: "LBR" } } : {}),
creator: { "@type": "Person", "@id": `${site}/about.html#aaron`, name: "Aaron Filson" },
brand: { "@type": "Brand", name: SITE_NAME },
offers: item.variations.map((v) => ({
"@type": "Offer",
Expand All @@ -85,7 +115,8 @@ export function structuredData(item, site) {
priceCurrency: v.currency ?? "USD",
availability: isOpen(v) ? "https://schema.org/InStock" : "https://schema.org/SoldOut",
itemCondition: "https://schema.org/NewCondition",
seller: { "@type": "Organization", name: SITE_NAME, url: `${site}/` },
availableDeliveryMethod: delivery,
seller: { "@type": "OnlineStore", "@id": `${site}/#store`, name: SITE_NAME, url: `${site}/` },
// policies.html: returns are not accepted (a piece broken in shipping is refunded).
hasMerchantReturnPolicy: {
"@type": "MerchantReturnPolicy",
Expand All @@ -96,6 +127,7 @@ export function structuredData(item, site) {
},
{
"@type": "BreadcrumbList",
"@id": `${url}#breadcrumb`,
itemListElement: crumbs.map((c, n) => ({ "@type": "ListItem", position: n + 1, ...c })),
},
],
Expand All @@ -115,6 +147,7 @@ function headTags(item, site) {
`<meta property="og:description" content="${esc(specLine(item.description) || metaDescription(item))}">`,
`<meta property="og:url" content="${esc(url)}">`,
`<meta property="og:image" content="${esc(photo ? site + sized(photo, 1200, "jpeg") : `${site}/favicon.svg`)}">`,
`<meta property="og:image:alt" content="${esc(photoAlt(item, 0))}">`,
// Read by Facebook and Pinterest for the price on a shared piece.
...(open.length
? [
Expand Down Expand Up @@ -147,7 +180,7 @@ function body(item, items, { policies }) {
? photos
.map((p, i) =>
picture(p, {
alt: `${item.name}, photo ${i + 1}`,
alt: photoAlt(item, i),
sizes: i ? "(min-width: 900px) 270px, 50vw" : "(min-width: 900px) 560px, 100vw",
widths: [800, 1600], // the sizes scripts/warm-photos.mjs makes for every photo
eager: i === 0,
Expand All @@ -164,7 +197,7 @@ function body(item, items, { policies }) {
};
return (
`<div class="wrap piece-page">` +
`<nav class="crumbs" aria-label="Breadcrumb"><ol><li><a href="/shop.html">Shop</a></li>` +
`<nav class="crumbs" aria-label="Breadcrumb"><ol><li><a href="/">Home</a></li><li><a href="/shop.html">Shop</a></li>` +
(item.category ? `<li><a href="/shop.html?type=${esc(encodeURIComponent(item.category))}">${esc(item.category)}</a></li>` : "") +
`<li><span aria-current="page">${esc(item.name)}</span></li></ol></nav>` +
`<div class="piece-layout"><div class="piece-gallery${sold ? " is-sold" : ""}">${gallery}</div>` +
Expand Down Expand Up @@ -196,7 +229,7 @@ function body(item, items, { policies }) {
* site: the address pages are linked from, e.g. https://updraftpotterystudio.com ("" when unknown)
*/
export function renderPiece({ item, items, shell, site }) {
const title = `${esc(item.name)} | ${SITE_NAME}`;
const title = esc(pieceTitle(item));
if (shell?.includes("[[piece]]"))
return shell
.replace(/<title>[^<]*<\/title>/, () => `<title>${title}</title>`)
Expand All @@ -215,10 +248,19 @@ export const gonePage = () =>
`<meta name="viewport" content="width=device-width, initial-scale=1"><meta name="robots" content="noindex"></head><body>` +
`<p>That piece isn't listed any more. <a href="/shop.html">See what's in the shop</a>.</p></body></html>`;

/** Every listed piece, sold ones too: their pages stay up. */
/** Every listed piece (sold ones too: their pages stay up), with its 1200px photos for image search. */
export function piecesSitemap(items, site) {
const urls = items.map(
(i) => ` <url><loc>${esc(`${site}/p/${i.id}`)}</loc>${i.updatedAt ? `<lastmod>${esc(i.updatedAt.slice(0, 10))}</lastmod>` : ""}</url>`,
const urls = items.map((i) => {
const loc = `<loc>${esc(`${site}/p/${i.id}`)}</loc>`;
const lastmod = i.updatedAt ? `<lastmod>${esc(i.updatedAt.slice(0, 10))}</lastmod>` : "";
const imgs = photosOf(i)
.map((p) => `<image:image><image:loc>${esc(site + sized(p, 1200, "jpeg"))}</image:loc></image:image>`)
.join("");
return ` <url>${loc}${lastmod}${imgs}</url>`;
});
return (
`<?xml version="1.0" encoding="UTF-8"?>\n` +
`<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">\n` +
`${urls.join("\n")}\n</urlset>\n`
);
return `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${urls.join("\n")}\n</urlset>\n`;
}
39 changes: 31 additions & 8 deletions backend/test/shop-pages.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { handler, _setSquare } from "../src/handler.mjs";
import sharp from "sharp";
import { parseRequest, handler as images, _resetCatalog, _catalogWaits } from "../src/images.mjs";
import { _resetShell } from "../src/piece.mjs";
import { renderPiece, structuredData } from "../src/piece-page.mjs";
import { renderPiece, structuredData, pieceTitle } from "../src/piece-page.mjs";

const SQUARE_PHOTO = "https://items-images-sandbox.s3.us-west-2.amazonaws.com/files/abc/original.jpeg";

Expand Down Expand Up @@ -116,7 +116,7 @@ const iter = (arr) => ({
yield* arr;
},
});
function fakeCatalog({ name = "Celadon bowl", description = "Cone 10 porcelain · celadon\nThrown in Tacoma." } = {}) {
function fakeCatalog({ name = "Celadon bowl", description = "Cone 10 porcelain · celadon\nThrown in Tacoma.", shipLb = 14 } = {}) {
return {
catalog: {
list: async () =>
Expand All @@ -128,6 +128,7 @@ function fakeCatalog({ name = "Celadon bowl", description = "Cone 10 porcelain
type: "ITEM",
id: "I1",
updatedAt: "2026-10-15T18:04:00.000Z",
...(shipLb ? { customAttributeValues: { ship_lb: { key: "ship_lb", numberValue: String(shipLb) } } } : {}),
itemData: {
name,
description,
Expand All @@ -145,12 +146,13 @@ function fakeCatalog({ name = "Celadon bowl", description = "Cone 10 porcelain
}
const get = (path) => handler({ requestContext: { http: { method: "GET" } }, rawPath: path });

test("the catalog lists every photo, in order, and the piece's type", async () => {
test("the catalog lists every photo, in order, the piece's type and its shipping weight", async () => {
_setSquare(fakeCatalog());
const { items } = JSON.parse((await get("/api/catalog")).body);
assert.equal(items[0].image, SQUARE_PHOTO);
assert.deepEqual(items[0].images, [SQUARE_PHOTO, SQUARE_PHOTO.replace("abc", "def")]);
assert.equal(items[0].category, "Bowls");
assert.equal(items[0].shipLb, 14);
});

// The JSON-LD block of a page.
Expand All @@ -166,30 +168,49 @@ test("a piece's page has its name, price, photos, words and product data, and no
assert.match(res.body, /<p>Thrown in Tacoma\.<\/p>/);
assert.match(res.body, /<p class="price">\$65\.00<\/p>/);
assert.match(res.body, /<a class="btn" href="\/shop\.html#p-I1">Buy in the shop<\/a>/, "works without the script");
assert.match(res.body, /alt="Celadon bowl — Cone 10 porcelain · celadon"/);
assert.match(res.body, /alt="Celadon bowl, photo 2"/);
assert.match(res.body, /<meta property="og:title" content="Celadon bowl · \$65\.00">/);
assert.match(res.body, /<meta property="og:description" content="Cone 10 porcelain · celadon">/);
assert.match(res.body, /<meta property="og:image:alt" content="Celadon bowl — Cone 10 porcelain · celadon">/);
assert.match(
res.body,
/<meta name="description" content="Cone 10 porcelain · celadon\. Handmade in Tacoma by Updraft Pottery Studio\.">/,
);
assert.match(res.body, /<meta property="product:price:amount" content="65\.00">/);
assert.match(res.body, /<link rel="canonical" href="\/p\/I1">/);
assert.match(res.body, /<a href="\/shop\.html\?type=Bowls">Bowls<\/a>/, "breadcrumbs");
assert.match(
res.body,
/<li><a href="\/">Home<\/a><\/li><li><a href="\/shop\.html">Shop<\/a><\/li><li><a href="\/shop\.html\?type=Bowls">Bowls<\/a><\/li>/,
"breadcrumbs",
);
assert.ok(!res.body.includes("p.js"), "no redirect to the shop any more");
const [product, crumbs] = ld(res.body)["@graph"];
assert.equal(product["@type"], "Product");
assert.equal(product.material, "Porcelain");
assert.equal(product.countryOfOrigin, "US");
assert.deepEqual(product.weight, { "@type": "QuantitativeValue", value: 14, unitCode: "LBR" });
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.equal(product.image.length, 2);
assert.deepEqual(
crumbs.itemListElement.map((c) => c.name),
["Shop", "Bowls", "Celadon bowl"],
["Home", "Shop", "Bowls", "Celadon bowl"],
);
assert.equal(crumbs.itemListElement.at(-1).item, undefined, "current page crumb omits item URL");
const data = JSON.parse(res.body.match(/<script type="application\/json" id="piece-data">(.*?)<\/script>/)[1]);
assert.deepEqual(data.variations, [{ id: "V1", name: "R", price: 6500, currency: "USD", stock: 1 }]);
});

test("piece titles include 'Handmade pottery' when short enough, and stay within 60 characters", () => {
assert.equal(pieceTitle({ name: "Lantern bowl" }), "Lantern bowl – Handmade pottery | Updraft Pottery Studio");
assert.equal(pieceTitle({ name: "Celadon footed bowl" }), "Celadon footed bowl | Updraft Pottery Studio");
assert.equal(pieceTitle({ name: "Ceramic vessel" }), "Ceramic vessel | Updraft Pottery Studio");
assert.ok(pieceTitle({ name: "Lantern bowl" }).length <= 60);
assert.ok(pieceTitle({ name: "Celadon footed bowl" }).length <= 60);
});

test("a piece's page goes into the site's shell; without one it's a plain page kept out of search", async (t) => {
const SHELL =
'<!DOCTYPE html><html lang="en"><head><title>Piece | Updraft Pottery Studio</title><style>x</style></head>' +
Expand All @@ -202,7 +223,7 @@ test("a piece's page goes into the site's shell; without one it's a plain page k
shell: SHELL,
site: "https://s.example",
});
assert.match(html, /<title>Bowl \| Updraft Pottery Studio<\/title>/);
assert.match(html, /<title>Bowl – Handmade pottery \| Updraft Pottery Studio<\/title>/);
assert.match(html, /<link rel="canonical" href="https:\/\/s\.example\/p\/I1">.*<\/head>/);
assert.match(html, /<main id="main"><div class="wrap piece-page">/);
assert.match(html, /<a href="\/policies\.html">Shipping, pickup &amp; returns<\/a>/, "the shell's menu has the policy page");
Expand Down Expand Up @@ -248,10 +269,12 @@ test("unknown or odd ids are gone (410), never an error", async () => {
assert.equal((await get("/p/%E0")).statusCode, 410, "a malformed escape is not an unhandled error");
});

test("the pieces' sitemap lists every listed piece with the day it last changed", async () => {
test("the pieces' sitemap lists every listed piece with the day it last changed and its photos", async () => {
_setSquare(fakeCatalog());
const res = await get("/p/sitemap.xml");
assert.equal(res.statusCode, 200);
assert.match(res.headers["content-type"], /application\/xml/);
assert.match(res.body, /<url><loc>\/p\/I1<\/loc><lastmod>2026-10-15<\/lastmod><\/url>/);
assert.match(res.body, /xmlns:image="http:\/\/www\.google\.com\/schemas\/sitemap-image\/1\.1"/);
assert.match(res.body, /<url><loc>\/p\/I1<\/loc><lastmod>2026-10-15<\/lastmod><image:image><image:loc>\/api\/img\?u=/);
assert.equal([...res.body.matchAll(/<image:loc>/g)].length, 2);
});
Loading
Loading