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 .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0

- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
Expand Down
3 changes: 3 additions & 0 deletions backend/src/catalog.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export async function loadCatalog() {
for await (const obj of pager) objects.push(obj);

const images = new Map(objects.filter((o) => o.type === "IMAGE").map((o) => [o.id, o.imageData?.url]));
const imageCaptions = new Map(objects.filter((o) => o.type === "IMAGE").map((o) => [o.id, o.imageData?.caption?.trim() || ""]));
const categories = new Map(objects.filter((o) => o.type === "CATEGORY").map((o) => [o.id, o.categoryData?.name]));
// Square has moved items from one category to a list; the reporting category (else the first) is the shop's "type".
const categoryOf = (d) => categories.get(d.reportingCategory?.id ?? d.categories?.[0]?.id ?? d.categoryId) ?? null;
Expand All @@ -52,12 +53,14 @@ export async function loadCatalog() {
.map((o) => {
const shipLb = numberAttr(o, SHIP_LB_KEY);
const itemLb = numberAttr(o, ITEM_LB_KEY);
const captions = (o.itemData.imageIds ?? []).map((id) => imageCaptions.get(id) ?? "");
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
...(captions.some(Boolean) ? { imageCaptions: captions } : {}),
category: categoryOf(o.itemData),
...(shipLb ? { shipLb } : {}),
...(itemLb ? { itemLb } : {}),
Expand Down
157 changes: 128 additions & 29 deletions backend/src/piece-page.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,74 @@ export function priceText(item) {
return `${new Set(open.map((v) => v.price)).size > 1 ? "From " : ""}${money(low, open[0].currency)}`;
}

/** The search-result description: the spec line, then where it was made. */
const clipDesc = (s, max = 160) => {
if (s.length <= max) return s;
const cut = s.slice(0, max - 1);
const space = cut.lastIndexOf(" ");
return `${(space > 60 ? cut.slice(0, space) : cut).replace(/[.,;:!?-]+$/, "")}…`;
};

/** Search-result description combining spec line, lead sentence, and studio attribution (<= 160 chars). */
export function metaDescription(item) {
const spec = specLine(item.description);
return spec ? `${spec}. Handmade in Tacoma by ${SITE_NAME}.` : `Handmade in Tacoma by ${SITE_NAME}.`;
const rest = descriptionRest(item.description)[0] ?? "";
if (spec && rest) {
const base = `${spec.endsWith(".") ? spec : `${spec}.`} ${rest}`;
if (base.includes(SITE_NAME)) return clipDesc(base);
const ended = /[.!?]$/.test(base) ? base : `${base}.`;
for (const tail of [` Handmade by ${SITE_NAME}.`, ` ${SITE_NAME}.`]) {
if (ended.length + tail.length <= 160) return ended + tail;
}
return clipDesc(base);
}
if (spec) return clipDesc(`${spec.endsWith(".") ? spec : `${spec}.`} Handmade in Tacoma by ${SITE_NAME}.`);
if (rest) {
if (rest.includes(SITE_NAME)) return clipDesc(rest);
const ended = /[.!?]$/.test(rest) ? rest : `${rest}.`;
const tail = ` Handmade in Tacoma by ${SITE_NAME}.`;
return clipDesc(ended.length + tail.length <= 160 ? ended + tail : rest);
}
return `Handmade in Tacoma by ${SITE_NAME}.`;
}

/** Page <title>, adding "Handmade pottery" when the piece name has room (<= 60 characters). */
/** Page <title>, adding "Handmade pottery", clay material, or "Pottery" when it fits <= 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;
if (!/pottery|ceramic|porcelain|stoneware/i.test(name)) {
const mat = materialOf(item);
const suffixes = ["Handmade pottery", ...(mat === "Porcelain" || mat === "Stoneware" ? [mat] : []), "Pottery"];
for (const s of suffixes) {
const rich = `${name} – ${s} | ${SITE_NAME}`;
if (rich.length <= 60) return rich;
}
}
return `${name} | ${SITE_NAME}`;
}

/** @type {[RegExp, string][]} */
const COLOR_PATTERNS = [
[/\bceladon[- ]green\b|\bceladon\b/i, "Celadon green"],
[/\bolive[- ]brown\b/i, "Olive brown"],
[/\bsage[- ]green\b/i, "Sage green"],
[/\bgrey[- ]green\b|\bgray[- ]green\b/i, "Grey-green"],
[/\bbrown[- ]grey\b|\bbrown[- ]gray\b/i, "Brown-grey"],
[/\bpale green\b/i, "Pale green"],
[/\brust[- ]red\b/i, "Rust red"],
[/\btenmoku\b|\btemmoku\b/i, "Dark brown"],
[/\bshino\b/i, "Warm white"],
[/\bcobalt\b/i, "Cobalt blue"],
[/\bdark brown\b/i, "Dark brown"],
[/\bwarm brown\b/i, "Warm brown"],
];

/** Infers the glaze color for Product.color / Google Shopping <g:color> from explicit color or glaze copy. */
export function colorOf(item) {
if (typeof item.color === "string" && item.color.trim()) return item.color.trim();
const text = `${item.name ?? ""} ${item.description ?? ""}`;
for (const [re, label] of COLOR_PATTERNS) if (re.test(text)) return label;
return null;
}

function materialOf(item) {
const text = `${item.name ?? ""} ${item.description ?? ""}`;
if (/porcelain/i.test(text) && /stoneware/i.test(text)) return "Porcelain and stoneware";
Expand All @@ -65,6 +117,8 @@ function materialOf(item) {
}

function photoAlt(item, i) {
const caption = item.imageCaptions?.[i];
if (caption) return `${item.name} — ${caption}`;
const spec = specLine(item.description);
return i === 0 && spec ? `${item.name} — ${spec}` : `${item.name}, photo ${i + 1}`;
}
Expand Down Expand Up @@ -275,9 +329,10 @@ export function structuredData(item, site) {
codeValue: gpc.codeValue,
inCodeSet: GOOGLE_TAXONOMY,
};
const delivery =
item.shipLb > 0 ? ["https://schema.org/OnSitePickup", "https://schema.org/ParcelService"] : ["https://schema.org/OnSitePickup"];
const rates = shippingRatesFor(item.shipLb);
const delivery = rates ? ["https://schema.org/OnSitePickup", "https://schema.org/ParcelService"] : ["https://schema.org/OnSitePickup"];
const shippingDetails = shippingDetailsFor(item.shipLb);
const color = colorOf(item);
const crumbs = [
{ name: "Home", item: `${site}/` },
{ name: "Shop", item: `${site}/shop.html` },
Expand All @@ -297,13 +352,14 @@ export function structuredData(item, site) {
image: photosOf(item).map((p) => site + sized(p, 1200, "jpeg")),
category: item.category ? [item.category, categoryCode] : categoryCode,
material: materialOf(item),
...(color ? { color } : {}),
countryOfOrigin: "US",
...(dims.depth ? { depth: qvIn(dims.depth) } : {}),
...(dims.width ? { width: qvIn(dims.width) } : {}),
...(dims.height ? { height: qvIn(dims.height) } : {}),
...(item.itemLb > 0 ? { weight: qvLb(item.itemLb) } : {}),
creator: { "@type": "Person", "@id": `${site}/about.html#aaron`, name: "Aaron Filson" },
brand: { "@type": "Brand", name: SITE_NAME },
creator: { "@type": "Person", "@id": `${site}/about.html#aaron`, name: "Aaron Filson", url: `${site}/about.html` },
brand: { "@type": "Brand", "@id": `${site}/#store`, name: SITE_NAME, url: `${site}/` },
offers: item.variations.map((v) => ({
"@type": "Offer",
...(many ? { name: v.name } : {}),
Expand All @@ -317,6 +373,8 @@ export function structuredData(item, site) {
// policies.html: returns are not accepted (a piece broken in shipping is refunded).
hasMerchantReturnPolicy: {
"@type": "MerchantReturnPolicy",
"@id": `${site}/policies.html#returns`,
merchantReturnLink: `${site}/policies.html#returns`,
applicableCountry: "US",
returnPolicyCategory: "https://schema.org/MerchantReturnNotPermitted",
},
Expand Down Expand Up @@ -358,41 +416,78 @@ function headTags(item, site) {
].join("");
}

function rotateList(list, offset) {
if (list.length <= 1) return list;
const k = offset % list.length;
return [...list.slice(k), ...list.slice(0, k)];
}

/** Picks up to `limit` available sibling pieces: same category first, rotated deterministically by item.id. */
export function morePieces(item, items, limit = 4) {
const open = items.filter((i) => i.id !== item.id && i.variations.some(isOpen));
if (!open.length) return [];
const same = item.category ? open.filter((i) => i.category === item.category) : [];
const other = item.category ? open.filter((i) => i.category !== item.category) : open;
if (open.length <= limit) return [...same, ...other].slice(0, limit);
let h = 0;
for (const ch of String(item.id ?? "")) h = (h * 31 + ch.charCodeAt(0)) >>> 0;
return [...rotateList(same, h), ...rotateList(other, h)].slice(0, limit);
}

function moreCard(item) {
const photo = photosOf(item)[0];
return (
`<a class="card product-link" href="/p/${esc(item.id)}">` +
(photo
? picture(photo, { alt: "", sizes: "(max-width: 599px) 46vw, 260px", widths: [400, 800], eager: false })
? picture(photo, { alt: photoAlt(item, 0), sizes: "(max-width: 599px) 46vw, 260px", widths: [400, 800], eager: false })
: '<div class="ph"></div>') +
`<div class="card-body"><h3>${esc(item.name)}</h3><span class="price">${esc(priceText(item))}</span></div></a>`
);
}

/** What goes in <main>: photos, words, price, the way to buy, and a few other pieces. */
/** What goes in <main>: photos, words, price, logistics, the way to buy, and other pieces. */
function body(item, items, { policies }) {
const photos = photosOf(item);
const sold = !item.variations.some(isOpen);
const spec = specLine(item.description);
const gallery = photos.length
? photos
.map((p, i) =>
picture(p, {
alt: photoAlt(item, i),
.map((p, i) => {
const alt = photoAlt(item, i);
const pic = picture(p, {
alt,
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
widths: i ? [400, 800, 1600] : [800, 1600], // the sizes scripts/warm-photos.mjs makes for every photo
eager: i === 0,
}),
)
});
const zoom = `<a class="zoom" href="${esc(sized(p, 1600, "webp"))}" data-alt="${esc(alt)}" data-title="${esc(item.name)}"${spec ? ` data-desc="${esc(spec)}"` : ""}>${pic}</a>`;
return i === 0 && sold ? `<div class="piece-photo">${zoom}<span class="sold-badge">Sold</span></div>` : zoom;
})
.join("")
: '<div class="ph"></div>';
const others = items.filter((i) => i.id !== item.id && i.variations.some(isOpen)).slice(0, 4);
: sold
? `<div class="piece-photo"><div class="ph"></div><span class="sold-badge">Sold</span></div>`
: '<div class="ph"></div>';
const rates = shippingRatesFor(item.shipLb);
const facts = sold
? []
: [
...(item.variations.length === 1 && item.variations[0].stock === 1 ? ["One of a kind — 1 available"] : []),
...(item.itemLb > 0 ? [`Weight: ${+Number(item.itemLb).toFixed(2)} lb (${Math.round(Number(item.itemLb) * 16)} oz)`] : []),
rates
? `Double-boxed insured US shipping in 1–2 business days (up to $${rates.wa} WA / $${rates.us} US), or free Tacoma pickup`
: "Tacoma studio pickup only — not available for shipping",
...(rates ? ["Arrived broken? Email a photo for a full refund"] : []),
];
const others = morePieces(item, items, 4);
// For piece-page.js, which turns the link below into Add to cart; stock as of this page.
const data = {
id: item.id,
name: item.name,
variations: item.variations.map(({ id, name, price, currency, stock }) => ({ id, name, price, currency, stock: stock ?? null })),
};
const soldCopy = item.category
? `<p class="muted">This one-of-a-kind piece has found a home. <a href="/shop.html?type=${esc(encodeURIComponent(item.category))}">See available ${esc(item.category)}</a>, <a href="/shop.html">browse the shop</a>, or <a href="#signup">get notified when the next kiln opens</a>.</p>`
: `<p class="muted">This one-of-a-kind piece has found a home. <a href="/shop.html">See what's available</a>, or <a href="#signup">get notified when the next kiln opens</a>.</p>`;
return (
`<div class="wrap piece-page">` +
`<nav class="crumbs" aria-label="Breadcrumb"><ol><li><a href="/">Home</a></li><li><a href="/shop.html">Shop</a></li>` +
Expand All @@ -405,10 +500,11 @@ function body(item, items, { policies }) {
.map((t) => `<p>${esc(t)}</p>`)
.join("")}</div>` +
`<div class="piece-buy" id="piece-buy"><p class="price">${esc(priceText(item))}</p>` +
(sold
? `<p class="muted">This piece has found a home. <a href="/shop.html">See what's available</a>.</p>`
: `<p><a class="btn" href="/shop.html#p-${esc(item.id)}">Buy in the shop</a></p>`) +
(sold ? soldCopy : `<p><a class="btn" href="/shop.html#p-${esc(item.id)}">Buy in the shop</a></p>`) +
`</div>` +
(facts.length
? `<ul class="piece-facts" aria-label="Piece and shipping details">${facts.map((f) => `<li>${esc(f)}</li>`).join("")}</ul>`
: "") +
`<p class="piece-more"><a href="/care.html">Care &amp; use</a>` +
(policies ? `<a href="/policies.html">Shipping, pickup &amp; returns</a>` : "") +
`</p></div></div>` +
Expand Down Expand Up @@ -499,20 +595,23 @@ export function piecesFeed(items, site) {

/**
* Google Merchant Center + Pinterest Catalogs RSS 2.0 XML product feed (/p/merchant.xml).
* Lists every unarchived piece with live availability (in_stock / out_of_stock), explicit
* identifier_exists=no for one-of-a-kind handmade work, Google Product Taxonomy ID, 3D dimensions,
* item + shipping weights, and WA / US Ground shipping rates.
* Lists every available piece (permanently sold one-of-a-kind items are omitted per Google Merchant
* Center guidelines), with identifier_exists=no (and no g:brand conflict), Google Product Taxonomy
* ID, glaze color, 3D dimensions, item + shipping weights, and WA / US Ground shipping rates.
*/
export function piecesMerchantFeed(items, site) {
const entries = items.flatMap((item) => {
const open = item.variations.filter(isOpen);
if (!open.length) return [];
const many = item.variations.length > 1;
const url = `${site}/p/${item.id}`;
const photos = photosOf(item);
const dims = parseDimensions(item);
const gpc = googleCategoryFor(item);
const color = colorOf(item);
const rates = shippingRatesFor(item.shipLb);
const desc = item.description?.trim() || metaDescription(item);
return item.variations.map((v) => {
return open.map((v) => {
const id = many ? `${item.id}-${v.id}` : item.id;
const title = many ? `${item.name} (${v.name})` : item.name;
const fields = [
Expand All @@ -523,14 +622,14 @@ export function piecesMerchantFeed(items, site) {
`<link>${esc(url)}</link>`,
...(photos[0] ? [`<g:image_link>${esc(site + sized(photos[0], 1200, "jpeg"))}</g:image_link>`] : []),
...photos.slice(1, 11).map((p) => `<g:additional_image_link>${esc(site + sized(p, 1200, "jpeg"))}</g:additional_image_link>`),
`<g:availability>${isOpen(v) ? "in_stock" : "out_of_stock"}</g:availability>`,
`<g:availability>in_stock</g:availability>`,
`<g:price>${(v.price / 100).toFixed(2)} ${esc(v.currency ?? "USD")}</g:price>`,
`<g:condition>new</g:condition>`,
`<g:brand>${SITE_NAME}</g:brand>`,
`<g:identifier_exists>no</g:identifier_exists>`,
`<g:google_product_category>${esc(gpc.codeValue)}</g:google_product_category>`,
...(item.category ? [`<g:product_type>${esc(item.category)}</g:product_type>`] : []),
`<g:material>${esc(materialOf(item))}</g:material>`,
...(color ? [`<g:color>${esc(color)}</g:color>`] : []),
...(dims.depth ? [`<g:product_length>${+dims.depth.toFixed(3)} in</g:product_length>`] : []),
...(dims.width ? [`<g:product_width>${+dims.width.toFixed(3)} in</g:product_width>`] : []),
...(dims.height ? [`<g:product_height>${+dims.height.toFixed(3)} in</g:product_height>`] : []),
Expand Down
Loading
Loading