@windrun-huaiin/third-ui 31.3.2 → 31.3.3
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/lib/seo-metadata.js +21 -7
- package/dist/lib/seo-metadata.mjs +21 -7
- package/package.json +1 -1
- package/src/lib/seo-metadata.ts +29 -9
package/dist/lib/seo-metadata.js
CHANGED
|
@@ -11,16 +11,22 @@ const DEFAULT_SITE_ICONS = [
|
|
|
11
11
|
{ rel: 'apple-touch-icon', sizes: '180x180', url: '/favicon-180x180.png' },
|
|
12
12
|
{ rel: 'android-chrome', sizes: '512x512', url: '/favicon-512x512.png' },
|
|
13
13
|
];
|
|
14
|
+
function joinBaseUrl(baseUrl, path) {
|
|
15
|
+
const normalizedBaseUrl = baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl;
|
|
16
|
+
if (path === '/') {
|
|
17
|
+
return `${normalizedBaseUrl}/`;
|
|
18
|
+
}
|
|
19
|
+
return `${normalizedBaseUrl}${path}`;
|
|
20
|
+
}
|
|
14
21
|
function buildAlternateUrls(options) {
|
|
15
22
|
const { baseUrl, defaultLocale, locale, localePrefixAsNeeded, locales, pathname } = options;
|
|
16
23
|
const canonicalPath = utils.getAsNeededLocalizedUrl(locale, pathname, localePrefixAsNeeded, defaultLocale);
|
|
17
|
-
const canonical = `${baseUrl}${canonicalPath}`;
|
|
18
24
|
const languages = Object.fromEntries(locales.map((siteLocale) => [
|
|
19
25
|
siteLocale,
|
|
20
|
-
|
|
26
|
+
joinBaseUrl(baseUrl, utils.getAsNeededLocalizedUrl(siteLocale, pathname, localePrefixAsNeeded, defaultLocale)),
|
|
21
27
|
]));
|
|
22
28
|
return {
|
|
23
|
-
canonical,
|
|
29
|
+
canonical: joinBaseUrl(baseUrl, canonicalPath),
|
|
24
30
|
languages,
|
|
25
31
|
};
|
|
26
32
|
}
|
|
@@ -52,6 +58,12 @@ function getEnvText(value) {
|
|
|
52
58
|
const trimmed = value === null || value === void 0 ? void 0 : value.trim();
|
|
53
59
|
return trimmed ? trimmed : undefined;
|
|
54
60
|
}
|
|
61
|
+
function omitUndefined(value) {
|
|
62
|
+
if (!value)
|
|
63
|
+
return undefined;
|
|
64
|
+
const entries = Object.entries(value).filter(([, item]) => item !== undefined);
|
|
65
|
+
return entries.length > 0 ? Object.fromEntries(entries) : undefined;
|
|
66
|
+
}
|
|
55
67
|
function resolveMetadataOverrides(options) {
|
|
56
68
|
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
57
69
|
var _a, _b, _c;
|
|
@@ -98,12 +110,14 @@ function createLocalizedSiteMetadata(options) {
|
|
|
98
110
|
function createLocalizedPageMetadata(options) {
|
|
99
111
|
var _a, _b, _c, _d;
|
|
100
112
|
const { page, site, url } = options;
|
|
101
|
-
const { baseUrl } = url;
|
|
102
113
|
const alternates = buildAlternateUrls(url);
|
|
103
|
-
const
|
|
104
|
-
const
|
|
114
|
+
const siteOpenGraph = omitUndefined(site === null || site === void 0 ? void 0 : site.openGraph);
|
|
115
|
+
const pageOpenGraph = omitUndefined(page === null || page === void 0 ? void 0 : page.openGraph);
|
|
116
|
+
const openGraph = Object.assign(Object.assign(Object.assign({}, siteOpenGraph), pageOpenGraph), { url: alternates.canonical });
|
|
117
|
+
const siteTwitter = omitUndefined(site === null || site === void 0 ? void 0 : site.twitter);
|
|
118
|
+
const pageTwitter = omitUndefined(page === null || page === void 0 ? void 0 : page.twitter);
|
|
119
|
+
const twitter = Object.assign(Object.assign({}, siteTwitter), pageTwitter);
|
|
105
120
|
return {
|
|
106
|
-
metadataBase: new URL(baseUrl),
|
|
107
121
|
title: (_a = page === null || page === void 0 ? void 0 : page.title) !== null && _a !== void 0 ? _a : site === null || site === void 0 ? void 0 : site.title,
|
|
108
122
|
description: (_b = page === null || page === void 0 ? void 0 : page.description) !== null && _b !== void 0 ? _b : site === null || site === void 0 ? void 0 : site.description,
|
|
109
123
|
keywords: (_c = page === null || page === void 0 ? void 0 : page.keywords) !== null && _c !== void 0 ? _c : site === null || site === void 0 ? void 0 : site.keywords,
|
|
@@ -9,16 +9,22 @@ const DEFAULT_SITE_ICONS = [
|
|
|
9
9
|
{ rel: 'apple-touch-icon', sizes: '180x180', url: '/favicon-180x180.png' },
|
|
10
10
|
{ rel: 'android-chrome', sizes: '512x512', url: '/favicon-512x512.png' },
|
|
11
11
|
];
|
|
12
|
+
function joinBaseUrl(baseUrl, path) {
|
|
13
|
+
const normalizedBaseUrl = baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl;
|
|
14
|
+
if (path === '/') {
|
|
15
|
+
return `${normalizedBaseUrl}/`;
|
|
16
|
+
}
|
|
17
|
+
return `${normalizedBaseUrl}${path}`;
|
|
18
|
+
}
|
|
12
19
|
function buildAlternateUrls(options) {
|
|
13
20
|
const { baseUrl, defaultLocale, locale, localePrefixAsNeeded, locales, pathname } = options;
|
|
14
21
|
const canonicalPath = getAsNeededLocalizedUrl(locale, pathname, localePrefixAsNeeded, defaultLocale);
|
|
15
|
-
const canonical = `${baseUrl}${canonicalPath}`;
|
|
16
22
|
const languages = Object.fromEntries(locales.map((siteLocale) => [
|
|
17
23
|
siteLocale,
|
|
18
|
-
|
|
24
|
+
joinBaseUrl(baseUrl, getAsNeededLocalizedUrl(siteLocale, pathname, localePrefixAsNeeded, defaultLocale)),
|
|
19
25
|
]));
|
|
20
26
|
return {
|
|
21
|
-
canonical,
|
|
27
|
+
canonical: joinBaseUrl(baseUrl, canonicalPath),
|
|
22
28
|
languages,
|
|
23
29
|
};
|
|
24
30
|
}
|
|
@@ -50,6 +56,12 @@ function getEnvText(value) {
|
|
|
50
56
|
const trimmed = value === null || value === void 0 ? void 0 : value.trim();
|
|
51
57
|
return trimmed ? trimmed : undefined;
|
|
52
58
|
}
|
|
59
|
+
function omitUndefined(value) {
|
|
60
|
+
if (!value)
|
|
61
|
+
return undefined;
|
|
62
|
+
const entries = Object.entries(value).filter(([, item]) => item !== undefined);
|
|
63
|
+
return entries.length > 0 ? Object.fromEntries(entries) : undefined;
|
|
64
|
+
}
|
|
53
65
|
function resolveMetadataOverrides(options) {
|
|
54
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55
67
|
var _a, _b, _c;
|
|
@@ -96,12 +108,14 @@ function createLocalizedSiteMetadata(options) {
|
|
|
96
108
|
function createLocalizedPageMetadata(options) {
|
|
97
109
|
var _a, _b, _c, _d;
|
|
98
110
|
const { page, site, url } = options;
|
|
99
|
-
const { baseUrl } = url;
|
|
100
111
|
const alternates = buildAlternateUrls(url);
|
|
101
|
-
const
|
|
102
|
-
const
|
|
112
|
+
const siteOpenGraph = omitUndefined(site === null || site === void 0 ? void 0 : site.openGraph);
|
|
113
|
+
const pageOpenGraph = omitUndefined(page === null || page === void 0 ? void 0 : page.openGraph);
|
|
114
|
+
const openGraph = Object.assign(Object.assign(Object.assign({}, siteOpenGraph), pageOpenGraph), { url: alternates.canonical });
|
|
115
|
+
const siteTwitter = omitUndefined(site === null || site === void 0 ? void 0 : site.twitter);
|
|
116
|
+
const pageTwitter = omitUndefined(page === null || page === void 0 ? void 0 : page.twitter);
|
|
117
|
+
const twitter = Object.assign(Object.assign({}, siteTwitter), pageTwitter);
|
|
103
118
|
return {
|
|
104
|
-
metadataBase: new URL(baseUrl),
|
|
105
119
|
title: (_a = page === null || page === void 0 ? void 0 : page.title) !== null && _a !== void 0 ? _a : site === null || site === void 0 ? void 0 : site.title,
|
|
106
120
|
description: (_b = page === null || page === void 0 ? void 0 : page.description) !== null && _b !== void 0 ? _b : site === null || site === void 0 ? void 0 : site.description,
|
|
107
121
|
keywords: (_c = page === null || page === void 0 ? void 0 : page.keywords) !== null && _c !== void 0 ? _c : site === null || site === void 0 ? void 0 : site.keywords,
|
package/package.json
CHANGED
package/src/lib/seo-metadata.ts
CHANGED
|
@@ -53,19 +53,30 @@ const DEFAULT_SITE_ICONS = [
|
|
|
53
53
|
{ rel: 'android-chrome', sizes: '512x512', url: '/favicon-512x512.png' },
|
|
54
54
|
];
|
|
55
55
|
|
|
56
|
+
function joinBaseUrl(baseUrl: string, path: string): string {
|
|
57
|
+
const normalizedBaseUrl = baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl;
|
|
58
|
+
if (path === '/') {
|
|
59
|
+
return `${normalizedBaseUrl}/`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return `${normalizedBaseUrl}${path}`;
|
|
63
|
+
}
|
|
64
|
+
|
|
56
65
|
function buildAlternateUrls(options: LocalizedPageUrlOptions) {
|
|
57
66
|
const { baseUrl, defaultLocale, locale, localePrefixAsNeeded, locales, pathname } = options;
|
|
58
67
|
const canonicalPath = getAsNeededLocalizedUrl(locale, pathname, localePrefixAsNeeded, defaultLocale);
|
|
59
|
-
const canonical = `${baseUrl}${canonicalPath}`;
|
|
60
68
|
const languages = Object.fromEntries(
|
|
61
69
|
locales.map((siteLocale) => [
|
|
62
70
|
siteLocale,
|
|
63
|
-
|
|
71
|
+
joinBaseUrl(
|
|
72
|
+
baseUrl,
|
|
73
|
+
getAsNeededLocalizedUrl(siteLocale, pathname, localePrefixAsNeeded, defaultLocale),
|
|
74
|
+
),
|
|
64
75
|
]),
|
|
65
76
|
);
|
|
66
77
|
|
|
67
78
|
return {
|
|
68
|
-
canonical,
|
|
79
|
+
canonical: joinBaseUrl(baseUrl, canonicalPath),
|
|
69
80
|
languages,
|
|
70
81
|
};
|
|
71
82
|
}
|
|
@@ -109,6 +120,13 @@ function getEnvText(value?: string): string | undefined {
|
|
|
109
120
|
return trimmed ? trimmed : undefined;
|
|
110
121
|
}
|
|
111
122
|
|
|
123
|
+
function omitUndefined<T extends Record<string, unknown>>(value: T | undefined): Partial<T> | undefined {
|
|
124
|
+
if (!value) return undefined;
|
|
125
|
+
|
|
126
|
+
const entries = Object.entries(value).filter(([, item]) => item !== undefined);
|
|
127
|
+
return entries.length > 0 ? Object.fromEntries(entries) as Partial<T> : undefined;
|
|
128
|
+
}
|
|
129
|
+
|
|
112
130
|
export async function resolveMetadataOverrides(options: {
|
|
113
131
|
locale: string;
|
|
114
132
|
namespace: string;
|
|
@@ -185,20 +203,22 @@ export function createLocalizedPageMetadata(
|
|
|
185
203
|
options: CreateLocalizedPageMetadataOptions,
|
|
186
204
|
): Metadata {
|
|
187
205
|
const { page, site, url } = options;
|
|
188
|
-
const { baseUrl } = url;
|
|
189
206
|
const alternates = buildAlternateUrls(url);
|
|
207
|
+
const siteOpenGraph = omitUndefined(site?.openGraph as Record<string, unknown> | undefined);
|
|
208
|
+
const pageOpenGraph = omitUndefined(page?.openGraph as Record<string, unknown> | undefined);
|
|
190
209
|
const openGraph = {
|
|
191
|
-
...
|
|
192
|
-
...
|
|
210
|
+
...siteOpenGraph,
|
|
211
|
+
...pageOpenGraph,
|
|
193
212
|
url: alternates.canonical,
|
|
194
213
|
} as Metadata['openGraph'];
|
|
214
|
+
const siteTwitter = omitUndefined(site?.twitter as Record<string, unknown> | undefined);
|
|
215
|
+
const pageTwitter = omitUndefined(page?.twitter as Record<string, unknown> | undefined);
|
|
195
216
|
const twitter = {
|
|
196
|
-
...
|
|
197
|
-
...
|
|
217
|
+
...siteTwitter,
|
|
218
|
+
...pageTwitter,
|
|
198
219
|
} as Metadata['twitter'];
|
|
199
220
|
|
|
200
221
|
return {
|
|
201
|
-
metadataBase: new URL(baseUrl),
|
|
202
222
|
title: page?.title ?? site?.title,
|
|
203
223
|
description: page?.description ?? site?.description,
|
|
204
224
|
keywords: page?.keywords ?? site?.keywords,
|