@monkeyplus/flow 6.0.57 → 6.0.59
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/package.json +1 -1
- package/server/lib/pages.mjs +13 -1
- package/server/lib/render.mjs +27 -1
- package/src/runtime/pages.d.ts +10 -1
package/package.json
CHANGED
package/server/lib/pages.mjs
CHANGED
|
@@ -98,10 +98,14 @@ function createLocale(code) {
|
|
|
98
98
|
function createContext(definition, locale, localePage, pathname, params, dynamic, request) {
|
|
99
99
|
const imageUtils = getFlowImageRuntimeUtils();
|
|
100
100
|
const preview = request?.headers.get("cookie")?.includes("flow_preview=true") || false;
|
|
101
|
+
const config = getFlowRuntimeConfig();
|
|
102
|
+
const siteUrl = config.flow?.siteUrl || "";
|
|
103
|
+
const fullPath = siteUrl ? `${siteUrl.replace(/\/$/, "")}${pathname}` : pathname;
|
|
101
104
|
return {
|
|
102
105
|
dynamic,
|
|
103
106
|
locale,
|
|
104
107
|
path: pathname,
|
|
108
|
+
fullPath,
|
|
105
109
|
name: definition.name,
|
|
106
110
|
page: localePage,
|
|
107
111
|
params,
|
|
@@ -379,7 +383,15 @@ export async function resolveBreadcrumbs(pageName, pathname, localeCode, params,
|
|
|
379
383
|
if (!localePage || !localePage.breadcrumb) return [];
|
|
380
384
|
const locale = createLocale(localeCode);
|
|
381
385
|
const ctx = createContext(definition, locale, localePage, pathname, params, dynamic, request);
|
|
382
|
-
const
|
|
386
|
+
const pageContext = localePage.context ? await localePage.context(ctx) : {};
|
|
387
|
+
const pageHead = localePage.head ? await localePage.head(ctx) : localePage.seo ? await localePage.seo(ctx) : {};
|
|
388
|
+
const breadcrumbCtx = {
|
|
389
|
+
...ctx,
|
|
390
|
+
context: pageContext,
|
|
391
|
+
head: pageHead,
|
|
392
|
+
seo: pageHead.seo || pageHead
|
|
393
|
+
};
|
|
394
|
+
const result = await localePage.breadcrumb(breadcrumbCtx);
|
|
383
395
|
if (!result) return [];
|
|
384
396
|
let currentItems = [];
|
|
385
397
|
if (result.items) {
|
package/server/lib/render.mjs
CHANGED
|
@@ -150,6 +150,9 @@ ${cleanTrace}`);
|
|
|
150
150
|
lang: page.locale.lang
|
|
151
151
|
}
|
|
152
152
|
});
|
|
153
|
+
if (page.head) {
|
|
154
|
+
head.push(page.head);
|
|
155
|
+
}
|
|
153
156
|
head.push(normalizeSeoToHead(page.head, fallbackTitle, fallbackDescription));
|
|
154
157
|
app.use(head);
|
|
155
158
|
installFlowVuePlugins(app);
|
|
@@ -200,5 +203,28 @@ export async function renderDocument(page, clientAssets) {
|
|
|
200
203
|
].join("\n "),
|
|
201
204
|
body: pageMarkup
|
|
202
205
|
});
|
|
203
|
-
|
|
206
|
+
let finalHtml = await transformHtmlTemplate(rendered.head, html);
|
|
207
|
+
const schemaOrgConfig = page.head.templateParams?.schemaOrg;
|
|
208
|
+
if (schemaOrgConfig?.inLanguage && schemaOrgConfig.inLanguage !== page.locale.lang) {
|
|
209
|
+
finalHtml = finalHtml.replace(/<script[^>]*data-hid="schema-org-graph"[^>]*>([\s\S]*?)<\/script>/, (match, content) => {
|
|
210
|
+
try {
|
|
211
|
+
const data = JSON.parse(content);
|
|
212
|
+
const replaceLang = (obj) => {
|
|
213
|
+
if (Array.isArray(obj)) {
|
|
214
|
+
obj.forEach(replaceLang);
|
|
215
|
+
} else if (typeof obj === "object" && obj !== null) {
|
|
216
|
+
if (obj.inLanguage === page.locale.lang) {
|
|
217
|
+
obj.inLanguage = schemaOrgConfig.inLanguage;
|
|
218
|
+
}
|
|
219
|
+
Object.values(obj).forEach(replaceLang);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
replaceLang(data);
|
|
223
|
+
return match.replace(content, JSON.stringify(data));
|
|
224
|
+
} catch (e) {
|
|
225
|
+
return match;
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
return finalHtml;
|
|
204
230
|
}
|
package/src/runtime/pages.d.ts
CHANGED
|
@@ -99,6 +99,7 @@ export interface PageContextUtils {
|
|
|
99
99
|
export interface PageContextInput {
|
|
100
100
|
locale: FlowLocale;
|
|
101
101
|
path: string;
|
|
102
|
+
fullPath?: string;
|
|
102
103
|
name: string;
|
|
103
104
|
view: PageViewDefinition;
|
|
104
105
|
page: PageLocaleDefinition;
|
|
@@ -120,6 +121,14 @@ export interface BreadcrumbDefinition {
|
|
|
120
121
|
item?: BreadcrumbItem;
|
|
121
122
|
items?: BreadcrumbItem[];
|
|
122
123
|
}
|
|
124
|
+
export interface BreadcrumbContextInput extends PageContextInput {
|
|
125
|
+
context: Record<string, unknown>;
|
|
126
|
+
head: HeadDefinition;
|
|
127
|
+
/**
|
|
128
|
+
* @deprecated Use head.
|
|
129
|
+
*/
|
|
130
|
+
seo: HeadDefinition;
|
|
131
|
+
}
|
|
123
132
|
export interface PageLocaleDefinition {
|
|
124
133
|
url: string;
|
|
125
134
|
head?: (ctx: PageContextInput) => MaybePromise<HeadDefinition>;
|
|
@@ -128,7 +137,7 @@ export interface PageLocaleDefinition {
|
|
|
128
137
|
*/
|
|
129
138
|
seo?: (ctx: PageContextInput) => MaybePromise<HeadDefinition>;
|
|
130
139
|
context?: (ctx: PageContextInput) => MaybePromise<Record<string, unknown>>;
|
|
131
|
-
breadcrumb?: (ctx:
|
|
140
|
+
breadcrumb?: (ctx: BreadcrumbContextInput) => MaybePromise<BreadcrumbDefinition>;
|
|
132
141
|
dynamic?: DynamicRouteOptions;
|
|
133
142
|
}
|
|
134
143
|
export interface PageDefinition {
|