|
| 1 | +--- |
| 2 | +"@bigcommerce/catalyst-makeswift": patch |
| 3 | +--- |
| 4 | + |
| 5 | +Add explicit Makeswift SEO metadata support to public-facing pages. When configured in Makeswift, the SEO title and description will take priority over the default values from BigCommerce or static translations. |
| 6 | + |
| 7 | +The following pages now support Makeswift SEO metadata: |
| 8 | + |
| 9 | +- Home page (`/`) |
| 10 | +- Catch-all page (`/[...rest]`) |
| 11 | +- Product page (`/product/[slug]`) |
| 12 | +- Brand page (`/brand/[slug]`) |
| 13 | +- Category page (`/category/[slug]`) |
| 14 | +- Blog list page (`/blog`) |
| 15 | +- Blog post page (`/blog/[blogId]`) |
| 16 | +- Search page (`/search`) |
| 17 | +- Cart page (`/cart`) |
| 18 | +- Compare page (`/compare`) |
| 19 | +- Gift certificates page (`/gift-certificates`) |
| 20 | +- Gift certificates balance page (`/gift-certificates/balance`) |
| 21 | +- Contact webpage (`/webpages/[id]/contact`) |
| 22 | +- Normal webpage (`/webpages/[id]/normal`) |
| 23 | + |
| 24 | +## Migration steps |
| 25 | + |
| 26 | +### Step 1: Add `getPageMetadata` function |
| 27 | + |
| 28 | +Add the `getPageMetadata` function to `core/lib/makeswift/client.ts`: |
| 29 | + |
| 30 | +```diff |
| 31 | ++ export async function getPageMetadata({ path, locale }: { path: string; locale: string }) { |
| 32 | ++ const snapshot = await getPageSnapshot({ path, locale }); |
| 33 | ++ |
| 34 | ++ if (snapshot == null) { |
| 35 | ++ return null; |
| 36 | ++ } |
| 37 | ++ |
| 38 | ++ const { meta } = snapshot.document; |
| 39 | ++ |
| 40 | ++ return { |
| 41 | ++ ...(meta.title && { title: meta.title }), |
| 42 | ++ ...(meta.description && { description: meta.description }), |
| 43 | ++ }; |
| 44 | ++ } |
| 45 | +``` |
| 46 | + |
| 47 | +Export the function from `core/lib/makeswift/index.ts`: |
| 48 | + |
| 49 | +```diff |
| 50 | + export { Page } from './page'; |
| 51 | +- export { client } from './client'; |
| 52 | ++ export { client, getPageMetadata } from './client'; |
| 53 | +``` |
| 54 | + |
| 55 | +### Step 2: Update page metadata |
| 56 | + |
| 57 | +Each page's `generateMetadata` function has been updated to fetch Makeswift metadata and use it as the primary source, falling back to existing values. Here's an example using the cart page: |
| 58 | + |
| 59 | +Update `core/app/[locale]/(default)/cart/page.tsx`: |
| 60 | + |
| 61 | +```diff |
| 62 | + import { getPreferredCurrencyCode } from '~/lib/currency'; |
| 63 | ++ import { getPageMetadata } from '~/lib/makeswift'; |
| 64 | + import { Slot } from '~/lib/makeswift/slot'; |
| 65 | +``` |
| 66 | + |
| 67 | +```diff |
| 68 | + export async function generateMetadata({ params }: Props): Promise<Metadata> { |
| 69 | + const { locale } = await params; |
| 70 | + |
| 71 | + const t = await getTranslations({ locale, namespace: 'Cart' }); |
| 72 | ++ const makeswiftMetadata = await getPageMetadata({ path: '/cart', locale }); |
| 73 | + |
| 74 | + return { |
| 75 | +- title: t('title'), |
| 76 | ++ title: makeswiftMetadata?.title || t('title'), |
| 77 | ++ description: makeswiftMetadata?.description || undefined, |
| 78 | + }; |
| 79 | + } |
| 80 | +``` |
| 81 | + |
| 82 | +Apply the same pattern to the other pages listed above, using the appropriate path for each page (e.g., `/blog`, `/search`, `/compare`, etc.). |
0 commit comments