forked from vercel/commerce
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
80 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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,33 @@ | ||
import { getCollections, getPages, getProducts } from 'lib/shopify'; | ||
import { MetadataRoute } from 'next'; | ||
|
||
const baseUrl = process.env.NEXT_PUBLIC_VERCEL_URL | ||
? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}` | ||
: 'http://localhost:3000'; | ||
|
||
export default async function sitemap(): Promise<Promise<Promise<MetadataRoute.Sitemap>>> { | ||
const routesMap = ['', '/search'].map((route) => ({ | ||
url: `${baseUrl}${route}`, | ||
lastModified: new Date().toISOString() | ||
})); | ||
|
||
const collections = await getCollections(); | ||
const collectionsMap = collections.map((collection) => ({ | ||
url: `${baseUrl}${collection.path}`, | ||
lastModified: collection.updatedAt | ||
})); | ||
|
||
const products = await getProducts({}); | ||
const productsMap = products.map((product) => ({ | ||
url: `${baseUrl}/product/${product.handle}`, | ||
lastModified: product.updatedAt | ||
})); | ||
|
||
const pages = await getPages(); | ||
const pagesMap = pages.map((page) => ({ | ||
url: `${baseUrl}/${page.handle}`, | ||
lastModified: page.updatedAt | ||
})); | ||
|
||
return [...routesMap, ...collectionsMap, ...productsMap, ...pagesMap]; | ||
} |
This file contains 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 |
---|---|---|
|
@@ -55,6 +55,7 @@ const productFragment = /* GraphQL */ ` | |
...seo | ||
} | ||
tags | ||
updatedAt | ||
} | ||
${imageFragment} | ||
${seoFragment} | ||
|
This file contains 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 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 |
---|---|---|
|
@@ -9,6 +9,7 @@ const collectionFragment = /* GraphQL */ ` | |
seo { | ||
...seo | ||
} | ||
updatedAt | ||
} | ||
${seoFragment} | ||
`; | ||
|
This file contains 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 |
---|---|---|
@@ -1,21 +1,41 @@ | ||
import seoFragment from '../fragments/seo'; | ||
|
||
const pageFragment = /* GraphQL */ ` | ||
fragment page on Page { | ||
... on Page { | ||
id | ||
title | ||
handle | ||
body | ||
bodySummary | ||
seo { | ||
...seo | ||
} | ||
createdAt | ||
updatedAt | ||
} | ||
} | ||
${seoFragment} | ||
`; | ||
|
||
export const getPageQuery = /* GraphQL */ ` | ||
query getPage($handle: String!) { | ||
pageByHandle(handle: $handle) { | ||
id | ||
... on Page { | ||
title | ||
handle | ||
body | ||
bodySummary | ||
seo { | ||
...seo | ||
...page | ||
} | ||
} | ||
${pageFragment} | ||
`; | ||
|
||
export const getPagesQuery = /* GraphQL */ ` | ||
query getPages { | ||
pages(first: 100) { | ||
edges { | ||
node { | ||
...page | ||
} | ||
createdAt | ||
updatedAt | ||
} | ||
} | ||
} | ||
${seoFragment} | ||
${pageFragment} | ||
`; |
This file contains 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