@yimingliao/cms 0.0.219 → 0.0.221
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/dist/src/shared/seo-metadata/build-article-metadata.js +35 -27
- package/dist/src/shared/seo-metadata/build-website-metadata.js +28 -23
- package/dist/src/shared/seo-metadata/utils/to-iso-time.js +4 -2
- package/dist/src/shared/seo-metadata/utils/to-og-locale.js +6 -0
- package/dist/types/src/shared/seo-metadata/build-article-metadata.d.ts +2 -1
- package/dist/types/src/shared/seo-metadata/build-article-metadata.d.ts.map +1 -1
- package/dist/types/src/shared/seo-metadata/build-website-metadata.d.ts +2 -1
- package/dist/types/src/shared/seo-metadata/build-website-metadata.d.ts.map +1 -1
- package/dist/types/src/shared/seo-metadata/utils/sanitize-string-array.d.ts +1 -1
- package/dist/types/src/shared/seo-metadata/utils/sanitize-string-array.d.ts.map +1 -1
- package/dist/types/src/shared/seo-metadata/utils/to-iso-time.d.ts +1 -1
- package/dist/types/src/shared/seo-metadata/utils/to-iso-time.d.ts.map +1 -1
- package/dist/types/src/shared/seo-metadata/utils/to-og-locale.d.ts +2 -0
- package/dist/types/src/shared/seo-metadata/utils/to-og-locale.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -5,77 +5,85 @@ import { ensureOgType } from './utils/ensure-og-type.js';
|
|
|
5
5
|
import { ensureTwitterCard } from './utils/ensure-twitter-card.js';
|
|
6
6
|
import { sanitizeStringArray } from './utils/sanitize-string-array.js';
|
|
7
7
|
import { toIsoTime } from './utils/to-iso-time.js';
|
|
8
|
+
import { toOgLocale } from './utils/to-og-locale.js';
|
|
8
9
|
|
|
9
10
|
function createBuildArticleMetadata({
|
|
10
11
|
getDefaults,
|
|
11
12
|
defaultLocale,
|
|
13
|
+
locales,
|
|
12
14
|
storageUrl
|
|
13
15
|
}) {
|
|
14
16
|
return function buildArticleMetadata(post, locale) {
|
|
15
|
-
const
|
|
17
|
+
const resolvedLocale = locale ?? defaultLocale;
|
|
18
|
+
const defaults = getDefaults(resolvedLocale);
|
|
16
19
|
const seoMetadata = findTranslation(post?.seoMetadatas, locale);
|
|
17
20
|
const authorT = findTranslation(post?.author?.translations, locale);
|
|
18
21
|
const coverImageT = findTranslation(post?.coverImage?.translations, locale);
|
|
22
|
+
const tags = sanitizeStringArray(
|
|
23
|
+
post?.tags.map((t) => findTranslation(t.translations, locale).title)
|
|
24
|
+
);
|
|
19
25
|
return {
|
|
20
26
|
metadataBase: defaults.metadataBase,
|
|
21
27
|
// -----------------------------------------------------------------------
|
|
22
28
|
// Basic
|
|
23
29
|
// -----------------------------------------------------------------------
|
|
24
|
-
title: seoMetadata
|
|
25
|
-
description: seoMetadata
|
|
30
|
+
title: seoMetadata.title || defaults.title,
|
|
31
|
+
description: seoMetadata.description,
|
|
26
32
|
// identity
|
|
27
33
|
authors: [
|
|
28
34
|
{
|
|
29
|
-
name: seoMetadata
|
|
35
|
+
name: seoMetadata.author || authorT.authorName || defaults.author,
|
|
30
36
|
url: authorT.url || void 0
|
|
31
37
|
}
|
|
32
38
|
],
|
|
33
39
|
// url
|
|
34
40
|
alternates: {
|
|
35
|
-
canonical: seoMetadata
|
|
36
|
-
languages: buildAlternateMap(seoMetadata
|
|
41
|
+
canonical: seoMetadata.canonical,
|
|
42
|
+
languages: buildAlternateMap(seoMetadata.alternate)
|
|
37
43
|
},
|
|
38
44
|
// robots
|
|
39
|
-
robots: seoMetadata
|
|
45
|
+
robots: seoMetadata.robots || defaults.robots,
|
|
40
46
|
// -----------------------------------------------------------------------
|
|
41
47
|
// Open Graph
|
|
42
48
|
// -----------------------------------------------------------------------
|
|
43
49
|
openGraph: {
|
|
44
|
-
title: seoMetadata
|
|
45
|
-
description: seoMetadata
|
|
50
|
+
title: seoMetadata.ogTitle || void 0,
|
|
51
|
+
description: seoMetadata.ogDescription || void 0,
|
|
46
52
|
// url
|
|
47
|
-
url: seoMetadata
|
|
53
|
+
url: seoMetadata.ogUrl || seoMetadata.canonical || void 0,
|
|
48
54
|
// identity
|
|
49
|
-
type: ensureOgType("article", seoMetadata
|
|
50
|
-
siteName: seoMetadata
|
|
55
|
+
type: ensureOgType("article", seoMetadata.ogType),
|
|
56
|
+
siteName: seoMetadata.ogSiteName || defaults.ogSiteName,
|
|
51
57
|
// image
|
|
52
58
|
images: buildOgImages(
|
|
53
|
-
seoMetadata
|
|
54
|
-
seoMetadata
|
|
55
|
-
seoMetadata
|
|
56
|
-
seoMetadata
|
|
57
|
-
seoMetadata
|
|
59
|
+
seoMetadata.ogImage || `${storageUrl}/${post?.coverImage?.key}`,
|
|
60
|
+
seoMetadata.ogImageAlt || coverImageT.alt,
|
|
61
|
+
seoMetadata.ogImageType,
|
|
62
|
+
seoMetadata.ogImageWidth,
|
|
63
|
+
seoMetadata.ogImageHeight
|
|
58
64
|
),
|
|
59
65
|
// locale
|
|
60
|
-
locale: seoMetadata
|
|
61
|
-
alternateLocale: sanitizeStringArray(
|
|
66
|
+
locale: seoMetadata.ogLocale ?? toOgLocale(resolvedLocale),
|
|
67
|
+
alternateLocale: sanitizeStringArray(
|
|
68
|
+
seoMetadata.ogLocaleAlternate ?? locales.filter((l) => l !== resolvedLocale).map(toOgLocale)
|
|
69
|
+
),
|
|
62
70
|
// article
|
|
63
|
-
publishedTime: toIsoTime(seoMetadata
|
|
64
|
-
modifiedTime: toIsoTime(seoMetadata
|
|
71
|
+
publishedTime: toIsoTime(seoMetadata.ogArticlePublishedTime),
|
|
72
|
+
modifiedTime: toIsoTime(seoMetadata.ogArticleModifiedTime),
|
|
65
73
|
authors: [
|
|
66
|
-
seoMetadata
|
|
74
|
+
seoMetadata.ogArticleAuthor || authorT.authorName || defaults.ogSiteName
|
|
67
75
|
],
|
|
68
|
-
section: seoMetadata
|
|
69
|
-
tags: sanitizeStringArray(seoMetadata
|
|
76
|
+
section: seoMetadata.ogArticleSection,
|
|
77
|
+
tags: sanitizeStringArray(seoMetadata.ogArticleTag) ?? tags
|
|
70
78
|
},
|
|
71
79
|
// -----------------------------------------------------------------------
|
|
72
80
|
// Twitter
|
|
73
81
|
// -----------------------------------------------------------------------
|
|
74
82
|
twitter: {
|
|
75
|
-
card: ensureTwitterCard(defaults.twitterCard, seoMetadata
|
|
83
|
+
card: ensureTwitterCard(defaults.twitterCard, seoMetadata.twitterCard),
|
|
76
84
|
// identity
|
|
77
|
-
site: seoMetadata
|
|
78
|
-
creator: seoMetadata
|
|
85
|
+
site: seoMetadata.twitterSite || void 0,
|
|
86
|
+
creator: seoMetadata.twitterCreator || void 0
|
|
79
87
|
}
|
|
80
88
|
};
|
|
81
89
|
};
|
|
@@ -4,61 +4,66 @@ import { buildOgImages } from './utils/build-og-image.js';
|
|
|
4
4
|
import { ensureOgType } from './utils/ensure-og-type.js';
|
|
5
5
|
import { ensureTwitterCard } from './utils/ensure-twitter-card.js';
|
|
6
6
|
import { sanitizeStringArray } from './utils/sanitize-string-array.js';
|
|
7
|
+
import { toOgLocale } from './utils/to-og-locale.js';
|
|
7
8
|
|
|
8
9
|
function createBuildWebsiteMetadata({
|
|
9
10
|
getDefaults,
|
|
10
|
-
defaultLocale
|
|
11
|
+
defaultLocale,
|
|
12
|
+
locales
|
|
11
13
|
}) {
|
|
12
14
|
return function buildWebsiteMetadata(post, locale) {
|
|
13
|
-
const
|
|
15
|
+
const resolvedLocale = locale ?? defaultLocale;
|
|
16
|
+
const defaults = getDefaults(resolvedLocale);
|
|
14
17
|
const seoMetadata = findTranslation(post?.seoMetadatas, locale);
|
|
15
18
|
return {
|
|
16
19
|
metadataBase: defaults.metadataBase,
|
|
17
20
|
// -----------------------------------------------------------------------
|
|
18
21
|
// Basic
|
|
19
22
|
// -----------------------------------------------------------------------
|
|
20
|
-
title: seoMetadata
|
|
21
|
-
description: seoMetadata
|
|
23
|
+
title: seoMetadata.title || defaults.title,
|
|
24
|
+
description: seoMetadata.description,
|
|
22
25
|
// identity
|
|
23
|
-
authors: [{ name: seoMetadata
|
|
26
|
+
authors: [{ name: seoMetadata.author || defaults.author }],
|
|
24
27
|
// url
|
|
25
28
|
alternates: {
|
|
26
|
-
canonical: seoMetadata
|
|
27
|
-
languages: buildAlternateMap(seoMetadata
|
|
29
|
+
canonical: seoMetadata.canonical,
|
|
30
|
+
languages: buildAlternateMap(seoMetadata.alternate)
|
|
28
31
|
},
|
|
29
32
|
// robots
|
|
30
|
-
robots: seoMetadata
|
|
33
|
+
robots: seoMetadata.robots || defaults.robots,
|
|
31
34
|
// -----------------------------------------------------------------------
|
|
32
35
|
// Open Graph
|
|
33
36
|
// -----------------------------------------------------------------------
|
|
34
37
|
openGraph: {
|
|
35
|
-
title: seoMetadata
|
|
36
|
-
description: seoMetadata
|
|
38
|
+
title: seoMetadata.ogTitle || void 0,
|
|
39
|
+
description: seoMetadata.ogDescription || void 0,
|
|
37
40
|
// url
|
|
38
|
-
url: seoMetadata
|
|
41
|
+
url: seoMetadata.ogUrl || seoMetadata.canonical || void 0,
|
|
39
42
|
// identity
|
|
40
|
-
type: ensureOgType("website", seoMetadata
|
|
41
|
-
siteName: seoMetadata
|
|
43
|
+
type: ensureOgType("website", seoMetadata.ogType),
|
|
44
|
+
siteName: seoMetadata.ogSiteName || defaults.ogSiteName,
|
|
42
45
|
// image
|
|
43
46
|
images: buildOgImages(
|
|
44
|
-
seoMetadata
|
|
45
|
-
seoMetadata
|
|
46
|
-
seoMetadata
|
|
47
|
-
seoMetadata
|
|
48
|
-
seoMetadata
|
|
47
|
+
seoMetadata.ogImage,
|
|
48
|
+
seoMetadata.ogImageAlt,
|
|
49
|
+
seoMetadata.ogImageType,
|
|
50
|
+
seoMetadata.ogImageWidth,
|
|
51
|
+
seoMetadata.ogImageHeight
|
|
49
52
|
),
|
|
50
53
|
// locale
|
|
51
|
-
locale: seoMetadata
|
|
52
|
-
alternateLocale: sanitizeStringArray(
|
|
54
|
+
locale: seoMetadata.ogLocale ?? toOgLocale(resolvedLocale),
|
|
55
|
+
alternateLocale: sanitizeStringArray(
|
|
56
|
+
seoMetadata.ogLocaleAlternate ?? locales.filter((l) => l !== resolvedLocale).map(toOgLocale)
|
|
57
|
+
)
|
|
53
58
|
},
|
|
54
59
|
// -----------------------------------------------------------------------
|
|
55
60
|
// Twitter
|
|
56
61
|
// -----------------------------------------------------------------------
|
|
57
62
|
twitter: {
|
|
58
|
-
card: ensureTwitterCard(defaults.twitterCard, seoMetadata
|
|
63
|
+
card: ensureTwitterCard(defaults.twitterCard, seoMetadata.twitterCard),
|
|
59
64
|
// identity
|
|
60
|
-
site: seoMetadata
|
|
61
|
-
creator: seoMetadata
|
|
65
|
+
site: seoMetadata.twitterSite || void 0,
|
|
66
|
+
creator: seoMetadata.twitterCreator || void 0
|
|
62
67
|
}
|
|
63
68
|
};
|
|
64
69
|
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
const toIsoTime = (
|
|
2
|
-
if (
|
|
1
|
+
const toIsoTime = (input) => {
|
|
2
|
+
if (input == null) return void 0;
|
|
3
|
+
const date = typeof input === "string" ? new Date(input) : input;
|
|
4
|
+
if (isNaN(date.getTime())) return void 0;
|
|
3
5
|
return date.toISOString();
|
|
4
6
|
};
|
|
5
7
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { SeoMetadataDefaults } from "./types";
|
|
2
2
|
import type { PostFull } from "../../domain/resources/post/full";
|
|
3
3
|
import type { Metadata } from "next";
|
|
4
|
-
export declare function createBuildArticleMetadata({ getDefaults, defaultLocale, storageUrl, }: {
|
|
4
|
+
export declare function createBuildArticleMetadata({ getDefaults, defaultLocale, locales, storageUrl, }: {
|
|
5
5
|
getDefaults: (locale: string) => SeoMetadataDefaults;
|
|
6
6
|
defaultLocale: string;
|
|
7
|
+
locales: string[];
|
|
7
8
|
storageUrl: string;
|
|
8
9
|
}): (post?: PostFull, locale?: string) => Metadata;
|
|
9
10
|
//# sourceMappingURL=build-article-metadata.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-article-metadata.d.ts","sourceRoot":"","sources":["../../../../../src/shared/seo-metadata/build-article-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"build-article-metadata.d.ts","sourceRoot":"","sources":["../../../../../src/shared/seo-metadata/build-article-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAUrC,wBAAgB,0BAA0B,CAAC,EACzC,WAAW,EACX,aAAa,EACb,OAAO,EACP,UAAU,GACX,EAAE;IACD,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,mBAAmB,CAAC;IACrD,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,IAEG,OAAO,QAAQ,EACf,SAAS,MAAM,KACd,QAAQ,CA0FZ"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { SeoMetadataDefaults } from "./types";
|
|
2
2
|
import type { PostFull } from "../../domain/resources/post/full";
|
|
3
3
|
import type { Metadata } from "next";
|
|
4
|
-
export declare function createBuildWebsiteMetadata({ getDefaults, defaultLocale, }: {
|
|
4
|
+
export declare function createBuildWebsiteMetadata({ getDefaults, defaultLocale, locales, }: {
|
|
5
5
|
getDefaults: (locale: string) => SeoMetadataDefaults;
|
|
6
6
|
defaultLocale: string;
|
|
7
|
+
locales: string[];
|
|
7
8
|
}): (post?: PostFull, locale?: string) => Metadata;
|
|
8
9
|
//# sourceMappingURL=build-website-metadata.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-website-metadata.d.ts","sourceRoot":"","sources":["../../../../../src/shared/seo-metadata/build-website-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"build-website-metadata.d.ts","sourceRoot":"","sources":["../../../../../src/shared/seo-metadata/build-website-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AASrC,wBAAgB,0BAA0B,CAAC,EACzC,WAAW,EACX,aAAa,EACb,OAAO,GACR,EAAE;IACD,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,mBAAmB,CAAC;IACrD,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,IAEG,OAAO,QAAQ,EACf,SAAS,MAAM,KACd,QAAQ,CAqEZ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const sanitizeStringArray: (array?: string[]) => string[] | undefined;
|
|
1
|
+
export declare const sanitizeStringArray: (array?: (string | undefined | null)[]) => string[] | undefined;
|
|
2
2
|
//# sourceMappingURL=sanitize-string-array.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitize-string-array.d.ts","sourceRoot":"","sources":["../../../../../../src/shared/seo-metadata/utils/sanitize-string-array.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"sanitize-string-array.d.ts","sourceRoot":"","sources":["../../../../../../src/shared/seo-metadata/utils/sanitize-string-array.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,GAC9B,QAAQ,CAAC,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC,EAAE,KACpC,MAAM,EAAE,GAAG,SAMb,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const toIsoTime: (
|
|
1
|
+
export declare const toIsoTime: (input?: Date | string | null) => string | undefined;
|
|
2
2
|
//# sourceMappingURL=to-iso-time.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-iso-time.d.ts","sourceRoot":"","sources":["../../../../../../src/shared/seo-metadata/utils/to-iso-time.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,GAAI,
|
|
1
|
+
{"version":3,"file":"to-iso-time.d.ts","sourceRoot":"","sources":["../../../../../../src/shared/seo-metadata/utils/to-iso-time.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,GAAI,QAAQ,IAAI,GAAG,MAAM,GAAG,IAAI,KAAG,MAAM,GAAG,SAQjE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-og-locale.d.ts","sourceRoot":"","sources":["../../../../../../src/shared/seo-metadata/utils/to-og-locale.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG9D"}
|