Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

feat(content): name the product cards whose price changed in the catalog in Before you publish (#1664)

Cihan6a0ccccc408a
diff --git a/docs/guides/content-editor.mdx b/docs/guides/content-editor.mdx
index dfcc4a45c..c8c5b293d 100644
--- a/docs/guides/content-editor.mdx
+++ b/docs/guides/content-editor.mdx
@@ -157,7 +157,7 @@ The Content Agent never changes these passages. If you edit one, the editor asks
- **Add HTML** in the toolbar adds an HTML block: an embed, a widget or a form, kept exactly as written. Ansvisor never runs it. **Edit as HTML** shows the page's source; scripts, iframes and inline styles are removed when you switch back.
- **Products** (the bag in the toolbar, or **Add › Products** on an empty line), on an online shop's draft, adds products from your catalog: search by name, pick 1 to 4 that are in stock, and **Insert**. One shows as a card, more as a grid, each with its picture, name and price (in stock before low stock, then its cheapest variant there; a sale price when it's lower), linked to its page. It goes in as an HTML block; Webflow's rich text has no grid, so there it's a list, a product a line. A product sold out by the time you insert is left out, and the editor says so. When the Content Agent writes a new buying guide, best-of list, comparison or alternatives page with a shopping path, it adds the same grid of the path's products in stock (two or more), at the end of the section that links them most.
- **Send to CMS** (admins and managers) sends the page to the brand's Webflow collection as a draft item, or to your workflow tool through the brand's webhook, for it to create the post in your CMS. See [Send to CMS](/guides/send-to-cms).
-- **Mark ready** saves the page, sets it to **Ready** and keeps a version in History. If the draft was sent to the Action Center, it also completes its task there. Ansvisor doesn't publish the page: copy or export it to your site, or send it to your CMS.
+- **Mark ready** saves the page, sets it to **Ready** and keeps a version in History. If the draft was sent to the Action Center, it also completes its task there. Ansvisor doesn't publish the page: copy or export it to your site, or send it to your CMS. On a page with a shopping path, **Before you publish** also names the product cards whose price has changed in your catalog since they went in. A card keeps its price: to show today's, replace the card by deleting it and adding the product again (**Add › Products**).
- **Mark published** (the Library's **Status** menu, or the header's **Next step** once the page is ready, when Quality is on): once the page is live, tell Ansvisor where. It asks for the live address, starting from the page it optimizes or your site with the page's slug, and the **Live page** tab measures that address from then. If the draft came from the Action Center, its Publish task is completed once all the action's work is live. On a published page, the header's **Published** button changes the address. A page your CMS reports live, or one published in Webflow, gets its address on its own. An archived page is restored first.
- Click **Ready** in the header to move the page back to **In review**. A task that Mark ready completed is open again (**In Progress**), unless someone changed it in the Action Center since or the action is closed.
diff --git a/web/messages/en.json b/web/messages/en.json
index a8cf37e6a..958dceb97 100644
--- a/web/messages/en.json
+++ b/web/messages/en.json
@@ -5081,7 +5081,10 @@
"noCategory": "No link to the category page",
"noCategoryDetail": "Link the category page in Brief › Shopping path, so readers reach the products.",
"few": "{count} of {want} products linked",
- "fewDetail": "Link more of the products in Brief › Shopping path that are in stock: a product card or grid counts."
+ "fewDetail": "Link more of the products in Brief › Shopping path that are in stock: a product card or grid counts.",
+ "prices": "{count, plural, one {# product card shows an old price} other {# product cards show an old price}}",
+ "pricesDetail": "{list}{more, plural, =0 {} other { +# more}}. A card keeps the price it was put in with. To show today's, replace the card: delete it and add the product again (Add › Products).",
+ "priceItem": "{title}: {page} on the page, {now, select, none {no price} other {{now}}} now"
},
"disclosure": {
"ok": "Disclosure",
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.test.tsx
index 4cb45eb44..c1854447c 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.test.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.test.tsx
@@ -223,6 +223,27 @@ describe('BeforePublish', () => {
);
});
+ it('names the cards that show an old price, with the price now, beside the links row (#1610)', async () => {
+ await render(quality(), {
+ shopping: links({
+ linked: [product('Summit', 'ok')],
+ want: 1,
+ prices: [
+ { title: 'Summit', page: '$199.00', now: '$179.00' },
+ { title: 'Trail', page: '$50.00', now: null },
+ ],
+ }),
+ });
+ expect(rows().find((r) => r?.startsWith('2 product cards show an old price'))).toContain(
+ "Summit: $199.00 on the page, $179.00 now; Trail: $50.00 on the page, no price now. A card keeps the price it was put in with. To show today's, replace the card: delete it and add the product again (Add › Products).",
+ );
+ // The links themselves still work.
+ expect(rows().join('|')).toContain('Shopping links work');
+
+ await render(quality(), { shopping: links({ prices: [] }) });
+ expect(rows().join('|')).not.toContain('old price');
+ });
+
it('asks for the category page, then the products the rule wants', async () => {
await render(quality(), { shopping: links({ categoryLinked: false, want: 3 }) });
expect(rows().join('|')).toContain('No link to the category page');
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.tsx
index d4c3d035e..b5d76ac5e 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.tsx
@@ -27,7 +27,7 @@ import {
} from '@/lib/content/page-schema';
import { qualityPhase } from '@/lib/content/quality';
import { checksOff } from '@/lib/content/quality-profiles';
-import { listed, type ShoppingLinks } from '@/lib/content/shopping-check';
+import { listed, type CardPrice, type ShoppingLinks } from '@/lib/content/shopping-check';
import { cn } from '@/lib/utils';
import { copyToClipboard } from './_html-block';
import { trustSuggestions, type QualityRead } from './_quality-tab';
@@ -367,6 +367,9 @@ export function BeforePublish({
]
: []),
...(shopping ? [shoppingRow(t, shopping)] : []),
+ ...(typeof shopping === 'object' && shopping?.prices?.length
+ ? [cardPricesRow(t, shopping.prices)]
+ : []),
{ ...readyRow(t, paste, linksPending), fill: paste.placeholders > 0 },
];
// Nothing to ask about as Send opens it: straight on to the Send dialog.
@@ -650,6 +653,24 @@ function readyRow(t: T, paste: ReadyToPaste, linksPending: number): Row {
return { state: 'ok', title: t('paste.title'), detail: t('paste.ok') };
}
+/**
+ * The product cards that show a price the catalog no longer has (#1610): a
+ * card's price is written when it goes in. Put in again, it shows today's.
+ */
+function cardPricesRow(t: T, prices: CardPrice[]): Row {
+ const { shown, more } = listed(prices);
+ return {
+ state: 'check',
+ title: t('shopping.prices', { count: prices.length }),
+ detail: t('shopping.pricesDetail', {
+ list: shown
+ .map((p) => t('shopping.priceItem', { title: p.title, page: p.page, now: p.now ?? 'none' }))
+ .join('; '),
+ more,
+ }),
+ };
+}
+
/**
* The shopping links' row (shopping path, part 6): the products the page
* links that no longer sell, by name, to remove or replace on the page;
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx
index 4cdd81fe4..4b649318b 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx
@@ -3186,7 +3186,8 @@ export function DraftEditor({
};
// The page to publish's shopping links against the catalog (shopping path,
// part 6), as the Shopping rules read them: every link, a product grid's
- // too, and the products the rule asks for (none with it off). Read fresh:
+ // too, and the products the rule asks for (none with it off); and its
+ // product cards' prices against the catalog's now. Read fresh:
// 'reading' meanwhile, for a draft known to have a path. No row while
// none is known to, so a draft without one never shows it.
const shopRule = rules.rules.find(({ rule }) => rule.key === 'shopProductLinks')?.rule;
@@ -3196,7 +3197,8 @@ export function DraftEditor({
if (!publishOpen || shopping === null || shopping === 'reading') return null;
if (shoppingRefreshing) return 'reading';
if (shopping === 'failed') return 'failed';
- return shoppingLinks(readPage(publishOpen.html, 0).links ?? [], shopping, shopWant);
+ const page = readPage(publishOpen.html, 0);
+ return shoppingLinks(page.links ?? [], shopping, shopWant, page.cards ?? []);
}, [publishOpen, shopping, shoppingRefreshing, shopWant]);
// Read once per change (a link read landing, the title), not on every render.
const readyToPaste = useMemo((): ReadyToPaste | null => {
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_shopping-path.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_shopping-path.tsx
index 2c6ec27b3..9cfc27bd1 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_shopping-path.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_shopping-path.tsx
@@ -18,31 +18,17 @@ import {
choicesOf,
leftOutReason,
placementOf,
- priceAmount,
+ priceText,
withAdded,
withLocked,
withRemoved,
type NoPathReason,
type ShoppingPath,
- type ShoppingProduct,
} from '@/lib/content/shopping-path';
import { pagePath } from '@/lib/content/overlap';
-/** A product's price as the catalog has it, in its currency (priceAmount); null without one. */
-export function priceText(product: Pick<ShoppingProduct, 'price' | 'salePrice' | 'currency'>) {
- const amount = priceAmount(product);
- if (amount == null) return null;
- try {
- return product.currency
- ? new Intl.NumberFormat('en-US', { style: 'currency', currency: product.currency }).format(
- amount,
- )
- : new Intl.NumberFormat('en-US', { minimumFractionDigits: 2 }).format(amount);
- } catch {
- // A currency code Intl doesn't know: the amount and the code as the catalog has them.
- return `${amount} ${product.currency}`;
- }
-}
+// Where the product dialog and the tests read it.
+export { priceText };
type PathState =
| { status: 'loading' }
diff --git a/web/src/lib/actions/shopping-path.test.ts b/web/src/lib/actions/shopping-path.test.ts
index 67850e7fd..741e8e4ed 100644
--- a/web/src/lib/actions/shopping-path.test.ts
+++ b/web/src/lib/actions/shopping-path.test.ts
@@ -555,6 +555,23 @@ describe('getShoppingCheck', () => {
};
});
+ it('reads the price a card would show now, of the best stock, for each product that sells (#1610)', async () => {
+ db.catalog_variants = [
+ variant(1, 'limited_availability', { price: 149, sale_price: null, currency: 'USD' }),
+ variant(1, 'in_stock', { price: 199, sale_price: 179, currency: 'USD' }),
+ variant(2, 'in_stock', { price: null, sale_price: null, currency: 'USD' }),
+ variant(3, 'out_of_stock', { price: 50, sale_price: null, currency: 'USD' }),
+ ];
+ db.catalog_products = [row(1), row(2), row(3)];
+ draftRow().shopping_path = pathOf({ products: [1, 2, 3].map((n) => inPath(n)) });
+ const check = await getShoppingCheck(DRAFT);
+ expect(check?.products.map((p) => [p.state, p.price])).toEqual([
+ ['ok', '$179.00'],
+ ['ok', null],
+ ['sold_out', null],
+ ]);
+ });
+
it('reads each product now: gone, sold out, refused only when every variant in stock is', async () => {
const v1 = variant(1, 'In Stock');
const v3a = variant(3, 'in_stock');
@@ -612,6 +629,8 @@ describe('getShoppingCheck', () => {
title: `Boot ${n}`,
state,
inPath: true,
+ // No variant here has a price.
+ price: null,
})),
site: 'https://www.shop.example/',
});
@@ -644,15 +663,28 @@ describe('getShoppingCheck', () => {
const check = await getShoppingCheck(DRAFT);
expect(check!.products).toEqual([
- { key: 'shop.example/products/1', title: 'Boot 1', state: 'ok', inPath: true },
+ { key: 'shop.example/products/1', title: 'Boot 1', state: 'ok', inPath: true, price: null },
// 11 still sells: linking it is fine.
- { key: 'shop.example/products/10', title: 'Catalog 10', state: 'sold_out', inPath: false },
- { key: 'shop.example/products/12', title: 'Catalog 12', state: 'gone', inPath: false },
+ {
+ key: 'shop.example/products/10',
+ title: 'Catalog 10',
+ state: 'sold_out',
+ inPath: false,
+ price: null,
+ },
+ {
+ key: 'shop.example/products/12',
+ title: 'Catalog 12',
+ state: 'gone',
+ inPath: false,
+ price: null,
+ },
{
key: 'shop.example/products/13?variant=1',
title: 'Left Boot',
state: 'refused',
inPath: false,
+ price: null,
},
]);
});
diff --git a/web/src/lib/actions/shopping-path.ts b/web/src/lib/actions/shopping-path.ts
index ad015bdd9..0605cbf2b 100644
--- a/web/src/lib/actions/shopping-path.ts
+++ b/web/src/lib/actions/shopping-path.ts
@@ -16,6 +16,7 @@ import { readAllRpcRows } from '@/lib/supabase/rpc-pages';
import {
NO_PATH_REASONS,
bestInStock,
+ priceText,
shoppingChoicesSchema,
shoppingPathSchema,
type NoPathReason,
@@ -400,7 +401,7 @@ export async function getShoppingCheck(draftId: string): Promise<ShoppingCheck |
readByIds(ids, (chunk, from, to) =>
supabase
.from('catalog_variants')
- .select('id, product_id, external_id, url, availability')
+ .select('id, product_id, external_id, url, availability, price, sale_price, currency')
.eq('brand_id', brandId)
.in('product_id', chunk)
.is('removed_at', null)
@@ -442,6 +443,17 @@ export async function getShoppingCheck(draftId: string): Promise<ShoppingCheck |
if (list) list.push(v);
else selling.set(v.product_id, [v]);
}
+ // The price a card shows of it now, as one goes in (getProductsForBlock).
+ const priceOf = (id: string) => {
+ const variant = bestInStock(selling.get(id) ?? []);
+ return variant
+ ? priceText({
+ price: variant.price,
+ salePrice: variant.sale_price,
+ currency: variant.currency,
+ })
+ : null;
+ };
const stateOf = (id: string): ShoppingLinkState => {
const product = byId.get(id);
if (!product || product.removed_at) return 'gone';
@@ -453,7 +465,11 @@ export async function getShoppingCheck(draftId: string): Promise<ShoppingCheck |
const pathProducts = path.products.flatMap((p): ShoppingProductCheck[] => {
// A link the path couldn't keep (not http(s)) is null: nothing to check.
const key = p.url ? linkKey(p.url) : null;
- return key ? [{ key, title: p.title, state: stateOf(p.id), inPath: true }] : [];
+ if (!key) return [];
+ const state = stateOf(p.id);
+ return [
+ { key, title: p.title, state, inPath: true, price: state === 'ok' ? priceOf(p.id) : null },
+ ];
});
// Removed or left out: listed only when it no longer sells, at the
// catalog's page for it (the path doesn't keep one).
@@ -465,7 +481,7 @@ export async function getShoppingCheck(draftId: string): Promise<ShoppingCheck |
const url = product.url ?? variants.find((v) => v.product_id === id && v.url)?.url ?? null;
const key = url ? linkKey(url) : null;
const title = leftOutTitles.get(id) ?? product.title;
- return key ? [{ key, title, state, inPath: false }] : [];
+ return key ? [{ key, title, state, inPath: false, price: null }] : [];
});
return {
categories: path.categories
diff --git a/web/src/lib/content/rules.test.ts b/web/src/lib/content/rules.test.ts
index 3c5231913..fbc54bf87 100644
--- a/web/src/lib/content/rules.test.ts
+++ b/web/src/lib/content/rules.test.ts
@@ -1,6 +1,7 @@
import { describe, expect, it } from 'vitest';
import messages from '../../../messages/en.json';
import { htmlBlockElement } from './html-allowlist';
+import { productBlockHtml } from './product-block';
import type { ShoppingCheck, ShoppingLinkState } from './shopping-check';
import {
NO_DRAFT_RULES,
@@ -526,6 +527,20 @@ describe('shopping path rules (shopping path, part 6)', () => {
expect(status('shopCategoryLink')).toEqual({ state: 'ok' });
});
+ it('read the product cards with the price each shows, from the editor’s own markup (#1610)', () => {
+ const block = productBlockHtml([
+ { title: 'Summit', url: 'https://shop.example/products/p1', image: null, price: '$189.00' },
+ { title: 'Trail', url: 'https://shop.example/products/p2', image: null, price: null },
+ ]);
+ const read = page(`<p>Intro</p>${htmlBlockElement(block)}`);
+ expect(read.cards).toEqual([
+ { href: 'https://shop.example/products/p1', price: '$189.00' },
+ { href: 'https://shop.example/products/p2', price: null },
+ ]);
+ // A link in the text is no card.
+ expect(page('<p><a href="https://shop.example/products/p1">Summit</a></p>').cards).toEqual([]);
+ });
+
it('count only the products that sell towards the number, and name the ones that don’t', () => {
// Summit and Ridge sell; Trail, in the grid, is sold out: 2 of 3.
expect(status('shopProductLinks')).toEqual({ state: 'bad', code: 'partOf', count: 2, of: 3 });
diff --git a/web/src/lib/content/rules.ts b/web/src/lib/content/rules.ts
index ce8496e56..1cc9e77c5 100644
--- a/web/src/lib/content/rules.ts
+++ b/web/src/lib/content/rules.ts
@@ -10,6 +10,7 @@ import { countWords, languageCode } from '@/lib/content/readability';
import { wordsOf } from '@/lib/content/sources';
import {
shoppingLinks,
+ type PageCard,
type ShoppingCheck,
type ShoppingLinkState,
} from '@/lib/content/shopping-check';
@@ -573,6 +574,8 @@ export interface PageRead {
* Shopping rules and Before you publish read (shopping path).
*/
links?: string[];
+ /** The product cards in its HTML blocks, with the price each shows (Before you publish). */
+ cards?: PageCard[];
}
const BLOCK_TAGS = 'h1, h2, h3, p, li, table, ol, ul, blockquote';
@@ -603,6 +606,7 @@ export function readPage(html: string, characters: number): PageRead {
const links = new Set(
[...doc.body.querySelectorAll('a[href]')].map((a) => a.getAttribute('href') ?? ''),
);
+ const cards: PageCard[] = [];
for (const el of doc.body.querySelectorAll('[data-html-block]')) {
const inner = decodeHtmlBlock(el.getAttribute('data-html-block') ?? '');
if (!inner) continue;
@@ -611,6 +615,11 @@ export function readPage(html: string, characters: number): PageRead {
h.textContent?.trim(),
).length;
for (const a of block.body.querySelectorAll('a[href]')) links.add(a.getAttribute('href') ?? '');
+ // A card's price is its span, after the name (product-block.ts).
+ for (const a of block.body.querySelectorAll('a.ansvisor-product[href]')) {
+ const price = a.querySelector('span')?.textContent?.trim();
+ cards.push({ href: a.getAttribute('href') ?? '', price: price || null });
+ }
}
return {
blocks,
@@ -621,6 +630,7 @@ export function readPage(html: string, characters: number): PageRead {
characters,
htmlBlockH1s,
links: [...links].filter((href) => href.trim()),
+ cards,
};
}
diff --git a/web/src/lib/content/shopping-check.test.ts b/web/src/lib/content/shopping-check.test.ts
index af5b27eea..40bb2c9e3 100644
--- a/web/src/lib/content/shopping-check.test.ts
+++ b/web/src/lib/content/shopping-check.test.ts
@@ -28,6 +28,49 @@ const CHECK: ShoppingCheck = {
site: 'https://www.shop.example/blog/boots',
};
+describe('shoppingLinks, with the page’s product cards (#1610)', () => {
+ const priced: ShoppingCheck = {
+ ...CHECK,
+ products: [
+ { ...product('a', 'ok'), price: '$189.00' },
+ { ...product('d', 'ok'), price: null },
+ { ...product('c', 'sold_out'), price: null },
+ // Its price not read: never compared.
+ product('e', 'ok'),
+ ],
+ };
+ const card = (id: string, price: string | null) => ({
+ href: `https://shop.example/products/${id}`,
+ price,
+ });
+
+ it('lists each product once whose card shows a price the catalog no longer has', () => {
+ const read = shoppingLinks([], priced, 0, [
+ card('a', '$199.00'),
+ // A second card of it: listed once, by the first.
+ card('a', '$179.00'),
+ // No price in the catalog now.
+ card('d', '$50.00'),
+ // No longer sells: listed to remove, not for its price.
+ card('c', '$20.00'),
+ card('e', '$1.00'),
+ // Not one the path checks.
+ card('x', '$5.00'),
+ ]);
+ expect(read.prices).toEqual([
+ { title: 'A', page: '$199.00', now: '$189.00' },
+ { title: 'D', page: '$50.00', now: null },
+ ]);
+ });
+
+ it("leaves a card with today's price, or with none, alone", () => {
+ expect(shoppingLinks([], priced, 0, [card('a', '$189.00'), card('d', null)]).prices).toEqual(
+ [],
+ );
+ expect(shoppingLinks([], priced).prices).toEqual([]);
+ });
+});
+
describe('shoppingLinks', () => {
it('reads the category page and the products linked, each once, and those that no longer sell', () => {
const read = shoppingLinks(
diff --git a/web/src/lib/content/shopping-check.ts b/web/src/lib/content/shopping-check.ts
index fecdb0191..0faa98484 100644
--- a/web/src/lib/content/shopping-check.ts
+++ b/web/src/lib/content/shopping-check.ts
@@ -23,6 +23,27 @@ export interface ShoppingProductCheck {
* linked" alone.
*/
inPath: boolean;
+ /**
+ * Its price as a card would show it now ("$189.00", shopping-path.ts
+ * priceText, of its best stock's variant); null without one, or when it
+ * no longer sells. Absent when it wasn't read: no card is compared then.
+ */
+ price?: string | null;
+}
+
+/** A product card or grid card on the page, as its HTML block holds it (product-block.ts). */
+export interface PageCard {
+ href: string;
+ /** The price it shows, as it shows it; null for a card without one. */
+ price: string | null;
+}
+
+/** A card that shows a price the catalog no longer has: the page's, and the one now. */
+export interface CardPrice {
+ title: string;
+ page: string;
+ /** Null when the catalog has no price for it now. */
+ now: string | null;
}
export interface ShoppingCheck {
@@ -50,6 +71,8 @@ export interface ShoppingLinks {
want: number;
/** The path's category pages. */
categories: number;
+ /** The cards of products that sell whose price changed since they went in, each product once. */
+ prices?: CardPrice[];
}
/** A link's key, a relative one read against `site`; null when it leads to no page. */
@@ -70,11 +93,14 @@ function hrefKey(href: string, site: string | null): string | null {
* The page's links read against its shopping path, `n` the products it
* should link (the Shopping rule's number). Only products that sell count
* towards it: a sold-out one is the one to swap, not a link that counts.
+ * With the page's product cards, those whose price isn't the catalog's now:
+ * a card's price is written when it goes in, and stays.
*/
export function shoppingLinks(
hrefs: readonly string[],
check: ShoppingCheck,
n = 0,
+ cards: readonly PageCard[] = [],
): ShoppingLinks {
const keys = new Set(
hrefs.map((href) => hrefKey(href, check.site)).filter((k): k is string => !!k),
@@ -87,6 +113,18 @@ export function shoppingLinks(
return true;
});
const selling = products.filter((p) => p.inPath && p.state === 'ok');
+ const byKey = new Map(products.map((p) => [p.key, p]));
+ const prices = new Map<string, CardPrice>();
+ for (const card of cards) {
+ const product = byKey.get(hrefKey(card.href, check.site) ?? '');
+ // One that no longer sells is listed to remove already; a card without
+ // a price shows none to be wrong.
+ if (!product || product.state !== 'ok' || product.price === undefined) continue;
+ if (!card.price || prices.has(product.key)) continue;
+ if (card.price !== product.price) {
+ prices.set(product.key, { title: product.title, page: card.price, now: product.price });
+ }
+ }
return {
categoryLinked: check.categories.some((key) => keys.has(key)),
linked: selling.filter((p) => keys.has(p.key)),
@@ -94,6 +132,7 @@ export function shoppingLinks(
products: selling.length,
want: Math.min(Math.max(0, n), selling.length),
categories: check.categories.length,
+ prices: [...prices.values()],
};
}
diff --git a/web/src/lib/content/shopping-path.ts b/web/src/lib/content/shopping-path.ts
index b8c4cc469..d50c5d6d3 100644
--- a/web/src/lib/content/shopping-path.ts
+++ b/web/src/lib/content/shopping-path.ts
@@ -63,6 +63,30 @@ export function priceAmount({
return sale != null && sale < regular ? sale : regular;
}
+/**
+ * A price as a product card shows it ("$189.00", priceAmount's), in its
+ * currency; null without one. Before you publish compares a card's with
+ * the catalog's now (shopping-check.ts).
+ */
+export function priceText(product: {
+ price: number | null;
+ salePrice: number | null;
+ currency: string | null;
+}): string | null {
+ const amount = priceAmount(product);
+ if (amount == null) return null;
+ try {
+ return product.currency
+ ? new Intl.NumberFormat('en-US', { style: 'currency', currency: product.currency }).format(
+ amount,
+ )
+ : new Intl.NumberFormat('en-US', { minimumFractionDigits: 2 }).format(amount);
+ } catch {
+ // A currency code Intl doesn't know: the amount and the code as the catalog has them.
+ return `${amount} ${product.currency}`;
+ }
+}
+
/** In stock before low stock (limited availability): the better stock, the lower. */
function inStockRank(availability: string | null): number {
return (availability ?? '').toLowerCase().replace(/[\s-]+/g, '_') === 'limited_availability'