@trebired/frontend 6.11.5 → 6.12.0
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 +7 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +1 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/product-shell.d.ts +1 -0
- package/dist/react/product-shell.d.ts.map +1 -1
- package/dist/react/product-shell.js +25 -3
- package/dist/react/product-shell.js.map +1 -1
- package/dist/react/seo.d.ts +8 -0
- package/dist/react/seo.d.ts.map +1 -0
- package/dist/react/seo.js +62 -0
- package/dist/react/seo.js.map +1 -0
- package/dist/server/framework.d.ts +18 -0
- package/dist/server/framework.d.ts.map +1 -0
- package/dist/server/framework.js +17 -0
- package/dist/server/framework.js.map +1 -0
- package/dist/server/index.d.ts +7 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +7 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/render/mode-toolkit.d.ts +50 -0
- package/dist/server/render/mode-toolkit.d.ts.map +1 -0
- package/dist/server/render/mode-toolkit.js +42 -0
- package/dist/server/render/mode-toolkit.js.map +1 -0
- package/dist/server/{render-mode.d.ts → render/mode.d.ts} +2 -2
- package/dist/server/render/mode.d.ts.map +1 -0
- package/dist/{src/server/render-mode.js → server/render/mode.js} +2 -2
- package/dist/server/render/mode.js.map +1 -0
- package/dist/server/seo/robots.d.ts +8 -0
- package/dist/server/seo/robots.d.ts.map +1 -0
- package/dist/server/seo/robots.js +56 -0
- package/dist/server/seo/robots.js.map +1 -0
- package/dist/server/seo/routes.d.ts +34 -0
- package/dist/server/seo/routes.d.ts.map +1 -0
- package/dist/server/seo/routes.js +86 -0
- package/dist/server/seo/routes.js.map +1 -0
- package/dist/server/seo/text.d.ts +3 -0
- package/dist/server/seo/text.d.ts.map +1 -0
- package/dist/server/seo/text.js +11 -0
- package/dist/server/seo/text.js.map +1 -0
- package/dist/server/seo/types.d.ts +103 -0
- package/dist/server/seo/types.d.ts.map +1 -0
- package/dist/server/seo/types.js +2 -0
- package/dist/server/seo/types.js.map +1 -0
- package/dist/server/seo.d.ts +10 -98
- package/dist/server/seo.d.ts.map +1 -1
- package/dist/server/seo.js +133 -85
- package/dist/server/seo.js.map +1 -1
- package/dist/server/services.d.ts +9 -3
- package/dist/server/services.d.ts.map +1 -1
- package/dist/server/services.js +13 -4
- package/dist/server/services.js.map +1 -1
- package/dist/server/sidebar-live.d.ts +45 -0
- package/dist/server/sidebar-live.d.ts.map +1 -0
- package/dist/server/sidebar-live.js +93 -0
- package/dist/server/sidebar-live.js.map +1 -0
- package/dist/src/react/index.d.ts +1 -0
- package/dist/src/react/index.d.ts.map +1 -1
- package/dist/src/react/index.js +1 -0
- package/dist/src/react/index.js.map +1 -1
- package/dist/src/react/product-shell.d.ts +1 -0
- package/dist/src/react/product-shell.d.ts.map +1 -1
- package/dist/src/react/product-shell.js +25 -3
- package/dist/src/react/product-shell.js.map +1 -1
- package/dist/src/react/seo.d.ts +8 -0
- package/dist/src/react/seo.d.ts.map +1 -0
- package/dist/src/react/seo.js +62 -0
- package/dist/src/react/seo.js.map +1 -0
- package/dist/src/server/framework.d.ts +18 -0
- package/dist/src/server/framework.d.ts.map +1 -0
- package/dist/src/server/framework.js +17 -0
- package/dist/src/server/framework.js.map +1 -0
- package/dist/src/server/index.d.ts +7 -1
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +7 -1
- package/dist/src/server/index.js.map +1 -1
- package/dist/src/server/render/mode-toolkit.d.ts +50 -0
- package/dist/src/server/render/mode-toolkit.d.ts.map +1 -0
- package/dist/src/server/render/mode-toolkit.js +42 -0
- package/dist/src/server/render/mode-toolkit.js.map +1 -0
- package/dist/src/server/{render-mode.d.ts → render/mode.d.ts} +2 -2
- package/dist/src/server/render/mode.d.ts.map +1 -0
- package/dist/{server/render-mode.js → src/server/render/mode.js} +2 -2
- package/dist/src/server/render/mode.js.map +1 -0
- package/dist/src/server/seo/robots.d.ts +8 -0
- package/dist/src/server/seo/robots.d.ts.map +1 -0
- package/dist/src/server/seo/robots.js +56 -0
- package/dist/src/server/seo/robots.js.map +1 -0
- package/dist/src/server/seo/routes.d.ts +34 -0
- package/dist/src/server/seo/routes.d.ts.map +1 -0
- package/dist/src/server/seo/routes.js +86 -0
- package/dist/src/server/seo/routes.js.map +1 -0
- package/dist/src/server/seo/text.d.ts +3 -0
- package/dist/src/server/seo/text.d.ts.map +1 -0
- package/dist/src/server/seo/text.js +11 -0
- package/dist/src/server/seo/text.js.map +1 -0
- package/dist/src/server/seo/types.d.ts +103 -0
- package/dist/src/server/seo/types.d.ts.map +1 -0
- package/dist/src/server/seo/types.js +2 -0
- package/dist/src/server/seo/types.js.map +1 -0
- package/dist/src/server/seo.d.ts +10 -98
- package/dist/src/server/seo.d.ts.map +1 -1
- package/dist/src/server/seo.js +133 -85
- package/dist/src/server/seo.js.map +1 -1
- package/dist/src/server/services.d.ts +9 -3
- package/dist/src/server/services.d.ts.map +1 -1
- package/dist/src/server/services.js +13 -4
- package/dist/src/server/services.js.map +1 -1
- package/dist/src/server/sidebar-live.d.ts +45 -0
- package/dist/src/server/sidebar-live.d.ts.map +1 -0
- package/dist/src/server/sidebar-live.js +93 -0
- package/dist/src/server/sidebar-live.js.map +1 -0
- package/package.json +1 -1
- package/dist/server/render-mode.d.ts.map +0 -1
- package/dist/server/render-mode.js.map +0 -1
- package/dist/src/server/render-mode.d.ts.map +0 -1
- package/dist/src/server/render-mode.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../../../src/server/seo/routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACxB,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,KAAK,mBAAmB,GA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,iBAAiB,EACtB,KAAK,kBAAkB,sBAQ1B;AAED,iBAAS,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,GAAE,eAAoB,QAanE;AAED,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,uBAAuB,EACvB,gBAAgB,EAChB,iBAAiB,GAClB,CAAC;AACF,YAAY,EACV,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,aAAa,GACd,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { sendText, } from "../../../server/http.js";
|
|
2
|
+
import { firstSeoText } from "./text.js";
|
|
3
|
+
function textArray(value) {
|
|
4
|
+
if (Array.isArray(value))
|
|
5
|
+
return value.map(firstSeoText).filter(Boolean);
|
|
6
|
+
const text = firstSeoText(value);
|
|
7
|
+
return text ? [text] : [];
|
|
8
|
+
}
|
|
9
|
+
function xmlEscape(value) {
|
|
10
|
+
return firstSeoText(value).replace(/[<>&'"]/gu, (char) => ({
|
|
11
|
+
"\"": """,
|
|
12
|
+
"&": "&",
|
|
13
|
+
"'": "'",
|
|
14
|
+
"<": "<",
|
|
15
|
+
">": ">",
|
|
16
|
+
}[char] || char));
|
|
17
|
+
}
|
|
18
|
+
function robotsTxtContent(options = {}) {
|
|
19
|
+
const lines = [`User-agent: ${firstSeoText(options.userAgent, "*")}`];
|
|
20
|
+
for (const item of options.allow || [])
|
|
21
|
+
lines.push(`Allow: ${item}`);
|
|
22
|
+
for (const item of options.disallow || [])
|
|
23
|
+
lines.push(`Disallow: ${item}`);
|
|
24
|
+
for (const item of textArray(options.sitemapUrl))
|
|
25
|
+
lines.push(`Sitemap: ${item}`);
|
|
26
|
+
for (const item of options.extraLines || [])
|
|
27
|
+
lines.push(item);
|
|
28
|
+
return `${lines.join("\n")}\n`;
|
|
29
|
+
}
|
|
30
|
+
function sitemapAlternateXml(item) {
|
|
31
|
+
if (!item.href || !item.hreflang)
|
|
32
|
+
return "";
|
|
33
|
+
return [
|
|
34
|
+
"<xhtml:link rel=\"alternate\"",
|
|
35
|
+
` hreflang="${xmlEscape(item.hreflang)}"`,
|
|
36
|
+
` href="${xmlEscape(item.href)}"/>`,
|
|
37
|
+
].join("");
|
|
38
|
+
}
|
|
39
|
+
function sitemapUrlXml(entry) {
|
|
40
|
+
const alternates = (entry.alternates || []).map(sitemapAlternateXml).join("");
|
|
41
|
+
const fields = [
|
|
42
|
+
`<loc>${xmlEscape(entry.loc)}</loc>`,
|
|
43
|
+
entry.lastmod ? `<lastmod>${xmlEscape(entry.lastmod)}</lastmod>` : "",
|
|
44
|
+
entry.changefreq ? `<changefreq>${xmlEscape(entry.changefreq)}</changefreq>` : "",
|
|
45
|
+
entry.priority != null
|
|
46
|
+
? `<priority>${Number(entry.priority).toFixed(1)}</priority>`
|
|
47
|
+
: "",
|
|
48
|
+
alternates,
|
|
49
|
+
].filter(Boolean).join("");
|
|
50
|
+
return `<url>${fields}</url>`;
|
|
51
|
+
}
|
|
52
|
+
async function sitemapXmlContent(req, options = {}) {
|
|
53
|
+
const source = typeof options.urls === "function" ? await options.urls(req) : options.urls || [];
|
|
54
|
+
const urls = Array.from(source).map(sitemapUrlXml).join("");
|
|
55
|
+
return [
|
|
56
|
+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
|
|
57
|
+
"<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"",
|
|
58
|
+
" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">",
|
|
59
|
+
urls,
|
|
60
|
+
"</urlset>",
|
|
61
|
+
].join("");
|
|
62
|
+
}
|
|
63
|
+
function createRobotsTxtHandler(options = {}) {
|
|
64
|
+
return function robotsTxtHandler(_req, res) {
|
|
65
|
+
return sendText(res, robotsTxtContent(options), "text/plain; charset=utf-8");
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function createSitemapXmlHandler(options = {}) {
|
|
69
|
+
return async function sitemapXmlHandler(req, res) {
|
|
70
|
+
return sendText(res, await sitemapXmlContent(req, options), "application/xml; charset=utf-8");
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function attachSeoRoutes(app, options = {}) {
|
|
74
|
+
if (!(app && typeof app.get === "function"))
|
|
75
|
+
return;
|
|
76
|
+
const get = app.get
|
|
77
|
+
.bind(app);
|
|
78
|
+
if (options.robots !== false && options.robots) {
|
|
79
|
+
get(options.robots.path || "/robots.txt", createRobotsTxtHandler(options.robots));
|
|
80
|
+
}
|
|
81
|
+
if (options.sitemap !== false && options.sitemap) {
|
|
82
|
+
get(options.sitemap.path || "/sitemap.xml", createSitemapXmlHandler(options.sitemap));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export { attachSeoRoutes, createRobotsTxtHandler, createSitemapXmlHandler, robotsTxtContent, sitemapXmlContent, };
|
|
86
|
+
//# sourceMappingURL=routes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../../../src/server/seo/routes.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,GAGT,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAmCzC,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACzE,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IACjC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC5B,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACvD,IAAI,EAAE,QAAQ;QACd,GAAG,EAAE,OAAO;QACZ,GAAG,EAAE,QAA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BAAS,YAAY,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,UAMzC;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { serverString } from "../../../server/http.js";
|
|
2
|
+
function firstSeoText(...values) {
|
|
3
|
+
for (const value of values) {
|
|
4
|
+
const text = serverString(value).trim();
|
|
5
|
+
if (text)
|
|
6
|
+
return text;
|
|
7
|
+
}
|
|
8
|
+
return "";
|
|
9
|
+
}
|
|
10
|
+
export { firstSeoText };
|
|
11
|
+
//# sourceMappingURL=text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../../../src/server/seo/text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,SAAS,YAAY,CAAC,GAAG,MAAiB;IACxC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;QACxC,IAAI,IAAI;YAAE,OAAO,IAAI,CAAC;IACxB,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { SeoRouteOptions } from "./routes.js";
|
|
2
|
+
type SeoRobotsConfig = {
|
|
3
|
+
archive?: boolean;
|
|
4
|
+
follow?: boolean;
|
|
5
|
+
imageIndex?: boolean;
|
|
6
|
+
imagePreview?: "none" | "standard" | "large";
|
|
7
|
+
index?: boolean;
|
|
8
|
+
maxImagePreview?: "none" | "standard" | "large";
|
|
9
|
+
maxSnippet?: number;
|
|
10
|
+
maxVideoPreview?: number;
|
|
11
|
+
nocache?: boolean;
|
|
12
|
+
snippet?: boolean;
|
|
13
|
+
translate?: boolean;
|
|
14
|
+
unavailableAfter?: string;
|
|
15
|
+
};
|
|
16
|
+
type SeoAlternateLink = {
|
|
17
|
+
href: string;
|
|
18
|
+
hreflang?: string;
|
|
19
|
+
media?: string;
|
|
20
|
+
title?: string;
|
|
21
|
+
type?: string;
|
|
22
|
+
};
|
|
23
|
+
type SeoImage = string | {
|
|
24
|
+
alt?: string;
|
|
25
|
+
height?: number;
|
|
26
|
+
type?: string;
|
|
27
|
+
url?: string;
|
|
28
|
+
width?: number;
|
|
29
|
+
};
|
|
30
|
+
type SeoSocialConfig = {
|
|
31
|
+
card?: string;
|
|
32
|
+
creator?: string;
|
|
33
|
+
description?: string;
|
|
34
|
+
image?: SeoImage | readonly SeoImage[];
|
|
35
|
+
imageAlt?: string;
|
|
36
|
+
locale?: string;
|
|
37
|
+
site?: string;
|
|
38
|
+
siteName?: string;
|
|
39
|
+
title?: string;
|
|
40
|
+
type?: string;
|
|
41
|
+
url?: string;
|
|
42
|
+
};
|
|
43
|
+
type SeoVerificationConfig = {
|
|
44
|
+
bing?: string;
|
|
45
|
+
google?: string;
|
|
46
|
+
other?: Record<string, string>;
|
|
47
|
+
yandex?: string;
|
|
48
|
+
};
|
|
49
|
+
type SeoStructuredData = Record<string, unknown> | readonly unknown[] | string;
|
|
50
|
+
type SeoConfig = {
|
|
51
|
+
alternates?: readonly SeoAlternateLink[];
|
|
52
|
+
applicationName?: string;
|
|
53
|
+
bingbot?: SeoRobotsConfig | readonly string[] | string;
|
|
54
|
+
bingbotContent?: string;
|
|
55
|
+
canonicalUrl?: string;
|
|
56
|
+
colorScheme?: string;
|
|
57
|
+
contentLanguage?: string;
|
|
58
|
+
googlebot?: SeoRobotsConfig | readonly string[] | string;
|
|
59
|
+
googlebotContent?: string;
|
|
60
|
+
htmlLang?: string;
|
|
61
|
+
index?: boolean;
|
|
62
|
+
jsonLd?: SeoStructuredData | readonly SeoStructuredData[];
|
|
63
|
+
manifestHref?: string;
|
|
64
|
+
metaDescription?: string;
|
|
65
|
+
metaKeywords?: string;
|
|
66
|
+
ogDescription?: string;
|
|
67
|
+
ogImage?: string;
|
|
68
|
+
ogLocale?: string;
|
|
69
|
+
ogSiteName?: string;
|
|
70
|
+
ogTitle?: string;
|
|
71
|
+
ogType?: string;
|
|
72
|
+
ogUrl?: string;
|
|
73
|
+
openGraph?: SeoSocialConfig;
|
|
74
|
+
referrer?: string;
|
|
75
|
+
robots?: SeoRobotsConfig | readonly string[] | string;
|
|
76
|
+
robotsContent?: string;
|
|
77
|
+
siteName?: string;
|
|
78
|
+
structuredData?: SeoStructuredData | readonly SeoStructuredData[];
|
|
79
|
+
themeColor?: string;
|
|
80
|
+
title?: string;
|
|
81
|
+
titleSuffix?: string;
|
|
82
|
+
twitter?: SeoSocialConfig;
|
|
83
|
+
twitterCard?: string;
|
|
84
|
+
twitterCreator?: string;
|
|
85
|
+
twitterDescription?: string;
|
|
86
|
+
twitterImage?: string;
|
|
87
|
+
twitterSite?: string;
|
|
88
|
+
twitterTitle?: string;
|
|
89
|
+
verification?: SeoVerificationConfig;
|
|
90
|
+
};
|
|
91
|
+
type SeoMiddlewareOptions = {
|
|
92
|
+
defaults?: SeoConfig;
|
|
93
|
+
getSeo?: () => SeoConfig;
|
|
94
|
+
routes?: false | SeoRouteOptions;
|
|
95
|
+
};
|
|
96
|
+
type SeoStoreOptions = {
|
|
97
|
+
defaults?: SeoConfig;
|
|
98
|
+
logger?: {
|
|
99
|
+
info?: (scope: string, message: string, metadata?: Record<string, unknown>) => unknown;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
export type { SeoAlternateLink, SeoConfig, SeoImage, SeoMiddlewareOptions, SeoRobotsConfig, SeoSocialConfig, SeoStoreOptions, SeoStructuredData, SeoVerificationConfig, };
|
|
103
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/server/seo/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC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,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC/B,OAAO,CAAC;KACd,CAAC;CACH,CAAC;AAEF,YAAY,EACV,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,qBAAqB,GACtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/server/seo/types.ts"],"names":[],"mappings":""}
|
package/dist/src/server/seo.d.ts
CHANGED
|
@@ -1,109 +1,21 @@
|
|
|
1
1
|
import { type ServerRequestLike, type ServerResponseLike } from "./http.js";
|
|
2
|
-
|
|
3
|
-
type SeoConfig
|
|
4
|
-
canonicalUrl?: string;
|
|
5
|
-
contentLanguage?: string;
|
|
6
|
-
googlebotContent?: string;
|
|
7
|
-
htmlLang?: string;
|
|
8
|
-
index?: boolean;
|
|
9
|
-
metaDescription?: string;
|
|
10
|
-
metaKeywords?: string;
|
|
11
|
-
ogDescription?: string;
|
|
12
|
-
ogImage?: string;
|
|
13
|
-
ogLocale?: string;
|
|
14
|
-
ogTitle?: string;
|
|
15
|
-
ogType?: string;
|
|
16
|
-
robotsContent?: string;
|
|
17
|
-
title?: string;
|
|
18
|
-
titleSuffix?: string;
|
|
19
|
-
twitterCard?: string;
|
|
20
|
-
twitterSite?: string;
|
|
21
|
-
};
|
|
22
|
-
type SeoMiddlewareOptions = {
|
|
23
|
-
defaults?: SeoConfig;
|
|
24
|
-
getSeo?: () => SeoConfig;
|
|
25
|
-
};
|
|
26
|
-
type SeoStoreOptions = {
|
|
27
|
-
defaults?: SeoConfig;
|
|
28
|
-
logger?: {
|
|
29
|
-
info?: (scope: string, message: string, metadata?: Record<string, unknown>) => unknown;
|
|
30
|
-
};
|
|
31
|
-
};
|
|
2
|
+
import { ROBOTS_NOINDEX_CONTENT, robotsContent } from "./seo/robots.js";
|
|
3
|
+
import type { SeoAlternateLink, SeoConfig, SeoMiddlewareOptions, SeoRobotsConfig, SeoSocialConfig, SeoStoreOptions, SeoStructuredData, SeoVerificationConfig } from "./seo/types.js";
|
|
32
4
|
declare const DEFAULT_SEO: SeoConfig;
|
|
33
|
-
declare function pickSeo(body?: SeoConfig, defaults?: SeoConfig):
|
|
34
|
-
titleSuffix: string;
|
|
35
|
-
metaDescription: string;
|
|
36
|
-
metaKeywords: string;
|
|
37
|
-
htmlLang: string;
|
|
38
|
-
contentLanguage: string;
|
|
39
|
-
ogLocale: string;
|
|
40
|
-
ogTitle: string;
|
|
41
|
-
ogDescription: string;
|
|
42
|
-
ogType: string;
|
|
43
|
-
ogImage: string;
|
|
44
|
-
twitterCard: string;
|
|
45
|
-
twitterSite: string;
|
|
46
|
-
index: boolean;
|
|
47
|
-
};
|
|
5
|
+
declare function pickSeo(body?: SeoConfig, defaults?: SeoConfig): SeoConfig;
|
|
48
6
|
declare function buildCanonical(req: ServerRequestLike): string;
|
|
49
7
|
declare function humanizeFromPath(path: unknown): string;
|
|
50
8
|
declare function getRobotsTagContent(config?: SeoConfig): string;
|
|
51
|
-
declare function buildSeoBase(req: ServerRequestLike, seo: SeoConfig):
|
|
52
|
-
|
|
53
|
-
titleSuffix: string;
|
|
54
|
-
canonicalUrl: string;
|
|
55
|
-
metaDescription: string;
|
|
56
|
-
metaKeywords: string;
|
|
57
|
-
htmlLang: string;
|
|
58
|
-
contentLanguage: string;
|
|
59
|
-
ogLocale: string;
|
|
60
|
-
ogTitle: string;
|
|
61
|
-
ogDescription: string;
|
|
62
|
-
ogType: string;
|
|
63
|
-
ogImage: string;
|
|
64
|
-
twitterCard: string;
|
|
65
|
-
twitterSite: string;
|
|
66
|
-
index: boolean;
|
|
67
|
-
robotsContent: string;
|
|
68
|
-
googlebotContent: string;
|
|
69
|
-
};
|
|
9
|
+
declare function buildSeoBase(req: ServerRequestLike, seo: SeoConfig): SeoConfig;
|
|
10
|
+
declare function applySeoHeaders(res: ServerResponseLike | null | undefined, seo: SeoConfig): void;
|
|
70
11
|
declare function applySeo(res: ServerResponseLike | null | undefined, overrides?: SeoConfig, options?: SeoMiddlewareOptions): void;
|
|
71
12
|
declare function createSeoStore(options?: SeoStoreOptions): {
|
|
72
|
-
getSeo():
|
|
73
|
-
|
|
74
|
-
googlebotContent: string;
|
|
75
|
-
titleSuffix: string;
|
|
76
|
-
metaDescription: string;
|
|
77
|
-
metaKeywords: string;
|
|
78
|
-
htmlLang: string;
|
|
79
|
-
contentLanguage: string;
|
|
80
|
-
ogLocale: string;
|
|
81
|
-
ogTitle: string;
|
|
82
|
-
ogDescription: string;
|
|
83
|
-
ogType: string;
|
|
84
|
-
ogImage: string;
|
|
85
|
-
twitterCard: string;
|
|
86
|
-
twitterSite: string;
|
|
87
|
-
index: boolean;
|
|
88
|
-
};
|
|
89
|
-
updateSeo(body?: SeoConfig): {
|
|
90
|
-
titleSuffix: string;
|
|
91
|
-
metaDescription: string;
|
|
92
|
-
metaKeywords: string;
|
|
93
|
-
htmlLang: string;
|
|
94
|
-
contentLanguage: string;
|
|
95
|
-
ogLocale: string;
|
|
96
|
-
ogTitle: string;
|
|
97
|
-
ogDescription: string;
|
|
98
|
-
ogType: string;
|
|
99
|
-
ogImage: string;
|
|
100
|
-
twitterCard: string;
|
|
101
|
-
twitterSite: string;
|
|
102
|
-
index: boolean;
|
|
103
|
-
};
|
|
13
|
+
getSeo(): SeoConfig;
|
|
14
|
+
updateSeo(body?: SeoConfig): SeoConfig;
|
|
104
15
|
};
|
|
105
16
|
declare function createSeoMiddleware(options?: SeoMiddlewareOptions): (req: ServerRequestLike, res: ServerResponseLike, next: () => unknown) => unknown;
|
|
106
17
|
declare function attachSeoMiddleware(app: unknown, options?: SeoMiddlewareOptions): void;
|
|
107
|
-
|
|
108
|
-
export
|
|
18
|
+
declare function createProductSeoDefaults(product?: Record<string, unknown>, options?: SeoConfig): SeoConfig;
|
|
19
|
+
export { DEFAULT_SEO, ROBOTS_NOINDEX_CONTENT, applySeo, applySeoHeaders, attachSeoMiddleware, buildCanonical, buildSeoBase, createProductSeoDefaults, createSeoMiddleware, createSeoStore, getRobotsTagContent, humanizeFromPath, pickSeo, robotsContent, };
|
|
20
|
+
export type { SeoAlternateLink, SeoConfig, SeoMiddlewareOptions, SeoRobotsConfig, SeoSocialConfig, SeoStoreOptions, SeoStructuredData, SeoVerificationConfig, };
|
|
109
21
|
//# sourceMappingURL=seo.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seo.d.ts","sourceRoot":"","sources":["../../../src/server/seo.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"seo.d.ts","sourceRoot":"","sources":["../../../src/server/seo.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACxB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,sBAAsB,EAEtB,aAAa,EACd,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EACV,gBAAgB,EAChB,SAAS,EACT,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AAExB,QAAA,MAAM,WAAW,EAAE,SAQjB,CAAC;AA0IH,iBAAS,OAAO,CAAC,IAAI,GAAE,SAAc,EAAE,QAAQ,GAAE,SAAc,aAmB9D;AAYD,iBAAS,cAAc,CAAC,GAAG,EAAE,iBAAiB,UAgB7C;AAED,iBAAS,gBAAgB,CAAC,IAAI,EAAE,OAAO,UAGtC;AAED,iBAAS,mBAAmB,CAAC,MAAM,GAAE,SAAc,UAElD;AAED,iBAAS,YAAY,CAAC,GAAG,EAAE,iBAAiB,EAAE,GAAG,EAAE,SAAS,aAG3D;AAED,iBAAS,eAAe,CAAC,GAAG,EAAE,kBAAkB,GAAG,IAAI,GAAG,SAAS,EAAE,GAAG,EAAE,SAAS,QAIlF;AAED,iBAAS,QAAQ,CACf,GAAG,EAAE,kBAAkB,GAAG,IAAI,GAAG,SAAS,EAC1C,SAAS,GAAE,SAAc,EACzB,OAAO,GAAE,oBAAyB,QAQnC;AAED,iBAAS,cAAc,CAAC,OAAO,GAAE,eAAoB;;qBAMjC,SAAS;EAM5B;AAED,iBAAS,mBAAmB,CAAC,OAAO,GAAE,oBAAyB,IAC/B,KAAK,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,MAAM,MAAM,OAAO,aAQnG;AAED,iBAAS,mBAAmB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,GAAE,oBAAyB,QAI5E;AAED,iBAAS,wBAAwB,CAAC,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EAAE,OAAO,GAAE,SAAc,aAS/F;AAED,OAAO,EACL,WAAW,EACX,sBAAsB,EACtB,QAAQ,EACR,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,YAAY,EACZ,wBAAwB,EACxB,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,OAAO,EACP,aAAa,GACd,CAAC;AACF,YAAY,EACV,gBAAgB,EAChB,SAAS,EACT,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,qBAAqB,GACtB,CAAC"}
|
package/dist/src/server/seo.js
CHANGED
|
@@ -1,111 +1,153 @@
|
|
|
1
|
-
import { serverString, setResponseHeader, } from "./http.js";
|
|
2
|
-
|
|
1
|
+
import { serverObject, serverString, setResponseHeader, } from "./http.js";
|
|
2
|
+
import { ROBOTS_NOINDEX_CONTENT, botRobotsContent, robotsContent, } from "./seo/robots.js";
|
|
3
|
+
import { firstSeoText } from "./seo/text.js";
|
|
3
4
|
const DEFAULT_SEO = Object.freeze({
|
|
4
|
-
titleSuffix: "",
|
|
5
|
-
metaDescription: "",
|
|
6
|
-
metaKeywords: "",
|
|
7
|
-
htmlLang: "en",
|
|
8
5
|
contentLanguage: "en",
|
|
6
|
+
htmlLang: "en",
|
|
7
|
+
index: false,
|
|
9
8
|
ogLocale: "en_US",
|
|
10
|
-
ogTitle: "",
|
|
11
|
-
ogDescription: "",
|
|
12
9
|
ogType: "website",
|
|
13
|
-
|
|
10
|
+
robots: { archive: false, follow: false, index: false },
|
|
14
11
|
twitterCard: "summary_large_image",
|
|
15
|
-
twitterSite: "",
|
|
16
|
-
index: false,
|
|
17
12
|
});
|
|
18
|
-
function
|
|
19
|
-
|
|
13
|
+
function firstArray(...values) {
|
|
14
|
+
for (const value of values) {
|
|
15
|
+
if (Array.isArray(value))
|
|
16
|
+
return value;
|
|
17
|
+
if (value != null)
|
|
18
|
+
return [value];
|
|
19
|
+
}
|
|
20
|
+
return [];
|
|
20
21
|
}
|
|
21
|
-
function
|
|
22
|
-
|
|
22
|
+
function mergeRecord(...values) {
|
|
23
|
+
return Object.assign({}, ...values.map(serverObject));
|
|
24
|
+
}
|
|
25
|
+
function booleanFallback(value, fallback) {
|
|
26
|
+
return typeof value === "boolean" ? value : fallback === true;
|
|
27
|
+
}
|
|
28
|
+
function defaultRobotsForIndex(index) {
|
|
29
|
+
return index
|
|
30
|
+
? { follow: true, index: true }
|
|
31
|
+
: { archive: false, follow: false, index: false };
|
|
32
|
+
}
|
|
33
|
+
function resolvedSeoRobots(body, base, index) {
|
|
34
|
+
return body.robots ??
|
|
35
|
+
("index" in body
|
|
36
|
+
? defaultRobotsForIndex(index)
|
|
37
|
+
: base.robots ?? defaultRobotsForIndex(index));
|
|
38
|
+
}
|
|
39
|
+
function createBaseSeoFields(context) {
|
|
40
|
+
const { base, body, description, index, openGraph, robots, title, twitter } = context;
|
|
23
41
|
return {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
alternates: firstArray(body.alternates, base.alternates),
|
|
43
|
+
applicationName: firstSeoText(body.applicationName, base.applicationName),
|
|
44
|
+
bingbot: body.bingbot ?? base.bingbot,
|
|
45
|
+
canonicalUrl: firstSeoText(body.canonicalUrl, base.canonicalUrl),
|
|
46
|
+
colorScheme: firstSeoText(body.colorScheme, base.colorScheme),
|
|
47
|
+
contentLanguage: firstSeoText(body.contentLanguage, base.contentLanguage),
|
|
48
|
+
googlebot: body.googlebot ?? base.googlebot,
|
|
49
|
+
htmlLang: firstSeoText(body.htmlLang, base.htmlLang),
|
|
50
|
+
index,
|
|
51
|
+
manifestHref: firstSeoText(body.manifestHref, base.manifestHref),
|
|
52
|
+
metaDescription: description,
|
|
53
|
+
metaKeywords: firstSeoText(body.metaKeywords, base.metaKeywords),
|
|
54
|
+
openGraph,
|
|
55
|
+
referrer: firstSeoText(body.referrer, base.referrer),
|
|
56
|
+
robots,
|
|
57
|
+
siteName: firstSeoText(body.siteName, base.siteName, openGraph.siteName),
|
|
58
|
+
structuredData: firstArray(body.structuredData, body.jsonLd, base.structuredData, base.jsonLd),
|
|
59
|
+
themeColor: firstSeoText(body.themeColor, base.themeColor),
|
|
60
|
+
title,
|
|
61
|
+
titleSuffix: firstSeoText(body.titleSuffix, base.titleSuffix),
|
|
62
|
+
twitter,
|
|
63
|
+
verification: mergeRecord(base.verification, body.verification),
|
|
37
64
|
};
|
|
38
65
|
}
|
|
66
|
+
function applyOpenGraphSeo(next, body, base, openGraph) {
|
|
67
|
+
next.ogTitle = firstSeoText(body.ogTitle, openGraph.title, base.ogTitle, next.title);
|
|
68
|
+
next.ogDescription = firstSeoText(body.ogDescription, openGraph.description, next.metaDescription, base.ogDescription);
|
|
69
|
+
next.ogType = firstSeoText(body.ogType, openGraph.type, base.ogType, "website");
|
|
70
|
+
next.ogImage = firstSeoText(body.ogImage, openGraphImage(openGraph.image), base.ogImage);
|
|
71
|
+
next.ogUrl = firstSeoText(body.ogUrl, openGraph.url, base.ogUrl, next.canonicalUrl);
|
|
72
|
+
next.ogLocale = firstSeoText(body.ogLocale, openGraph.locale, base.ogLocale);
|
|
73
|
+
next.ogSiteName = firstSeoText(body.ogSiteName, openGraph.siteName, base.ogSiteName, next.siteName);
|
|
74
|
+
}
|
|
75
|
+
function applyTwitterSeo(next, body, base, twitter) {
|
|
76
|
+
next.twitterCard = firstSeoText(body.twitterCard, twitter.card, base.twitterCard);
|
|
77
|
+
next.twitterTitle = firstSeoText(body.twitterTitle, twitter.title, base.twitterTitle, next.ogTitle);
|
|
78
|
+
next.twitterDescription = firstSeoText(body.twitterDescription, twitter.description, base.twitterDescription, next.ogDescription);
|
|
79
|
+
next.twitterImage = firstSeoText(body.twitterImage, openGraphImage(twitter.image), base.twitterImage, next.ogImage);
|
|
80
|
+
next.twitterSite = firstSeoText(body.twitterSite, twitter.site, base.twitterSite);
|
|
81
|
+
next.twitterCreator = firstSeoText(body.twitterCreator, twitter.creator, base.twitterCreator);
|
|
82
|
+
}
|
|
83
|
+
function applyBotSeo(next) {
|
|
84
|
+
next.robotsContent = robotsContent(next);
|
|
85
|
+
next.googlebotContent = botRobotsContent(next, "googlebot");
|
|
86
|
+
next.bingbotContent = botRobotsContent(next, "bingbot");
|
|
87
|
+
}
|
|
88
|
+
function pickSeo(body = {}, defaults = {}) {
|
|
89
|
+
const base = { ...DEFAULT_SEO, ...defaults };
|
|
90
|
+
const index = booleanFallback(body.index, base.index);
|
|
91
|
+
const openGraph = mergeRecord(base.openGraph, body.openGraph);
|
|
92
|
+
const twitter = mergeRecord(base.twitter, body.twitter);
|
|
93
|
+
const next = createBaseSeoFields({
|
|
94
|
+
base,
|
|
95
|
+
body,
|
|
96
|
+
description: firstSeoText(body.metaDescription, base.metaDescription),
|
|
97
|
+
index,
|
|
98
|
+
openGraph,
|
|
99
|
+
robots: resolvedSeoRobots(body, base, index),
|
|
100
|
+
title: firstSeoText(body.title, base.title),
|
|
101
|
+
twitter,
|
|
102
|
+
});
|
|
103
|
+
applyOpenGraphSeo(next, body, base, openGraph);
|
|
104
|
+
applyTwitterSeo(next, body, base, twitter);
|
|
105
|
+
applyBotSeo(next);
|
|
106
|
+
return next;
|
|
107
|
+
}
|
|
108
|
+
function openGraphImage(input) {
|
|
109
|
+
const first = Array.isArray(input) ? input[0] : input;
|
|
110
|
+
return typeof first === "string" ? first : firstSeoText(serverObject(first).url);
|
|
111
|
+
}
|
|
39
112
|
function requestGetter(req, name) {
|
|
40
113
|
const getter = req.get;
|
|
41
114
|
return typeof getter === "function" ? serverString(getter.call(req, name)) : "";
|
|
42
115
|
}
|
|
43
116
|
function buildCanonical(req) {
|
|
44
|
-
const headers = req && req.headers
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
host = host.replace(/:(80|443)$/, "");
|
|
117
|
+
const headers = serverObject(req && req.headers);
|
|
118
|
+
const proto = firstSeoText(serverString(headers["x-forwarded-proto"]).split(",")[0], req?.protocol, "https");
|
|
119
|
+
let host = firstSeoText(serverString(headers["x-forwarded-host"]).split(",")[0], requestGetter(req, "host"), headers.host);
|
|
120
|
+
if ((proto === "https" && /:443$/u.test(host)) ||
|
|
121
|
+
(proto === "http" && /:80$/u.test(host))) {
|
|
122
|
+
host = host.replace(/:(80|443)$/u, "");
|
|
51
123
|
}
|
|
52
|
-
const path =
|
|
53
|
-
return `${proto}://${host}${path}
|
|
124
|
+
const path = firstSeoText(req?.path, "/").replace(/\/+$/u, "") || "/";
|
|
125
|
+
return host ? `${proto}://${host}${path}` : path;
|
|
54
126
|
}
|
|
55
127
|
function humanizeFromPath(path) {
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
.filter(Boolean);
|
|
59
|
-
const last = segments.pop() || "";
|
|
60
|
-
if (!last)
|
|
61
|
-
return "";
|
|
62
|
-
return last
|
|
63
|
-
.replace(/-/g, " ")
|
|
64
|
-
.split(" ")
|
|
65
|
-
.map((word) => (/^[a-z]/.test(word) ? word.charAt(0).toUpperCase() + word.slice(1) : word))
|
|
66
|
-
.join(" ");
|
|
128
|
+
const last = firstSeoText(path, "/").split("/").filter(Boolean).pop() || "";
|
|
129
|
+
return last.replace(/[-_]+/gu, " ").replace(/\b[a-z]/gu, (char) => char.toUpperCase());
|
|
67
130
|
}
|
|
68
131
|
function getRobotsTagContent(config = {}) {
|
|
69
|
-
return robotsContent(config);
|
|
132
|
+
return robotsContent(pickSeo(config));
|
|
70
133
|
}
|
|
71
134
|
function buildSeoBase(req, seo) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
titleSuffix: seo.titleSuffix,
|
|
75
|
-
canonicalUrl: buildCanonical(req),
|
|
76
|
-
metaDescription: seo.metaDescription,
|
|
77
|
-
metaKeywords: seo.metaKeywords,
|
|
78
|
-
htmlLang: seo.htmlLang,
|
|
79
|
-
contentLanguage: seo.contentLanguage,
|
|
80
|
-
ogLocale: seo.ogLocale,
|
|
81
|
-
ogTitle: seo.ogTitle,
|
|
82
|
-
ogDescription: seo.ogDescription,
|
|
83
|
-
ogType: seo.ogType,
|
|
84
|
-
ogImage: seo.ogImage,
|
|
85
|
-
twitterCard: seo.twitterCard,
|
|
86
|
-
twitterSite: seo.twitterSite,
|
|
87
|
-
index: false,
|
|
88
|
-
robotsContent: getRobotsTagContent(seo),
|
|
89
|
-
googlebotContent: getRobotsTagContent(seo),
|
|
90
|
-
};
|
|
135
|
+
const title = firstSeoText(seo.title, humanizeFromPath(req?.path));
|
|
136
|
+
return pickSeo({ ...seo, canonicalUrl: firstSeoText(seo.canonicalUrl, buildCanonical(req)), title }, seo);
|
|
91
137
|
}
|
|
92
138
|
function applySeoHeaders(res, seo) {
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
setResponseHeader(res, "
|
|
139
|
+
const normalized = pickSeo(seo);
|
|
140
|
+
if (normalized.robotsContent)
|
|
141
|
+
setResponseHeader(res, "X-Robots-Tag", normalized.robotsContent);
|
|
142
|
+
if (normalized.contentLanguage)
|
|
143
|
+
setResponseHeader(res, "Content-Language", normalized.contentLanguage);
|
|
96
144
|
}
|
|
97
145
|
function applySeo(res, overrides = {}, options = {}) {
|
|
98
146
|
const locals = res?.locals;
|
|
99
147
|
if (!locals)
|
|
100
148
|
return;
|
|
101
|
-
const current = (locals.seo
|
|
102
|
-
const nextSeo = {
|
|
103
|
-
...current,
|
|
104
|
-
...overrides,
|
|
105
|
-
index: false,
|
|
106
|
-
robotsContent: getRobotsTagContent(options.defaults),
|
|
107
|
-
googlebotContent: getRobotsTagContent(options.defaults),
|
|
108
|
-
};
|
|
149
|
+
const current = serverObject(locals.seo);
|
|
150
|
+
const nextSeo = pickSeo(overrides, pickSeo(current, options.defaults || {}));
|
|
109
151
|
locals.seo = nextSeo;
|
|
110
152
|
applySeoHeaders(res, nextSeo);
|
|
111
153
|
}
|
|
@@ -113,11 +155,7 @@ function createSeoStore(options = {}) {
|
|
|
113
155
|
let current = pickSeo({}, options.defaults || {});
|
|
114
156
|
return {
|
|
115
157
|
getSeo() {
|
|
116
|
-
return
|
|
117
|
-
...current,
|
|
118
|
-
robotsContent: getRobotsTagContent(current),
|
|
119
|
-
googlebotContent: getRobotsTagContent(current),
|
|
120
|
-
};
|
|
158
|
+
return pickSeo(current);
|
|
121
159
|
},
|
|
122
160
|
updateSeo(body = {}) {
|
|
123
161
|
current = pickSeo(body, options.defaults || {});
|
|
@@ -142,5 +180,15 @@ function attachSeoMiddleware(app, options = {}) {
|
|
|
142
180
|
app.use(createSeoMiddleware(options));
|
|
143
181
|
}
|
|
144
182
|
}
|
|
145
|
-
|
|
183
|
+
function createProductSeoDefaults(product = {}, options = {}) {
|
|
184
|
+
const name = firstSeoText(product.name, options.siteName, "Product");
|
|
185
|
+
return pickSeo({
|
|
186
|
+
...options,
|
|
187
|
+
applicationName: firstSeoText(options.applicationName, name),
|
|
188
|
+
ogSiteName: firstSeoText(options.ogSiteName, options.siteName, name),
|
|
189
|
+
siteName: firstSeoText(options.siteName, name),
|
|
190
|
+
titleSuffix: options.titleSuffix === "" ? "" : firstSeoText(options.titleSuffix, ` | ${name}`),
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
export { DEFAULT_SEO, ROBOTS_NOINDEX_CONTENT, applySeo, applySeoHeaders, attachSeoMiddleware, buildCanonical, buildSeoBase, createProductSeoDefaults, createSeoMiddleware, createSeoStore, getRobotsTagContent, humanizeFromPath, pickSeo, robotsContent, };
|
|
146
194
|
//# sourceMappingURL=seo.js.map
|