@trebired/frontend 6.3.0 → 6.4.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 +5 -0
- package/dist/server/http.d.ts +6 -0
- package/dist/server/http.d.ts.map +1 -1
- package/dist/server/http.js.map +1 -1
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +3 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/language.d.ts +51 -0
- package/dist/server/language.d.ts.map +1 -0
- package/dist/server/language.js +147 -0
- package/dist/server/language.js.map +1 -0
- package/dist/server/navigation.d.ts +54 -0
- package/dist/server/navigation.d.ts.map +1 -0
- package/dist/server/navigation.js +184 -0
- package/dist/server/navigation.js.map +1 -0
- package/dist/server/seo.d.ts +109 -0
- package/dist/server/seo.d.ts.map +1 -0
- package/dist/server/seo.js +146 -0
- package/dist/server/seo.js.map +1 -0
- package/dist/src/server/http.d.ts +6 -0
- package/dist/src/server/http.d.ts.map +1 -1
- package/dist/src/server/http.js.map +1 -1
- package/dist/src/server/index.d.ts +3 -0
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +3 -0
- package/dist/src/server/index.js.map +1 -1
- package/dist/src/server/language.d.ts +51 -0
- package/dist/src/server/language.d.ts.map +1 -0
- package/dist/src/server/language.js +147 -0
- package/dist/src/server/language.js.map +1 -0
- package/dist/src/server/navigation.d.ts +54 -0
- package/dist/src/server/navigation.d.ts.map +1 -0
- package/dist/src/server/navigation.js +184 -0
- package/dist/src/server/navigation.js.map +1 -0
- package/dist/src/server/seo.d.ts +109 -0
- package/dist/src/server/seo.d.ts.map +1 -0
- package/dist/src/server/seo.js +146 -0
- package/dist/src/server/seo.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
const EMPTY_CURRENT = {
|
|
2
|
+
path: "/",
|
|
3
|
+
url: "/",
|
|
4
|
+
};
|
|
5
|
+
function normalizeNavigationPath(input) {
|
|
6
|
+
const raw = String(input == null ? "" : input).trim() || "/";
|
|
7
|
+
let path = raw;
|
|
8
|
+
const fragmentMarker = String.fromCharCode(35);
|
|
9
|
+
try {
|
|
10
|
+
path =
|
|
11
|
+
raw.startsWith("http://") || raw.startsWith("https://")
|
|
12
|
+
? new URL(raw).pathname
|
|
13
|
+
: raw;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
path = raw;
|
|
17
|
+
}
|
|
18
|
+
path = path.split(fragmentMarker)[0].split("?")[0].trim() || "/";
|
|
19
|
+
if (!path.startsWith("/"))
|
|
20
|
+
path = `/${path}`;
|
|
21
|
+
return path.replace(/\/{2,}/g, "/").replace(/\/+$/g, "") || "/";
|
|
22
|
+
}
|
|
23
|
+
function normalizeRequestPath(req) {
|
|
24
|
+
const request = req;
|
|
25
|
+
return normalizeNavigationPath(request && (request.originalUrl || request.url || request.path));
|
|
26
|
+
}
|
|
27
|
+
function normalizeNavigationHref(input) {
|
|
28
|
+
const raw = String(input || "").trim();
|
|
29
|
+
if (!raw || raw.startsWith(String.fromCharCode(35)))
|
|
30
|
+
return "";
|
|
31
|
+
return normalizeNavigationPath(raw);
|
|
32
|
+
}
|
|
33
|
+
function matchesCurrentPath(currentPath, input, opts = {}) {
|
|
34
|
+
const href = normalizeNavigationHref(input);
|
|
35
|
+
if (!href)
|
|
36
|
+
return false;
|
|
37
|
+
if (href === currentPath)
|
|
38
|
+
return true;
|
|
39
|
+
if (opts.exact === true || href === "/")
|
|
40
|
+
return false;
|
|
41
|
+
return currentPath.startsWith(href + "/");
|
|
42
|
+
}
|
|
43
|
+
function addClassAttr(tag, className) {
|
|
44
|
+
const cls = String(className || "").trim();
|
|
45
|
+
if (!cls)
|
|
46
|
+
return tag;
|
|
47
|
+
if (!/\bclass\s*=/i.test(tag))
|
|
48
|
+
return tag.replace(/>$/, ` class="${cls}">`);
|
|
49
|
+
return tag.replace(/\bclass=(["'])(.*?)\1/i, (_match, quote, value) => {
|
|
50
|
+
const classes = String(value || "")
|
|
51
|
+
.split(/\s+/)
|
|
52
|
+
.filter(Boolean);
|
|
53
|
+
if (!classes.includes(cls))
|
|
54
|
+
classes.push(cls);
|
|
55
|
+
return `class=${quote}${classes.join(" ")}${quote}`;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function addAttr(tag, name, value) {
|
|
59
|
+
const attr = String(name || "").trim();
|
|
60
|
+
if (!attr || new RegExp(`\\b${attr}\\s*=`, "i").test(tag))
|
|
61
|
+
return tag;
|
|
62
|
+
return tag.replace(/>$/, ` ${attr}="${String(value || "")}">`);
|
|
63
|
+
}
|
|
64
|
+
function hasAttr(tag, name) {
|
|
65
|
+
const attr = String(name || "").trim();
|
|
66
|
+
return Boolean(attr && new RegExp(`\\b${attr}(?:\\s*=|\\s|>|$)`, "i").test(tag));
|
|
67
|
+
}
|
|
68
|
+
function openParentLiStart(html, childStart) {
|
|
69
|
+
const beforeChild = html.slice(0, childStart).toLowerCase();
|
|
70
|
+
const liOpen = beforeChild.lastIndexOf("<li");
|
|
71
|
+
if (liOpen < 0)
|
|
72
|
+
return -1;
|
|
73
|
+
const liClose = beforeChild.lastIndexOf("</li>");
|
|
74
|
+
return liOpen > liClose ? liOpen : -1;
|
|
75
|
+
}
|
|
76
|
+
function activeLinkMatches(src, currentPath, exact) {
|
|
77
|
+
const linkRe = /<a\b([^>]*?)\bhref=(["'])(.*?)\2([^>]*)>([\s\S]*?)<\/a>/gi;
|
|
78
|
+
const matches = [];
|
|
79
|
+
let match;
|
|
80
|
+
while ((match = linkRe.exec(src))) {
|
|
81
|
+
const tag = match[0].slice(0, match[0].indexOf(">") + 1);
|
|
82
|
+
const href = normalizeNavigationHref(match[3]);
|
|
83
|
+
if (!href || hasAttr(tag, "data-nav-ignore"))
|
|
84
|
+
continue;
|
|
85
|
+
if (!matchesCurrentPath(currentPath, href, { exact }))
|
|
86
|
+
continue;
|
|
87
|
+
matches.push({
|
|
88
|
+
end: match.index + match[0].length,
|
|
89
|
+
href,
|
|
90
|
+
html: match[0],
|
|
91
|
+
start: match.index,
|
|
92
|
+
tagEnd: match[0].indexOf(">"),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return matches.sort((left, right) => right.href.length - left.href.length);
|
|
96
|
+
}
|
|
97
|
+
function decorateActiveLink(html, currentPath, opts = {}) {
|
|
98
|
+
const src = String(html || "");
|
|
99
|
+
if (!src)
|
|
100
|
+
return "";
|
|
101
|
+
const matches = activeLinkMatches(src, currentPath, opts.exact === true);
|
|
102
|
+
const best = matches[0];
|
|
103
|
+
if (!best)
|
|
104
|
+
return src;
|
|
105
|
+
const linkClass = String(opts.linkClass || "is-active").trim();
|
|
106
|
+
const liClass = String(opts.liClass || "active").trim();
|
|
107
|
+
const openTag = best.html.slice(0, best.tagEnd + 1);
|
|
108
|
+
const restLink = best.html.slice(best.tagEnd + 1);
|
|
109
|
+
const activeLink = addAttr(addClassAttr(openTag, linkClass), "aria-current", "page") + restLink;
|
|
110
|
+
const withLink = src.slice(0, best.start) + activeLink + src.slice(best.end);
|
|
111
|
+
const liStart = openParentLiStart(src, best.start);
|
|
112
|
+
if (liStart < 0 || !liClass)
|
|
113
|
+
return withLink;
|
|
114
|
+
const liOpenEnd = withLink.indexOf(">", liStart);
|
|
115
|
+
if (liOpenEnd < 0 || liOpenEnd > best.start)
|
|
116
|
+
return withLink;
|
|
117
|
+
const liOpen = withLink.slice(liStart, liOpenEnd + 1);
|
|
118
|
+
return withLink.slice(0, liStart) + addClassAttr(liOpen, liClass) + withLink.slice(liOpenEnd + 1);
|
|
119
|
+
}
|
|
120
|
+
function decorateDataNode(html, dataAttr, active, className = "is-active", aria = false) {
|
|
121
|
+
if (!active)
|
|
122
|
+
return html;
|
|
123
|
+
const attr = String(dataAttr || "").trim();
|
|
124
|
+
if (!attr)
|
|
125
|
+
return html;
|
|
126
|
+
const re = new RegExp(`<(?:a|button)\\b(?=[^>]*\\b${attr}\\b)[^>]*>`, "i");
|
|
127
|
+
return html.replace(re, (tag) => {
|
|
128
|
+
const withClass = addClassAttr(tag, className);
|
|
129
|
+
return aria ? addAttr(withClass, "aria-current", "page") : withClass;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
function currentIsCurrent(current, input, opts = {}) {
|
|
133
|
+
if (Array.isArray(input))
|
|
134
|
+
return input.some((item) => matchesCurrentPath(current.path, item, opts));
|
|
135
|
+
return matchesCurrentPath(current.path, input, opts);
|
|
136
|
+
}
|
|
137
|
+
function currentAttrs(current, input, opts = {}) {
|
|
138
|
+
return currentIsCurrent(current, input, opts) ? ' aria-current="page"' : "";
|
|
139
|
+
}
|
|
140
|
+
function currentLinkAttrs(current, input, opts = {}) {
|
|
141
|
+
return currentIsCurrent(current, input, opts) ? ' class="is-active" aria-current="page"' : "";
|
|
142
|
+
}
|
|
143
|
+
function currentLiAttrs(current, input, opts = {}) {
|
|
144
|
+
return currentIsCurrent(current, input, opts) ? ' class="active"' : "";
|
|
145
|
+
}
|
|
146
|
+
function currentClassName(current, base, input, opts = {}) {
|
|
147
|
+
return [String(base || "").trim(), currentIsCurrent(current, input, opts) ? "is-active" : ""]
|
|
148
|
+
.filter(Boolean)
|
|
149
|
+
.join(" ");
|
|
150
|
+
}
|
|
151
|
+
function currentMenuClass(current, base, opts = {}) {
|
|
152
|
+
const exclude = Array.isArray(opts.exclude) ? opts.exclude : [];
|
|
153
|
+
const active = current.path !== "/" && !currentIsCurrent(current, exclude);
|
|
154
|
+
return [String(base || "").trim(), active ? "has-current-page is-active" : ""]
|
|
155
|
+
.filter(Boolean)
|
|
156
|
+
.join(" ");
|
|
157
|
+
}
|
|
158
|
+
function decorateBottomBarHtml(current, html) {
|
|
159
|
+
let out = String(html || "");
|
|
160
|
+
out = decorateDataNode(out, "data-bottom-bar-apps", currentIsCurrent(current, "/apps"), "is-active", true);
|
|
161
|
+
out = decorateDataNode(out, "data-bottom-bar-profile", currentIsCurrent(current, "/me"), "is-active", true);
|
|
162
|
+
return out;
|
|
163
|
+
}
|
|
164
|
+
function createNavigationState(currentInput = EMPTY_CURRENT) {
|
|
165
|
+
const current = {
|
|
166
|
+
path: normalizeNavigationPath(currentInput.path),
|
|
167
|
+
url: String(currentInput.url || currentInput.path || "/"),
|
|
168
|
+
};
|
|
169
|
+
return {
|
|
170
|
+
current,
|
|
171
|
+
isCurrent: (input, opts = {}) => currentIsCurrent(current, input, opts),
|
|
172
|
+
attrs: (input, opts = {}) => currentAttrs(current, input, opts),
|
|
173
|
+
linkAttrs: (input, opts = {}) => currentLinkAttrs(current, input, opts),
|
|
174
|
+
liAttrs: (input, opts = {}) => currentLiAttrs(current, input, opts),
|
|
175
|
+
className: (base, input, opts = {}) => currentClassName(current, base, input, opts),
|
|
176
|
+
menuClass: (base, opts = {}) => currentMenuClass(current, base, opts),
|
|
177
|
+
decorate: (html, opts = {}) => decorateActiveLink(html, current.path, opts),
|
|
178
|
+
decorateSidebar: (html, opts = {}) => decorateActiveLink(html, current.path, opts),
|
|
179
|
+
decorateBottomBar: (html) => decorateBottomBarHtml(current, html),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
const defaultNavigationState = createNavigationState(EMPTY_CURRENT);
|
|
183
|
+
export { createNavigationState, decorateActiveLink, defaultNavigationState, matchesCurrentPath, normalizeNavigationHref, normalizeNavigationHref as normalizeHref, normalizeNavigationPath, normalizeRequestPath, };
|
|
184
|
+
//# sourceMappingURL=navigation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation.js","sourceRoot":"","sources":["../../../src/server/navigation.ts"],"names":[],"mappings":"AAgBA,MAAM,aAAa,GAAsB;IACvC,IAAI,EAAE,GAAG;IACT,GAAG,EAAE,GAAG;CACT,CAAC;AAEF,SAAS,uBAAuB,CAAC,KAAc;IAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IA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AAE,CAAC,KAAc,EAAE,OAA4B,EAAE,EAAE,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC;QACjG,SAAS,EAAE,CAAC,IAAa,EAAE,KAAc,EAAE,OAA4B,EAAE,EAAE,EAAE,CAC7E,gBAAgB,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC;QAC5C,SAAS,EAAE,CAAC,IAAa,EAAE,OAAgC,EAAE,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC;QACvG,QAAQ,EAAE,CAAC,IAAa,EAAE,OAAwB,EAAE,EAAE,EAAE,CAAC,kBAAkB,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC;QACrG,eAAe,EAAE,CAAC,IAAa,EAAE,OAAwB,EAAE,EAAE,EAAE,CAAC,kBAAkB,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC;QAC5G,iBAAiB,EAAE,CAAC,IAAa,EAAE,EAAE,CAAC,qBAAqB,CAAC,OAAO,EAAE,IAAI,CAAC;KACzE,CAAC;AACF,CAAC;AAED,MAAM,sBAAsB,GAAG,qBAAqB,CAAC,aAAa,CAAC,CAAC;AAEpE,OAAO,EACP,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,uBAAuB,EACvB,uBAAuB,IAAI,aAAa,EACxC,uBAAuB,EACvB,oBAAoB,GACnB,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { type ServerRequestLike, type ServerResponseLike } from "./http.js";
|
|
2
|
+
declare const ROBOTS_NOINDEX_CONTENT = "noindex, nofollow, noarchive";
|
|
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
|
+
};
|
|
32
|
+
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
|
+
};
|
|
48
|
+
declare function buildCanonical(req: ServerRequestLike): string;
|
|
49
|
+
declare function humanizeFromPath(path: unknown): string;
|
|
50
|
+
declare function getRobotsTagContent(config?: SeoConfig): string;
|
|
51
|
+
declare function buildSeoBase(req: ServerRequestLike, seo: SeoConfig): {
|
|
52
|
+
title: string;
|
|
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
|
+
};
|
|
70
|
+
declare function applySeo(res: ServerResponseLike | null | undefined, overrides?: SeoConfig, options?: SeoMiddlewareOptions): void;
|
|
71
|
+
declare function createSeoStore(options?: SeoStoreOptions): {
|
|
72
|
+
getSeo(): {
|
|
73
|
+
robotsContent: string;
|
|
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
|
+
};
|
|
104
|
+
};
|
|
105
|
+
declare function createSeoMiddleware(options?: SeoMiddlewareOptions): (req: ServerRequestLike, res: ServerResponseLike, next: () => unknown) => unknown;
|
|
106
|
+
declare function attachSeoMiddleware(app: unknown, options?: SeoMiddlewareOptions): void;
|
|
107
|
+
export { DEFAULT_SEO, ROBOTS_NOINDEX_CONTENT, applySeo, attachSeoMiddleware, buildCanonical, buildSeoBase, createSeoMiddleware, createSeoStore, getRobotsTagContent, humanizeFromPath, pickSeo, };
|
|
108
|
+
export type { SeoConfig, SeoMiddlewareOptions, SeoStoreOptions };
|
|
109
|
+
//# sourceMappingURL=seo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seo.d.ts","sourceRoot":"","sources":["../../../src/server/seo.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACxB,MAAM,WAAW,CAAC;AAEnB,QAAA,MAAM,sBAAsB,iCAAiC,CAAC;AAE9D,KAAK,SAAS,GAAG;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,KAAK,oBAAoB,GAAG;IAC1B,QAAQ,CAAC,EA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,EACZ,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,OAAO,GACR,CAAC;AACF,YAAY,EAAE,SAAS,EAAE,oBAAoB,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { serverString, setResponseHeader, } from "./http.js";
|
|
2
|
+
const ROBOTS_NOINDEX_CONTENT = "noindex, nofollow, noarchive";
|
|
3
|
+
const DEFAULT_SEO = Object.freeze({
|
|
4
|
+
titleSuffix: "",
|
|
5
|
+
metaDescription: "",
|
|
6
|
+
metaKeywords: "",
|
|
7
|
+
htmlLang: "en",
|
|
8
|
+
contentLanguage: "en",
|
|
9
|
+
ogLocale: "en_US",
|
|
10
|
+
ogTitle: "",
|
|
11
|
+
ogDescription: "",
|
|
12
|
+
ogType: "website",
|
|
13
|
+
ogImage: "",
|
|
14
|
+
twitterCard: "summary_large_image",
|
|
15
|
+
twitterSite: "",
|
|
16
|
+
index: false,
|
|
17
|
+
});
|
|
18
|
+
function robotsContent(config = {}) {
|
|
19
|
+
return serverString(config.robotsContent || ROBOTS_NOINDEX_CONTENT);
|
|
20
|
+
}
|
|
21
|
+
function pickSeo(body = {}, defaults = {}) {
|
|
22
|
+
const base = { ...DEFAULT_SEO, ...defaults };
|
|
23
|
+
return {
|
|
24
|
+
titleSuffix: serverString(body.titleSuffix || base.titleSuffix),
|
|
25
|
+
metaDescription: serverString(body.metaDescription || base.metaDescription),
|
|
26
|
+
metaKeywords: serverString(body.metaKeywords || base.metaKeywords),
|
|
27
|
+
htmlLang: serverString(body.htmlLang || base.htmlLang),
|
|
28
|
+
contentLanguage: serverString(body.contentLanguage || base.contentLanguage),
|
|
29
|
+
ogLocale: serverString(body.ogLocale || base.ogLocale),
|
|
30
|
+
ogTitle: serverString(body.ogTitle || base.ogTitle),
|
|
31
|
+
ogDescription: serverString(body.ogDescription || base.ogDescription),
|
|
32
|
+
ogType: serverString(body.ogType || base.ogType),
|
|
33
|
+
ogImage: serverString(body.ogImage || base.ogImage),
|
|
34
|
+
twitterCard: serverString(body.twitterCard || base.twitterCard),
|
|
35
|
+
twitterSite: serverString(body.twitterSite || base.twitterSite),
|
|
36
|
+
index: false,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function requestGetter(req, name) {
|
|
40
|
+
const getter = req.get;
|
|
41
|
+
return typeof getter === "function" ? serverString(getter.call(req, name)) : "";
|
|
42
|
+
}
|
|
43
|
+
function buildCanonical(req) {
|
|
44
|
+
const headers = req && req.headers && typeof req.headers === "object" ? req.headers : {};
|
|
45
|
+
const xfProto = serverString(headers["x-forwarded-proto"]).split(",")[0].trim();
|
|
46
|
+
const proto = xfProto || serverString(req.protocol) || "https";
|
|
47
|
+
const xfHost = serverString(headers["x-forwarded-host"]).split(",")[0].trim();
|
|
48
|
+
let host = xfHost || requestGetter(req, "host") || serverString(headers.host);
|
|
49
|
+
if ((proto === "https" && /:443$/.test(host)) || (proto === "http" && /:80$/.test(host))) {
|
|
50
|
+
host = host.replace(/:(80|443)$/, "");
|
|
51
|
+
}
|
|
52
|
+
const path = serverString(req.path || "/").replace(/\/+$/, "") || "/";
|
|
53
|
+
return `${proto}://${host}${path}`;
|
|
54
|
+
}
|
|
55
|
+
function humanizeFromPath(path) {
|
|
56
|
+
const segments = serverString(path || "/")
|
|
57
|
+
.split("/")
|
|
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(" ");
|
|
67
|
+
}
|
|
68
|
+
function getRobotsTagContent(config = {}) {
|
|
69
|
+
return robotsContent(config);
|
|
70
|
+
}
|
|
71
|
+
function buildSeoBase(req, seo) {
|
|
72
|
+
return {
|
|
73
|
+
title: humanizeFromPath(req.path) || "",
|
|
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
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function applySeoHeaders(res, seo) {
|
|
93
|
+
setResponseHeader(res, "X-Robots-Tag", getRobotsTagContent(seo));
|
|
94
|
+
if (seo.contentLanguage)
|
|
95
|
+
setResponseHeader(res, "Content-Language", serverString(seo.contentLanguage));
|
|
96
|
+
}
|
|
97
|
+
function applySeo(res, overrides = {}, options = {}) {
|
|
98
|
+
const locals = res?.locals;
|
|
99
|
+
if (!locals)
|
|
100
|
+
return;
|
|
101
|
+
const current = (locals.seo && typeof locals.seo === "object" ? locals.seo : {});
|
|
102
|
+
const nextSeo = {
|
|
103
|
+
...current,
|
|
104
|
+
...overrides,
|
|
105
|
+
index: false,
|
|
106
|
+
robotsContent: getRobotsTagContent(options.defaults),
|
|
107
|
+
googlebotContent: getRobotsTagContent(options.defaults),
|
|
108
|
+
};
|
|
109
|
+
locals.seo = nextSeo;
|
|
110
|
+
applySeoHeaders(res, nextSeo);
|
|
111
|
+
}
|
|
112
|
+
function createSeoStore(options = {}) {
|
|
113
|
+
let current = pickSeo({}, options.defaults || {});
|
|
114
|
+
return {
|
|
115
|
+
getSeo() {
|
|
116
|
+
return {
|
|
117
|
+
...current,
|
|
118
|
+
robotsContent: getRobotsTagContent(current),
|
|
119
|
+
googlebotContent: getRobotsTagContent(current),
|
|
120
|
+
};
|
|
121
|
+
},
|
|
122
|
+
updateSeo(body = {}) {
|
|
123
|
+
current = pickSeo(body, options.defaults || {});
|
|
124
|
+
options.logger?.info?.("seo", "Updated global SEO settings");
|
|
125
|
+
return current;
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function createSeoMiddleware(options = {}) {
|
|
130
|
+
return function seoMiddleware(req, res, next) {
|
|
131
|
+
const seo = options.getSeo ? options.getSeo() : pickSeo({}, options.defaults || {});
|
|
132
|
+
const baseSeo = buildSeoBase(req, seo);
|
|
133
|
+
const locals = res.locals;
|
|
134
|
+
if (locals)
|
|
135
|
+
locals.seo = baseSeo;
|
|
136
|
+
applySeoHeaders(res, baseSeo);
|
|
137
|
+
return next();
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function attachSeoMiddleware(app, options = {}) {
|
|
141
|
+
if (app && typeof app.use === "function") {
|
|
142
|
+
app.use(createSeoMiddleware(options));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export { DEFAULT_SEO, ROBOTS_NOINDEX_CONTENT, applySeo, attachSeoMiddleware, buildCanonical, buildSeoBase, createSeoMiddleware, createSeoStore, getRobotsTagContent, humanizeFromPath, pickSeo, };
|
|
146
|
+
//# sourceMappingURL=seo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seo.js","sourceRoot":"","sources":["../../../src/server/seo.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,iBAAiB,GAGlB,MAAM,WAAW,CAAC;AAEnB,MAAM,sBAAsB,GAAG,8BAA8B,CAAC;AAgC9D,MAAM,WAAW,GAAc,MAAM,CAAC,MAAM,CAAC;IACzC,WAAW,EAAE,EAAE;IACf,eAAe,EAAE,EAAE;IACnB,YAAY,EAAE,EAA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