Repository navigation
Add SEO support: meta tags, OpenGraph, and JSON-LD #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
69179db
Add comprehensive SEO support with meta tags, OpenGraph, and JSON-LD
Cichorek 4b5f814
Fix SEO security and caching issues from code review
Cichorek 550f5ec
Merge remote-tracking branch 'origin/main' into SEO
Cichorek 19b0c00
FIX coderabbits comments
Cichorek 9a21af0
FIX biome check error
Cichorek 1043e1f
FIX coderabbits & Damian comments.
Cichorek 3d31073
FIX coderabbits comment
Cichorek ad11d88
Merge branch 'main' into SEO
Cichorek 55a7a68
Merge branch 'main' into SEO
Cichorek 8c38f7b
FIX: lint:
Cichorek 0f59e57
Merge origin/main into SEO, update cached helpers to new SDK expand p…
Cichorek 35b331a
Merge remote-tracking branch 'origin/main' into SEO
Cichorek 36b1912
Replace store.url and store API with ENV vars for SEO settings
Cichorek 0a7f22e
Merge remote-tracking branch 'origin/main' into SEO
Cichorek 7e54d16
Replace hardcoded store name with ENV vars, fix post-merge SEO issues
Cichorek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| interface JsonLdProps { | ||
| data: Record<string, unknown>; | ||
| } | ||
|
|
||
| export function JsonLd({ data }: JsonLdProps) { | ||
| const serialized = JSON.stringify(data).replaceAll("<", "\\u003c"); | ||
|
|
||
| return ( | ||
| <script | ||
| type="application/ld+json" | ||
| dangerouslySetInnerHTML={{ __html: serialized }} | ||
| /> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { getProduct, getStore, getTaxon } from "@spree/next"; | ||
| import { cache } from "react"; | ||
|
|
||
| export const getCachedProduct = cache( | ||
| (slugOrId: string, includes: string, locale: string) => | ||
| getProduct(slugOrId, { includes }, { locale }), | ||
| ); | ||
|
|
||
| export const getCachedTaxon = cache( | ||
| (idOrPermalink: string, includes: string, locale: string) => | ||
| getTaxon(idOrPermalink, { includes }, { locale }), | ||
| ); | ||
|
|
||
| export const getCachedStore = cache((locale: string) => getStore({ locale })); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import type { Metadata } from "next"; | ||
| import { getCachedStore } from "@/lib/data/cached"; | ||
| import { buildCanonicalUrl } from "@/lib/seo"; | ||
|
|
||
| interface CategoriesMetadataParams { | ||
| country: string; | ||
| locale: string; | ||
| } | ||
|
|
||
| export async function generateCategoriesMetadata({ | ||
| country, | ||
| locale, | ||
| }: CategoriesMetadataParams): Promise<Metadata> { | ||
| let store; | ||
| try { | ||
| store = await getCachedStore(locale); | ||
| } catch { | ||
| store = null; | ||
| } | ||
|
|
||
| const canonicalUrl = store?.url | ||
| ? buildCanonicalUrl(store.url, `/${country}/${locale}/taxonomies`) | ||
| : undefined; | ||
|
|
||
| return { | ||
| title: "Categories", | ||
| description: "Browse all product categories.", | ||
| ...(canonicalUrl ? { alternates: { canonical: canonicalUrl } } : {}), | ||
| openGraph: { | ||
| title: "Categories", | ||
| description: "Browse all product categories.", | ||
| ...(canonicalUrl ? { url: canonicalUrl } : {}), | ||
| type: "website", | ||
| }, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import type { Metadata } from "next"; | ||
| import { getCachedStore, getCachedTaxon } from "@/lib/data/cached"; | ||
| import { buildCanonicalUrl } from "@/lib/seo"; | ||
|
|
||
| interface CategoryMetadataParams { | ||
| country: string; | ||
| locale: string; | ||
| permalink: string[]; | ||
| } | ||
|
|
||
| export async function generateCategoryMetadata({ | ||
| country, | ||
| locale, | ||
| permalink, | ||
| }: CategoryMetadataParams): Promise<Metadata> { | ||
| const fullPermalink = permalink.join("/"); | ||
|
|
||
| let taxon; | ||
| try { | ||
| taxon = await getCachedTaxon(fullPermalink, "ancestors,children", locale); | ||
| } catch { | ||
| return { title: "Category Not Found" }; | ||
| } | ||
|
|
||
| let store; | ||
| try { | ||
| store = await getCachedStore(locale); | ||
| } catch { | ||
| store = null; | ||
| } | ||
|
|
||
| const title = taxon.meta_title || taxon.name; | ||
| const description = | ||
| taxon.meta_description || | ||
| taxon.description || | ||
| `Browse ${taxon.name} products.`; | ||
|
Cichorek marked this conversation as resolved.
Outdated
|
||
|
|
||
| const canonicalUrl = store?.url | ||
| ? buildCanonicalUrl(store.url, `/${country}/${locale}/t/${taxon.permalink}`) | ||
| : undefined; | ||
|
|
||
| return { | ||
| title, | ||
| description, | ||
| ...(taxon.meta_keywords ? { keywords: taxon.meta_keywords } : {}), | ||
| ...(canonicalUrl ? { alternates: { canonical: canonicalUrl } } : {}), | ||
| openGraph: { | ||
| title, | ||
| description, | ||
| ...(canonicalUrl ? { url: canonicalUrl } : {}), | ||
| type: "website", | ||
| ...(taxon.image_url | ||
| ? { images: [{ url: taxon.image_url, alt: taxon.name }] } | ||
| : {}), | ||
| }, | ||
| }; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.