Skip to content

Commit

Permalink
GCOM-1489: Make sure categories and products create the correct URL's…
Browse files Browse the repository at this point in the history
… in sitemaps
  • Loading branch information
paales committed Dec 16, 2024
1 parent 2a05c4f commit c37d1ec
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 39 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-adults-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphcommerce/next-config': patch
---

Make sure categories and products create the correct URL's in sitemaps
14 changes: 9 additions & 5 deletions examples/magento-graphcms/pages/sitemap/categories.xml.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@ import {
} from '@graphcommerce/next-ui'
import { GetServerSideProps } from 'next'
import { graphqlSsrClient } from '../../lib/graphql/graphqlSsrClient'
import { productListLink } from '@graphcommerce/magento-product'

const excludes = []
const additionalPaths = []
const excludes: string[] = []
const additionalPaths: string[] = []

export const getServerSideProps: GetServerSideProps = async (context) => {
const { locale } = context
if (!locale) throw Error('Locale not found')

const categoryPaths = await getCategoryStaticPaths(graphqlSsrClient(context), locale, {
limit: false,
})
const client = graphqlSsrClient(context)
const categoryRoutes = await getCategoryStaticPaths(client, locale, { limit: false })

const categoryPaths = categoryRoutes
.map(staticPathsToString)
.map((url) => productListLink({ url, filters: {}, sort: {} }).slice(1))

const paths = [...categoryPaths, ...additionalPaths]
.map(staticPathsToString)
Expand Down
3 changes: 1 addition & 2 deletions examples/magento-graphcms/pages/sitemap/content.xml.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { graphqlSsrClient } from '../../lib/graphql/graphqlSsrClient'

const excludes = [
'*page/home',
'*/p/*',
'*/product/global',
'*/product*',
'*/account*',
Expand All @@ -31,7 +30,7 @@ const excludes = [
'*/cart',
'*/checkout',
]
const additionalPaths = ['']
const additionalPaths: string[] = []

export const getServerSideProps: GetServerSideProps = async (context) => {
const { locale } = context
Expand Down
18 changes: 9 additions & 9 deletions examples/magento-graphcms/pages/sitemap/products.xml.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getProductStaticPaths } from '@graphcommerce/magento-product'
import {
excludeSitemap,
staticPathsToString,
Expand All @@ -7,22 +6,23 @@ import {
} from '@graphcommerce/next-ui'
import { GetServerSideProps } from 'next'
import { graphqlSsrClient } from '../../lib/graphql/graphqlSsrClient'
import { getProductStaticPaths, productPath } from '@graphcommerce/magento-product'

const excludes = []
const additionalPaths = []
const excludes: string[] = []
const additionalPaths: string[] = []

export const getServerSideProps: GetServerSideProps = async (context) => {
const { locale } = context

if (!locale) throw Error('Locale not defined')

const productPaths = await getProductStaticPaths(graphqlSsrClient(context), locale, {
limit: false,
})
const client = graphqlSsrClient(context)
const productRoutes = await getProductStaticPaths(client, locale, { limit: false })

const paths = [...productPaths, ...additionalPaths]
const productPaths = productRoutes
.map(staticPathsToString)
.filter(excludeSitemap(excludes))
.map((path) => productPath(path).slice(1))

const paths = [...productPaths, ...additionalPaths].filter(excludeSitemap(excludes))

return getServerSidePropsSitemap(context, toSitemapFields(context, paths))
}
Expand Down
18 changes: 11 additions & 7 deletions examples/magento-open-source/pages/sitemap/categories.xml.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import { getCategoryStaticPaths } from '@graphcommerce/magento-category'
import {
excludeSitemap,
getServerSidePropsSitemap,
staticPathsToString,
getServerSidePropsSitemap,
toSitemapFields,
} from '@graphcommerce/next-ui'
import type { GetServerSideProps } from 'next'
import { GetServerSideProps } from 'next'
import { graphqlSsrClient } from '../../lib/graphql/graphqlSsrClient'
import { productListLink } from '@graphcommerce/magento-product'

const excludes = []
const additionalPaths = []
const excludes: string[] = []
const additionalPaths: string[] = []

export const getServerSideProps: GetServerSideProps = async (context) => {
const { locale } = context
if (!locale) throw Error('Locale not found')

const categoryPaths = await getCategoryStaticPaths(graphqlSsrClient(context), locale, {
limit: false,
})
const client = graphqlSsrClient(context)
const categoryRoutes = await getCategoryStaticPaths(client, locale, { limit: false })

const categoryPaths = categoryRoutes
.map(staticPathsToString)
.map((url) => productListLink({ url, filters: {}, sort: {} }).slice(1))

const paths = [...categoryPaths, ...additionalPaths]
.map(staticPathsToString)
Expand Down
8 changes: 3 additions & 5 deletions examples/magento-open-source/pages/sitemap/content.xml.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import {
staticPathsToString,
toSitemapFields,
} from '@graphcommerce/next-ui'
import type { GetServerSideProps } from 'next'
import { graphqlSsrClient } from '../../lib/graphql/graphqlSsrClient'
import { GetServerSideProps } from 'next'

const excludes: string[] = [
'*/p/*',
const excludes = [
'*/account*',
'*/wishlist*',
'*/cart*',
Expand All @@ -23,7 +21,7 @@ const excludes: string[] = [
'*/cart',
'*/checkout',
]
const additionalPaths = ['']
const additionalPaths: string[] = []

export const getServerSideProps: GetServerSideProps = async (context) => {
const { locale } = context
Expand Down
22 changes: 11 additions & 11 deletions examples/magento-open-source/pages/sitemap/products.xml.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { getProductStaticPaths } from '@graphcommerce/magento-product'
import {
excludeSitemap,
getServerSidePropsSitemap,
staticPathsToString,
getServerSidePropsSitemap,
toSitemapFields,
} from '@graphcommerce/next-ui'
import type { GetServerSideProps } from 'next'
import { GetServerSideProps } from 'next'
import { graphqlSsrClient } from '../../lib/graphql/graphqlSsrClient'
import { getProductStaticPaths, productPath } from '@graphcommerce/magento-product'

const excludes = []
const additionalPaths = []
const excludes: string[] = []
const additionalPaths: string[] = []

export const getServerSideProps: GetServerSideProps = async (context) => {
const { locale } = context

if (!locale) throw Error('Locale not defined')

const productPaths = await getProductStaticPaths(graphqlSsrClient(context), locale, {
limit: false,
})
const client = graphqlSsrClient(context)
const productRoutes = await getProductStaticPaths(client, locale, { limit: false })

const paths = [...productPaths, ...additionalPaths]
const productPaths = productRoutes
.map(staticPathsToString)
.filter(excludeSitemap(excludes))
.map((path) => productPath(path).slice(1))

const paths = [...productPaths, ...additionalPaths].filter(excludeSitemap(excludes))

return getServerSidePropsSitemap(context, toSitemapFields(context, paths))
}
Expand Down

0 comments on commit c37d1ec

Please sign in to comment.