@graphcommerce/next-ui 8.1.0-canary.7 → 8.1.0-canary.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/PageMeta/PageMeta.tsx +9 -4
- package/hooks/useDateTimeFormat.ts +1 -3
- package/index.ts +2 -0
- package/package.json +10 -9
- package/utils/robots.ts +41 -0
- package/utils/sitemap.ts +47 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 8.1.0-canary.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#2223](https://github.com/graphcommerce-org/graphcommerce/pull/2223) [`d7459fe`](https://github.com/graphcommerce-org/graphcommerce/commit/d7459feb6e6902af09ab9ff766c0b3b1a74fb723) - Updated canonicalize helper for better multi domain support
|
|
8
|
+
([@bramvanderholst](https://github.com/bramvanderholst))
|
|
9
|
+
|
|
10
|
+
## 8.1.0-canary.8
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [#2247](https://github.com/graphcommerce-org/graphcommerce/pull/2247) [`444e446`](https://github.com/graphcommerce-org/graphcommerce/commit/444e446a218cc9da3defb940a6d5cce0229ff845) - Added clear upgrade instructions for linguiLocale
|
|
15
|
+
([@paales](https://github.com/paales))
|
|
16
|
+
|
|
3
17
|
## 8.1.0-canary.7
|
|
4
18
|
|
|
5
19
|
## 8.1.0-canary.6
|
package/PageMeta/PageMeta.tsx
CHANGED
|
@@ -70,11 +70,16 @@ export function canonicalize(router: PartialNextRouter, incoming?: Canonical) {
|
|
|
70
70
|
if (localeDomain) {
|
|
71
71
|
canonical = localeDomain
|
|
72
72
|
} else {
|
|
73
|
-
|
|
73
|
+
const conf = storefrontConfig(router.locale)
|
|
74
|
+
|
|
75
|
+
href = addBasePath(
|
|
76
|
+
addLocale(as, curLocale, conf?.domain ? conf.locale : router.defaultLocale),
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
let siteUrl = conf?.canonicalBaseUrl || import.meta.graphCommerce.canonicalBaseUrl
|
|
80
|
+
|
|
81
|
+
if (conf?.domain && !conf?.canonicalBaseUrl) siteUrl = `https://${conf.domain}`
|
|
74
82
|
|
|
75
|
-
let siteUrl =
|
|
76
|
-
storefrontConfig(router.locale)?.canonicalBaseUrl ||
|
|
77
|
-
import.meta.graphCommerce.canonicalBaseUrl
|
|
78
83
|
if (siteUrl.endsWith('/')) siteUrl = siteUrl.slice(0, -1)
|
|
79
84
|
|
|
80
85
|
canonical = `${siteUrl}${href}`
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { normalizeLocale } from '@graphcommerce/lingui-next'
|
|
2
1
|
import { useMemo } from 'react'
|
|
3
|
-
import {
|
|
4
|
-
import { useLocale } from '@graphcommerce/next-ui'
|
|
2
|
+
import { useLocale } from './useLocale'
|
|
5
3
|
|
|
6
4
|
export type DateTimeFormatProps = Intl.DateTimeFormatOptions
|
|
7
5
|
|
package/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/next-ui",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "8.1.0-canary.
|
|
5
|
+
"version": "8.1.0-canary.9",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"@emotion/server": "^11.11.0",
|
|
18
18
|
"@emotion/styled": "^11.11.0",
|
|
19
19
|
"cookie": "^0.6.0",
|
|
20
|
+
"next-sitemap": "4.2.3",
|
|
20
21
|
"react-is": "^18.2.0"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
@@ -25,14 +26,14 @@
|
|
|
25
26
|
"typescript": "5.3.3"
|
|
26
27
|
},
|
|
27
28
|
"peerDependencies": {
|
|
28
|
-
"@graphcommerce/eslint-config-pwa": "^8.1.0-canary.
|
|
29
|
-
"@graphcommerce/framer-next-pages": "^8.1.0-canary.
|
|
30
|
-
"@graphcommerce/framer-scroller": "^8.1.0-canary.
|
|
31
|
-
"@graphcommerce/framer-utils": "^8.1.0-canary.
|
|
32
|
-
"@graphcommerce/image": "^8.1.0-canary.
|
|
33
|
-
"@graphcommerce/lingui-next": "^8.1.0-canary.
|
|
34
|
-
"@graphcommerce/prettier-config-pwa": "^8.1.0-canary.
|
|
35
|
-
"@graphcommerce/typescript-config-pwa": "^8.1.0-canary.
|
|
29
|
+
"@graphcommerce/eslint-config-pwa": "^8.1.0-canary.9",
|
|
30
|
+
"@graphcommerce/framer-next-pages": "^8.1.0-canary.9",
|
|
31
|
+
"@graphcommerce/framer-scroller": "^8.1.0-canary.9",
|
|
32
|
+
"@graphcommerce/framer-utils": "^8.1.0-canary.9",
|
|
33
|
+
"@graphcommerce/image": "^8.1.0-canary.9",
|
|
34
|
+
"@graphcommerce/lingui-next": "^8.1.0-canary.9",
|
|
35
|
+
"@graphcommerce/prettier-config-pwa": "^8.1.0-canary.9",
|
|
36
|
+
"@graphcommerce/typescript-config-pwa": "^8.1.0-canary.9",
|
|
36
37
|
"@lingui/core": "^4.2.1",
|
|
37
38
|
"@lingui/macro": "^4.2.1",
|
|
38
39
|
"@lingui/react": "^4.2.1",
|
package/utils/robots.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { GetServerSidePropsContext } from 'next'
|
|
2
|
+
|
|
3
|
+
type Stringifyable = boolean | string | number | null | undefined
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Tagged template literal for robots.txt that will automatically stringify values and indent them correctly.
|
|
7
|
+
* https://developers.google.com/search/docs/crawling-indexing/robots/robots_txt#syntax
|
|
8
|
+
*/
|
|
9
|
+
export function robotsTxt(strings: TemplateStringsArray, ...values: Stringifyable[]) {
|
|
10
|
+
return strings
|
|
11
|
+
.reduce((acc, str, i) => {
|
|
12
|
+
let value = values[i]
|
|
13
|
+
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
const [conditional, val] = value
|
|
16
|
+
value = conditional ? val : null
|
|
17
|
+
}
|
|
18
|
+
if (!value) value = ''
|
|
19
|
+
if (typeof value === 'boolean') value = value ? 'true' : 'false'
|
|
20
|
+
if (typeof value === 'number') value = String(value)
|
|
21
|
+
|
|
22
|
+
return acc + str + value
|
|
23
|
+
}, '')
|
|
24
|
+
.split('\n')
|
|
25
|
+
.map((v) => v.trim())
|
|
26
|
+
.join('\n')
|
|
27
|
+
.trim()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
31
|
+
export async function getServerSidePropsRobotsTxt(
|
|
32
|
+
context: GetServerSidePropsContext,
|
|
33
|
+
robots: string,
|
|
34
|
+
) {
|
|
35
|
+
context.res.setHeader('Content-Type', 'text/plain')
|
|
36
|
+
context.res.write(robots)
|
|
37
|
+
context.res.end()
|
|
38
|
+
context.res.setHeader('Cache-Control', `public, s-maxage=${60 * 60 * 2}`)
|
|
39
|
+
|
|
40
|
+
return { props: {} }
|
|
41
|
+
}
|
package/utils/sitemap.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { GetServerSidePropsContext, GetStaticPathsResult } from 'next'
|
|
2
|
+
import { getServerSideSitemapLegacy, ISitemapField } from 'next-sitemap'
|
|
3
|
+
import { canonicalize } from '../PageMeta/PageMeta'
|
|
4
|
+
|
|
5
|
+
export function excludeSitemap(excludes: string[]) {
|
|
6
|
+
const regexp = excludes.map((exclude) => new RegExp(exclude.replace(/\*/g, '.*?')))
|
|
7
|
+
|
|
8
|
+
return (path: string) => !regexp.some((pattern) => pattern.test(`/${path}`))
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function staticPathsToString(
|
|
12
|
+
path: GetStaticPathsResult<{ url: string[] | string }>['paths'][0],
|
|
13
|
+
) {
|
|
14
|
+
if (typeof path === 'string') return path
|
|
15
|
+
if (typeof path.params.url === 'string') return path.params.url
|
|
16
|
+
return path.params.url.join('/')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function toSitemapFields(
|
|
20
|
+
context: GetServerSidePropsContext,
|
|
21
|
+
paths: string[],
|
|
22
|
+
): ISitemapField[] {
|
|
23
|
+
const lastmod = new Date().toISOString()
|
|
24
|
+
const options = {
|
|
25
|
+
locale: context.locale,
|
|
26
|
+
defaultLocale: context.defaultLocale,
|
|
27
|
+
pathname: '/',
|
|
28
|
+
isLocaleDomain: false,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const sitemapPaths = paths.map<ISitemapField>((path) => ({
|
|
32
|
+
loc: canonicalize(options, `/${path}`) ?? '',
|
|
33
|
+
lastmod,
|
|
34
|
+
changefreq: 'daily',
|
|
35
|
+
priority: 0.7,
|
|
36
|
+
}))
|
|
37
|
+
|
|
38
|
+
return sitemapPaths
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function getServerSidePropsSitemap(
|
|
42
|
+
context: GetServerSidePropsContext,
|
|
43
|
+
paths: ISitemapField[],
|
|
44
|
+
) {
|
|
45
|
+
context.res.setHeader('Cache-Control', `public, s-maxage=${60 * 60 * 2}`)
|
|
46
|
+
return getServerSideSitemapLegacy(context, paths)
|
|
47
|
+
}
|