@phis/ui 0.4.5 → 0.4.7
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/components/cms/phi-cms-root-layout.js +1 -1
- package/components/controls/phi-button-control.d.ts +3 -1
- package/components/controls/phi-button-control.js +2 -2
- package/components/controls/phi-collapse-control.d.ts +6 -2
- package/components/controls/phi-collapse-control.js +2 -2
- package/components/controls/phi-dialog-control.d.ts +11 -5
- package/components/controls/phi-dialog-control.js +19 -13
- package/components/controls/phi-menu-control-vocabulary.d.ts +7 -0
- package/components/controls/phi-menu-control-vocabulary.js +10 -0
- package/components/controls/phi-menu-control.d.ts +4 -1
- package/components/controls/phi-menu-control.js +6 -1
- package/components/controls/phi-text-control.d.ts +6 -1
- package/components/controls/phi-text-control.js +2 -1
- package/components/layouts/clients/phi-split-card-layout-client.js +13 -5
- package/components/layouts/clients/phi-three-column-layout-client.js +9 -3
- package/components/layouts/split-card-geometry.js +6 -2
- package/components/media/aspect-ratios.d.ts +2 -2
- package/components/menus/phi-account-menu.js +3 -1
- package/components/navigation/phi-link.js +7 -2
- package/components/navigation/use-phi-protected-mail.d.ts +11 -0
- package/components/navigation/use-phi-protected-mail.js +29 -0
- package/components/regions/clients/cms-region-container-client.js +5 -1
- package/components/regions/phi-cms-region-shell.d.ts +1 -0
- package/components/regions/phi-cms-region-shell.js +11 -0
- package/components/regions/presets/phi-area-shell-preset-nodes.d.ts +5 -0
- package/components/regions/presets/phi-area-shell-preset-nodes.js +19 -3
- package/components/root/phi-config-provider.js +16 -0
- package/components/shell/phi-cms-shell.d.ts +3 -1
- package/components/shell/phi-cms-shell.js +7 -3
- package/components/shell/phi-nav-link.js +7 -2
- package/components/shell/phi-shell-sider-drawer.d.ts +17 -0
- package/components/shell/phi-shell-sider-drawer.js +88 -0
- package/components/widgets/helpers/internal-reference-resolver.server.d.ts +1 -0
- package/components/widgets/helpers/internal-reference-resolver.server.js +4 -1
- package/components/widgets/label-sets/inspector.js +2 -0
- package/components/widgets/label-sets/search-results.d.ts +4 -0
- package/components/widgets/label-sets/search-results.js +35 -0
- package/components/widgets/label-types/inspector.d.ts +2 -0
- package/components/widgets/label-types/inspector.js +1 -0
- package/components/widgets/label-types/search-results.d.ts +15 -0
- package/components/widgets/label-types/search-results.js +10 -0
- package/components/widgets/server/navigation-request.js +13 -1
- package/components/widgets/shared/card-body-client.d.ts +2 -0
- package/components/widgets/shared/card-body-client.js +8 -7
- package/components/widgets/shared/card-vocabulary.d.ts +36 -0
- package/components/widgets/shared/card-vocabulary.js +52 -0
- package/components/widgets/shared/markdown-body-client.d.ts +29 -0
- package/components/widgets/shared/markdown-body-client.js +60 -5
- package/components/widgets/shared/markdown-image-vocabulary.d.ts +31 -0
- package/components/widgets/shared/markdown-image-vocabulary.js +68 -0
- package/components/widgets/shared/markdown-render.d.ts +5 -0
- package/components/widgets/shared/markdown-render.js +123 -8
- package/components/widgets/shared/markdown-sections.d.ts +40 -0
- package/components/widgets/shared/markdown-sections.js +111 -0
- package/constants/cms-widget-types.d.ts +2 -0
- package/constants/cms-widget-types.js +4 -0
- package/gateway/site-area.d.ts +10 -7
- package/gateway/site-area.js +13 -11
- package/gateway/site-config.js +7 -1
- package/gateway/site-read-marker-listeners.d.ts +24 -0
- package/gateway/site-read-marker-listeners.js +22 -0
- package/gateway/site-search.d.ts +37 -0
- package/gateway/site-search.js +116 -0
- package/helpers/external-href.js +1 -1
- package/helpers/protected-mail.d.ts +16 -0
- package/helpers/protected-mail.js +81 -0
- package/next/areas/app.js +5 -1
- package/next/areas/public.js +5 -1
- package/next/seo-routes.js +2 -2
- package/package.json +2 -2
- package/plugins/runtime-modules/app/presets.js +23 -0
- package/plugins/runtime-modules/app/trees/phi-default-app-area-preset-tree.d.ts +2 -1
- package/plugins/runtime-modules/app/trees/phi-default-app-area-preset-tree.js +3 -2
- package/plugins/runtime-modules/builder/clients/region-inspector.js +20 -1
- package/plugins/runtime-modules/client-manifests/common.js +8 -0
- package/plugins/runtime-modules/core/authoring-widgets.js +4 -0
- package/plugins/runtime-modules/core/widgets/card/config.d.ts +8 -1
- package/plugins/runtime-modules/core/widgets/card/config.js +22 -1
- package/plugins/runtime-modules/core/widgets/card/editor.js +9 -1
- package/plugins/runtime-modules/core/widgets/card/plugin.js +18 -0
- package/plugins/runtime-modules/core/widgets/card/server.js +9 -1
- package/plugins/runtime-modules/core/widgets/description/plugin.js +10 -0
- package/plugins/runtime-modules/core/widgets/entry-list/view.server.js +2 -1
- package/plugins/runtime-modules/core/widgets/gallery/config.d.ts +3 -3
- package/plugins/runtime-modules/core/widgets/header-navigation/client.d.ts +6 -1
- package/plugins/runtime-modules/core/widgets/header-navigation/client.js +40 -13
- package/plugins/runtime-modules/core/widgets/header-navigation/config.d.ts +26 -1
- package/plugins/runtime-modules/core/widgets/header-navigation/config.js +27 -0
- package/plugins/runtime-modules/core/widgets/header-navigation/plugin.js +1 -1
- package/plugins/runtime-modules/core/widgets/header-navigation/server.d.ts +2 -2
- package/plugins/runtime-modules/core/widgets/header-navigation/server.js +3 -1
- package/plugins/runtime-modules/core/widgets/html/plugin.js +16 -1
- package/plugins/runtime-modules/core/widgets/html/server.d.ts +6 -0
- package/plugins/runtime-modules/core/widgets/html/server.js +12 -4
- package/plugins/runtime-modules/core/widgets/image/client.js +11 -7
- package/plugins/runtime-modules/core/widgets/markdown/config.d.ts +16 -0
- package/plugins/runtime-modules/core/widgets/markdown/config.js +46 -1
- package/plugins/runtime-modules/core/widgets/markdown/plugin.js +16 -0
- package/plugins/runtime-modules/core/widgets/markdown/server.js +22 -8
- package/plugins/runtime-modules/core/widgets/search-box/authoring.d.ts +6 -0
- package/plugins/runtime-modules/core/widgets/search-box/authoring.js +10 -0
- package/plugins/runtime-modules/core/widgets/search-box/client.d.ts +21 -0
- package/plugins/runtime-modules/core/widgets/search-box/client.js +17 -0
- package/plugins/runtime-modules/core/widgets/search-box/config.d.ts +63 -0
- package/plugins/runtime-modules/core/widgets/search-box/config.js +48 -0
- package/plugins/runtime-modules/core/widgets/search-box/plugin.d.ts +3 -0
- package/plugins/runtime-modules/core/widgets/search-box/plugin.js +11 -0
- package/plugins/runtime-modules/core/widgets/search-box/server.d.ts +21 -0
- package/plugins/runtime-modules/core/widgets/search-box/server.js +48 -0
- package/plugins/runtime-modules/core/widgets/search-results/authoring.d.ts +6 -0
- package/plugins/runtime-modules/core/widgets/search-results/authoring.js +10 -0
- package/plugins/runtime-modules/core/widgets/search-results/client.d.ts +34 -0
- package/plugins/runtime-modules/core/widgets/search-results/client.js +32 -0
- package/plugins/runtime-modules/core/widgets/search-results/config.d.ts +41 -0
- package/plugins/runtime-modules/core/widgets/search-results/config.js +39 -0
- package/plugins/runtime-modules/core/widgets/search-results/plugin.d.ts +3 -0
- package/plugins/runtime-modules/core/widgets/search-results/plugin.js +10 -0
- package/plugins/runtime-modules/core/widgets/search-results/server.d.ts +20 -0
- package/plugins/runtime-modules/core/widgets/search-results/server.js +73 -0
- package/plugins/runtime-modules/core/widgets/simple-text/plugin.js +11 -0
- package/plugins/runtime-modules/core/widgets/simple-text/server.js +11 -1
- package/plugins/runtime-modules/core/widgets.js +17 -0
- package/plugins/runtime-modules/public/presets.d.ts +16 -0
- package/plugins/runtime-modules/public/presets.js +22 -0
- package/plugins/runtime-modules/public-base-page-references.d.ts +1 -0
- package/plugins/runtime-modules/public-base-page-references.js +1 -0
- package/plugins/runtime-modules/search-page-references.d.ts +20 -0
- package/plugins/runtime-modules/search-page-references.js +35 -0
- package/plugins/runtime-modules/search-page-tree.d.ts +14 -0
- package/plugins/runtime-modules/search-page-tree.js +63 -0
- package/server-helpers/search-index.d.ts +28 -0
- package/server-helpers/search-index.js +299 -0
- package/server-helpers/search-text.d.ts +40 -0
- package/server-helpers/search-text.js +152 -0
- package/server-helpers.d.ts +1 -0
- package/server-helpers.js +1 -0
- package/styles/controls.css +108 -10
- package/styles/layout.css +35 -0
- package/styles/shell.css +142 -0
- package/theme/phi-tokens.d.ts +6 -0
- package/theme/phi-tokens.js +6 -0
- package/theme.d.ts +1 -0
- package/theme.js +6 -0
- package/types/cms-plugins.d.ts +20 -2
- package/types/core-widget-placements.d.ts +5 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { Fragment, useEffect, useMemo } from "react";
|
|
3
|
+
import { Fragment, useEffect, useMemo, useState } from "react";
|
|
4
|
+
import { PhiProtectedMailText } from "../../navigation/use-phi-protected-mail";
|
|
4
5
|
import { PhiLink } from "../../navigation/phi-link";
|
|
5
6
|
import { PHI_SIGNAL_VALUE_SCHEMAS } from "../../../types/signals";
|
|
6
7
|
import { usePhiSignalEmitter } from "../../runtime/runtime-signal-identity";
|
|
@@ -11,6 +12,10 @@ import { PhiPlainTable } from "../../tables/phi-plain-table";
|
|
|
11
12
|
import { PhiTypographyControl } from "../../controls/phi-typography-control";
|
|
12
13
|
import { PhiDividerControl } from "../../controls/phi-divider-control";
|
|
13
14
|
import { PhiBulletListControl } from "../../controls/phi-bullet-list-control";
|
|
15
|
+
import { PhiImageControl } from "../../controls/phi-image-control";
|
|
16
|
+
import { PhiCollapseControl } from "../../controls/phi-collapse-control";
|
|
17
|
+
import { resolvePhiMarkdownFoldLevel, splitPhiMarkdownSegments, } from "./markdown-sections";
|
|
18
|
+
import { resolvePhiMarkdownFigureSizes } from "./markdown-image-vocabulary";
|
|
14
19
|
import { resolvePhiBulletListStyle, } from "./bullet-list-vocabulary";
|
|
15
20
|
/**
|
|
16
21
|
* The colour a kind of code is drawn in, from the Theme and from nowhere else.
|
|
@@ -51,6 +56,8 @@ function renderInlineNodes(inlines) {
|
|
|
51
56
|
switch (inline.kind) {
|
|
52
57
|
case "text":
|
|
53
58
|
return _jsx(Fragment, { children: inline.text }, key);
|
|
59
|
+
case "mail_text":
|
|
60
|
+
return _jsx(PhiProtectedMailText, { token: inline.token }, key);
|
|
54
61
|
case "strong":
|
|
55
62
|
return _jsx("strong", { children: renderInlineNodes(inline.children) }, key);
|
|
56
63
|
case "emphasis":
|
|
@@ -83,6 +90,8 @@ function renderBlocks(blocks, token, paragraphStyle, headingStyle, lists, atStar
|
|
|
83
90
|
return (_jsx(PhiTypographyControl, { presentation: "title", id: block.id, level: block.level, style: headingBlockStyle, children: renderInlineNodes(block.inlines) }, key));
|
|
84
91
|
case "paragraph":
|
|
85
92
|
return (_jsx(PhiTypographyControl, { presentation: "paragraph", style: paragraphBlockStyle, children: renderInlineNodes(block.inlines) }, key));
|
|
93
|
+
case "image":
|
|
94
|
+
return _jsx(PhiMarkdownFigureBlock, { figure: block.image }, key);
|
|
86
95
|
case "blockquote":
|
|
87
96
|
return (_jsx("blockquote", { style: {
|
|
88
97
|
margin: 0,
|
|
@@ -186,6 +195,7 @@ export function PhiMarkdownWidgetClient({ config }) {
|
|
|
186
195
|
paddingBlockStart: resolvePhiSpacingScaleValue(config?.headingBlockSpacingBefore ?? "sm"),
|
|
187
196
|
marginBlockEnd: resolvePhiSpacingScaleValue(config?.headingBlockSpacingAfter ?? "sm"),
|
|
188
197
|
};
|
|
198
|
+
const lists = { style: resolvePhiBulletListStyle(config?.list), depth: 1 };
|
|
189
199
|
return (_jsx("div", { className: config?.imageFloat
|
|
190
200
|
? `phi-markdown-text phi-markdown-body phi-markdown-body--float-${config.imageFloat}`
|
|
191
201
|
: "phi-markdown-text",
|
|
@@ -193,8 +203,53 @@ export function PhiMarkdownWidgetClient({ config }) {
|
|
|
193
203
|
// browser's `normal`, and its marker centres on a line shorter than the one its words stand on.
|
|
194
204
|
style: config?.imageFloat
|
|
195
205
|
? { display: "flow-root", width: "100%", textAlign: config.textAlign, containerType: "inline-size", lineHeight: token.lineHeight }
|
|
196
|
-
: { display: "grid", gap: 0, width: "100%", textAlign: config?.textAlign, lineHeight: token.lineHeight }, children:
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
206
|
+
: { display: "grid", gap: 0, width: "100%", textAlign: config?.textAlign, lineHeight: token.lineHeight }, children: config?.foldSections && config.foldSections !== "none"
|
|
207
|
+
? splitPhiMarkdownSegments(blocks, resolvePhiMarkdownFoldLevel(config.headingOffset)).map((segment, index) => segment.kind === "text"
|
|
208
|
+
? _jsx(Fragment, { children: renderBlocks(segment.blocks, token, paragraphBlockStyle, headingBlockStyle, lists, index === 0) }, `text-${index}`)
|
|
209
|
+
: (_jsx(PhiMarkdownFoldedSections, { sections: segment.sections, accordion: config.foldSections === "accordion", renderBody: (sectionBlocks) => renderBlocks(sectionBlocks, token, paragraphBlockStyle, headingBlockStyle, lists, true) }, `sections-${index}`)))
|
|
210
|
+
: renderBlocks(blocks, token, paragraphBlockStyle, headingBlockStyle, lists, true) }));
|
|
211
|
+
}
|
|
212
|
+
/*
|
|
213
|
+
* The sections that fold: each heading is a header, what follows it the body. Every answer is drawn even
|
|
214
|
+
* while folded, so a search engine and the browser's own find read the whole text. A heading keeps its id,
|
|
215
|
+
* so the table of contents and a link to `#that-question` reach it -- and a link to it opens it, on arrival
|
|
216
|
+
* and whenever the address's fragment changes.
|
|
217
|
+
*/
|
|
218
|
+
function PhiMarkdownFoldedSections({ sections, accordion, renderBody, }) {
|
|
219
|
+
const [openKeys, setOpenKeys] = useState([]);
|
|
220
|
+
useEffect(() => {
|
|
221
|
+
const openFromAddress = () => {
|
|
222
|
+
const id = decodeURIComponent(window.location.hash.slice(1));
|
|
223
|
+
if (!id)
|
|
224
|
+
return;
|
|
225
|
+
const section = sections.find((entry) => entry.heading.id === id || entry.blocks.some((block) => block.kind === "heading" && block.id === id));
|
|
226
|
+
if (!section)
|
|
227
|
+
return;
|
|
228
|
+
setOpenKeys((current) => accordion ? [section.heading.id] : [...new Set([...current, section.heading.id])]);
|
|
229
|
+
window.requestAnimationFrame(() => document.getElementById(id)?.scrollIntoView({ block: "start" }));
|
|
230
|
+
};
|
|
231
|
+
openFromAddress();
|
|
232
|
+
window.addEventListener("hashchange", openFromAddress);
|
|
233
|
+
return () => window.removeEventListener("hashchange", openFromAddress);
|
|
234
|
+
}, [accordion, sections]);
|
|
235
|
+
return (_jsx("div", { className: "phi-markdown-folds", children: _jsx(PhiCollapseControl, { sections: sections.map((section) => ({
|
|
236
|
+
key: section.heading.id,
|
|
237
|
+
label: (_jsx(PhiTypographyControl, { presentation: "title", id: section.heading.id, level: section.heading.level, style: { margin: 0 }, children: renderInlineNodes(section.heading.inlines) })),
|
|
238
|
+
children: renderBody(section.blocks),
|
|
239
|
+
forceRender: true,
|
|
240
|
+
})), openKeys: openKeys, onOpenKeysChange: setOpenKeys, accordion: accordion,
|
|
241
|
+
// A question is answered wherever its row is clicked, not only on its words.
|
|
242
|
+
collapsible: "row", ghost: true, expandIconPlacement: "end",
|
|
243
|
+
// Flush with the text around them: a question starts where a paragraph starts.
|
|
244
|
+
headerPadding: `${PHI_SPACE.sm} 0`, bodyPadding: `0 0 ${PHI_SPACE.sm}` }) }));
|
|
245
|
+
}
|
|
246
|
+
/*
|
|
247
|
+
* A picture standing on its own: a figure, so it is a block between the paragraphs and never a box inside
|
|
248
|
+
* one. The box is reserved from the start -- the chosen proportion, else the picture's own -- so the text
|
|
249
|
+
* does not jump when the bytes arrive, and its corners are the Theme's surface step (`styles/controls.css`).
|
|
250
|
+
*/
|
|
251
|
+
function PhiMarkdownFigureBlock({ figure }) {
|
|
252
|
+
const { presentation } = figure;
|
|
253
|
+
const ownRatio = presentation.width && presentation.height ? `${presentation.width} / ${presentation.height}` : undefined;
|
|
254
|
+
return (_jsx("figure", { className: `phi-markdown-figure phi-markdown-figure--float-${figure.float}`, children: _jsx("div", { className: "phi-markdown-figure__frame", style: { aspectRatio: figure.aspectRatio ?? ownRatio }, children: _jsx(PhiImageControl, { presentation: presentation, source: "asset", alt: figure.alt, title: figure.title, blurDataUrl: figure.blurDataUrl, optimizable: figure.optimizable, sizes: resolvePhiMarkdownFigureSizes(figure.float), style: { width: "100%", height: "100%" }, imageStyle: { width: "100%", height: "100%" } }) }) }));
|
|
200
255
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How tall a picture stands, as a proportion of its width. `auto` is the picture's own proportion -- a text
|
|
3
|
+
* shows what was put in it; a step crops into that box around the picture's focal rectangle. `phi` is the
|
|
4
|
+
* golden rectangle, φ : 1 (`PHI_GOLDEN_RATIO`), between 3:2 and 16:9.
|
|
5
|
+
*/
|
|
6
|
+
export declare const PHI_MARKDOWN_IMAGE_ASPECT_RATIOS: readonly ["auto", "phi", "3:2", "4:3", "16:9", "2:1", "1:1"];
|
|
7
|
+
export type PhiMarkdownImageAspectRatio = (typeof PHI_MARKDOWN_IMAGE_ASPECT_RATIOS)[number];
|
|
8
|
+
/** Where a picture stands: at an edge with the text flowing past it, or on a line of its own (`none`). */
|
|
9
|
+
export declare const PHI_MARKDOWN_FIGURE_FLOATS: readonly ["start", "end", "none"];
|
|
10
|
+
export type PhiMarkdownFigureFloat = (typeof PHI_MARKDOWN_FIGURE_FLOATS)[number];
|
|
11
|
+
export declare function readPhiMarkdownImageAspectRatio(value: unknown): PhiMarkdownImageAspectRatio | undefined;
|
|
12
|
+
/** A step as a number, width over height; `auto` has none -- the picture decides. */
|
|
13
|
+
export declare function resolvePhiMarkdownImageAspectRatioValue(ratio: PhiMarkdownImageAspectRatio | undefined): number | null;
|
|
14
|
+
/** A step as CSS writes it (`16 / 9`); `auto` has none. */
|
|
15
|
+
export declare function resolvePhiMarkdownImageAspectRatioCss(ratio: PhiMarkdownImageAspectRatio | undefined): string | null;
|
|
16
|
+
/**
|
|
17
|
+
* A picture's address read apart: the reference, and what the picture says for itself. Only `ratio` and
|
|
18
|
+
* `float` are read; anything else after the `?` is left out of the reference and ignored, so an address a
|
|
19
|
+
* later release learns more words for still names its Asset today.
|
|
20
|
+
*/
|
|
21
|
+
export declare function readPhiMarkdownImageAddress(url: string): {
|
|
22
|
+
reference: string;
|
|
23
|
+
aspectRatio?: PhiMarkdownImageAspectRatio;
|
|
24
|
+
float?: PhiMarkdownFigureFloat;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* How wide a picture is drawn, for the image optimiser: beside the text its golden share of the column
|
|
28
|
+
* (`styles/controls.css`, about 0.38 of a reading column of at most 1120 px), on a line of its own the
|
|
29
|
+
* reading column's.
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolvePhiMarkdownFigureSizes(float: PhiMarkdownFigureFloat): "(max-width: 768px) 100vw, 1120px" | "(max-width: 560px) 100vw, 440px";
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* How a Markdown text sets its pictures, apart from the Widget's Client half: the render on the server and
|
|
3
|
+
* the Widget's definition read these, and a value imported from the Client file would make it a client
|
|
4
|
+
* reference of every route.
|
|
5
|
+
*
|
|
6
|
+
* Two places say it, and the nearer one wins. The Widget states what every picture in its text does -- the
|
|
7
|
+
* Inspector's "Image proportion" and "Image Float" -- and a picture that needs something else says so in its
|
|
8
|
+
* own address, after the Asset: ``. The address stays a
|
|
9
|
+
* `phis:asset/<id>` reference for everything that reads one (the server's reference index finds the id at
|
|
10
|
+
* its start), and it is plain Markdown, so a translation carries it through untouched.
|
|
11
|
+
*/
|
|
12
|
+
import { PHI_GOLDEN_RATIO } from "../../../theme/phi-tokens";
|
|
13
|
+
/**
|
|
14
|
+
* How tall a picture stands, as a proportion of its width. `auto` is the picture's own proportion -- a text
|
|
15
|
+
* shows what was put in it; a step crops into that box around the picture's focal rectangle. `phi` is the
|
|
16
|
+
* golden rectangle, φ : 1 (`PHI_GOLDEN_RATIO`), between 3:2 and 16:9.
|
|
17
|
+
*/
|
|
18
|
+
export const PHI_MARKDOWN_IMAGE_ASPECT_RATIOS = ["auto", "phi", "3:2", "4:3", "16:9", "2:1", "1:1"];
|
|
19
|
+
/** Where a picture stands: at an edge with the text flowing past it, or on a line of its own (`none`). */
|
|
20
|
+
export const PHI_MARKDOWN_FIGURE_FLOATS = ["start", "end", "none"];
|
|
21
|
+
export function readPhiMarkdownImageAspectRatio(value) {
|
|
22
|
+
return PHI_MARKDOWN_IMAGE_ASPECT_RATIOS.find((ratio) => ratio === value);
|
|
23
|
+
}
|
|
24
|
+
function readPhiMarkdownFigureFloat(value) {
|
|
25
|
+
return PHI_MARKDOWN_FIGURE_FLOATS.find((float) => float === value);
|
|
26
|
+
}
|
|
27
|
+
/** A step as a number, width over height; `auto` has none -- the picture decides. */
|
|
28
|
+
export function resolvePhiMarkdownImageAspectRatioValue(ratio) {
|
|
29
|
+
if (ratio == null || ratio === "auto")
|
|
30
|
+
return null;
|
|
31
|
+
if (ratio === "phi")
|
|
32
|
+
return PHI_GOLDEN_RATIO;
|
|
33
|
+
const [width, height] = ratio.split(":").map(Number);
|
|
34
|
+
return width / height;
|
|
35
|
+
}
|
|
36
|
+
/** A step as CSS writes it (`16 / 9`); `auto` has none. */
|
|
37
|
+
export function resolvePhiMarkdownImageAspectRatioCss(ratio) {
|
|
38
|
+
const value = resolvePhiMarkdownImageAspectRatioValue(ratio);
|
|
39
|
+
if (value == null)
|
|
40
|
+
return null;
|
|
41
|
+
return ratio === "phi" ? `${PHI_GOLDEN_RATIO.toFixed(6)} / 1` : ratio.replace(":", " / ");
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A picture's address read apart: the reference, and what the picture says for itself. Only `ratio` and
|
|
45
|
+
* `float` are read; anything else after the `?` is left out of the reference and ignored, so an address a
|
|
46
|
+
* later release learns more words for still names its Asset today.
|
|
47
|
+
*/
|
|
48
|
+
export function readPhiMarkdownImageAddress(url) {
|
|
49
|
+
const question = url.indexOf("?");
|
|
50
|
+
if (question < 0)
|
|
51
|
+
return { reference: url };
|
|
52
|
+
const params = new URLSearchParams(url.slice(question + 1));
|
|
53
|
+
const aspectRatio = readPhiMarkdownImageAspectRatio(params.get("ratio"));
|
|
54
|
+
const float = readPhiMarkdownFigureFloat(params.get("float"));
|
|
55
|
+
return {
|
|
56
|
+
reference: url.slice(0, question),
|
|
57
|
+
...(aspectRatio ? { aspectRatio } : {}),
|
|
58
|
+
...(float ? { float } : {}),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* How wide a picture is drawn, for the image optimiser: beside the text its golden share of the column
|
|
63
|
+
* (`styles/controls.css`, about 0.38 of a reading column of at most 1120 px), on a line of its own the
|
|
64
|
+
* reading column's.
|
|
65
|
+
*/
|
|
66
|
+
export function resolvePhiMarkdownFigureSizes(float) {
|
|
67
|
+
return float === "none" ? "(max-width: 768px) 100vw, 1120px" : "(max-width: 560px) 100vw, 440px";
|
|
68
|
+
}
|
|
@@ -2,6 +2,8 @@ import type { PhiBlockRuntime, PhiRenderableBlockRenderMode } from "../../../typ
|
|
|
2
2
|
import type { PhiCmsResolvedContent } from "../../../types/cms";
|
|
3
3
|
import type { PhiMarkdownTocHeading } from "../../../types/markdown";
|
|
4
4
|
import type { PhiMarkdownBlock } from "./markdown-body-client";
|
|
5
|
+
import type { PhiMarkdownImageFloat } from "../../../types/core-widget-placements";
|
|
6
|
+
import { type PhiMarkdownImageAspectRatio } from "./markdown-image-vocabulary";
|
|
5
7
|
/**
|
|
6
8
|
* Where Markdown comes from and how it is turned into blocks: inline text, a stored content field, or a
|
|
7
9
|
* document fetched by URL, translated or not, with heading ids under a prefix of its own.
|
|
@@ -32,6 +34,9 @@ export type PhiMarkdownSourceConfig = {
|
|
|
32
34
|
* header -- starts at `h2`, so `#` does not draw a second title of the same size. The level stops at 5.
|
|
33
35
|
*/
|
|
34
36
|
headingOffset?: number;
|
|
37
|
+
/** What every picture in the text does, unless its own address says otherwise (`markdown-image-vocabulary.ts`). */
|
|
38
|
+
imageAspectRatio?: PhiMarkdownImageAspectRatio;
|
|
39
|
+
imageFloat?: PhiMarkdownImageFloat;
|
|
35
40
|
};
|
|
36
41
|
export type MarkdownRenderData = {
|
|
37
42
|
blocks: PhiMarkdownBlock[];
|
|
@@ -3,9 +3,13 @@ import { unified } from "unified";
|
|
|
3
3
|
import remarkParse from "remark-parse";
|
|
4
4
|
import remarkGfm from "remark-gfm";
|
|
5
5
|
import { trBulk, trBulkForLocale } from "../../../server-helpers/translate";
|
|
6
|
+
import { resolvePhiImagePresentation } from "../../media/image-presentation";
|
|
7
|
+
import { isPhiMediaSvgContentType } from "../../../constants/media";
|
|
8
|
+
import { readPhiMarkdownImageAddress, resolvePhiMarkdownImageAspectRatioCss, resolvePhiMarkdownImageAspectRatioValue, } from "./markdown-image-vocabulary";
|
|
6
9
|
import { resolvePhiCodeLanguage, tokenizePhiCode } from "./markdown-code-tokens";
|
|
7
10
|
import { readPhiInternalReference } from "../../../types/references";
|
|
8
11
|
import { resolvePhiWidgetInternalReferences } from "../helpers/internal-reference-resolver.server";
|
|
12
|
+
import { protectPhiMailHref, splitPhiMailAddresses } from "../../../helpers/protected-mail";
|
|
9
13
|
import { resolvePhiWidgetSourceUrl } from "../helpers/widget-source-url";
|
|
10
14
|
const MARKDOWN_DEFAULT_REVALIDATE_SECONDS = 14400;
|
|
11
15
|
function normalizeMarkdownSourceUrl(sourceUrl, publicUrl) {
|
|
@@ -107,10 +111,11 @@ function projectExternalMarkdownNodes(nodes, sourceUrl, pageUrl = readExternalDo
|
|
|
107
111
|
async function projectInternalMarkdownNodes(tree, runtime) {
|
|
108
112
|
const pageReferences = [];
|
|
109
113
|
const assetIds = [];
|
|
114
|
+
const figures = new Map();
|
|
110
115
|
const collect = (nodes) => {
|
|
111
116
|
for (const node of nodes ?? []) {
|
|
112
117
|
if (node.type === "link" || node.type === "image") {
|
|
113
|
-
const reference = readPhiInternalReference(node.url);
|
|
118
|
+
const reference = readPhiInternalReference(node.type === "image" ? readPhiMarkdownImageAddress(node.url ?? "").reference : node.url);
|
|
114
119
|
if (reference?.kind === "page")
|
|
115
120
|
pageReferences.push(reference.reference);
|
|
116
121
|
if (reference?.kind === "asset")
|
|
@@ -134,10 +139,23 @@ async function projectInternalMarkdownNodes(tree, runtime) {
|
|
|
134
139
|
return [{ ...node, children }];
|
|
135
140
|
}
|
|
136
141
|
if (node.type === "image") {
|
|
137
|
-
const
|
|
142
|
+
const address = readPhiMarkdownImageAddress(node.url ?? "");
|
|
143
|
+
const reference = readPhiInternalReference(address.reference);
|
|
138
144
|
if (reference?.kind === "asset") {
|
|
139
|
-
const
|
|
140
|
-
|
|
145
|
+
const asset = resolved.assets.get(reference.assetId);
|
|
146
|
+
if (!asset)
|
|
147
|
+
return [];
|
|
148
|
+
/*
|
|
149
|
+
* Each picture gets an address of its own, so two pictures of one Asset can say different things:
|
|
150
|
+
* the fragment never reaches the server, and it travels with the address through a translation.
|
|
151
|
+
*/
|
|
152
|
+
const src = `${asset.deliveryUrl}#phi-figure-${figures.size}`;
|
|
153
|
+
figures.set(src, {
|
|
154
|
+
asset,
|
|
155
|
+
...(address.aspectRatio ? { aspectRatio: address.aspectRatio } : {}),
|
|
156
|
+
...(address.float ? { float: address.float } : {}),
|
|
157
|
+
});
|
|
158
|
+
return [{ ...node, url: src, children }];
|
|
141
159
|
}
|
|
142
160
|
if (!/^https?:/iu.test(node.url ?? "") && !PHI_INLINE_IMAGE_DATA_URL.test(node.url ?? ""))
|
|
143
161
|
return [];
|
|
@@ -146,6 +164,57 @@ async function projectInternalMarkdownNodes(tree, runtime) {
|
|
|
146
164
|
return [{ ...node, ...(node.children ? { children } : {}) }];
|
|
147
165
|
});
|
|
148
166
|
tree.children = project(tree.children);
|
|
167
|
+
return figures;
|
|
168
|
+
}
|
|
169
|
+
/*
|
|
170
|
+
* A paragraph that is one Media picture and nothing else is a figure: a block of its own, drawn by the
|
|
171
|
+
* house's picture Control -- optimised, sized, its box reserved and its corners the Theme's. A picture in
|
|
172
|
+
* the middle of a sentence, or one on somebody else's server, stays the plain picture it was.
|
|
173
|
+
*/
|
|
174
|
+
function promoteMarkdownFigures(blocks, figures, defaults) {
|
|
175
|
+
if (figures.size === 0)
|
|
176
|
+
return blocks;
|
|
177
|
+
return blocks.map((block) => {
|
|
178
|
+
if (block.kind === "blockquote")
|
|
179
|
+
return { ...block, children: promoteMarkdownFigures(block.children, figures, defaults) };
|
|
180
|
+
if (block.kind === "list")
|
|
181
|
+
return { ...block, items: block.items.map((item) => promoteMarkdownFigures(item, figures, defaults)) };
|
|
182
|
+
if (block.kind !== "paragraph")
|
|
183
|
+
return block;
|
|
184
|
+
const content = block.inlines.filter((inline) => !(inline.kind === "text" && !inline.text.trim()));
|
|
185
|
+
const only = content.length === 1 ? content[0] : null;
|
|
186
|
+
const source = only?.kind === "image" ? figures.get(only.src) : undefined;
|
|
187
|
+
if (!only || only.kind !== "image" || !source)
|
|
188
|
+
return block;
|
|
189
|
+
return { kind: "image", image: buildMarkdownFigure(only, source, defaults) };
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function buildMarkdownFigure(image, source, defaults) {
|
|
193
|
+
const aspectRatio = source.aspectRatio ?? defaults.aspectRatio ?? "auto";
|
|
194
|
+
const frameAspectRatio = resolvePhiMarkdownImageAspectRatioValue(aspectRatio);
|
|
195
|
+
const { asset } = source;
|
|
196
|
+
const presentation = resolvePhiImagePresentation({
|
|
197
|
+
sourceKind: "asset",
|
|
198
|
+
assetId: asset.id,
|
|
199
|
+
variantKey: null,
|
|
200
|
+
variantVersion: asset.variantVersion,
|
|
201
|
+
deliveryRevision: asset.deliveryRevision,
|
|
202
|
+
originalUrl: asset.deliveryUrl,
|
|
203
|
+
focalRect: asset.focalRect,
|
|
204
|
+
sourceWidth: asset.width,
|
|
205
|
+
sourceHeight: asset.height,
|
|
206
|
+
frameAspectRatio,
|
|
207
|
+
});
|
|
208
|
+
return {
|
|
209
|
+
presentation,
|
|
210
|
+
alt: (image.alt || asset.altText || "").trim(),
|
|
211
|
+
...(image.title ? { title: image.title } : {}),
|
|
212
|
+
blurDataUrl: asset.blurDataUrl,
|
|
213
|
+
// Only a public Asset resolves here; the optimiser takes every original that is not an SVG.
|
|
214
|
+
optimizable: !isPhiMediaSvgContentType(asset.contentType),
|
|
215
|
+
aspectRatio: resolvePhiMarkdownImageAspectRatioCss(aspectRatio),
|
|
216
|
+
float: source.float ?? defaults.float ?? "none",
|
|
217
|
+
};
|
|
149
218
|
}
|
|
150
219
|
function mapInlineNodes(nodes) {
|
|
151
220
|
return (nodes ?? []).flatMap((node) => {
|
|
@@ -517,20 +586,24 @@ export async function resolveMarkdownRenderData(config, runtime) {
|
|
|
517
586
|
*/
|
|
518
587
|
config?.sourceLocale?.trim() || undefined, sourceMode, sourceMode === "url" && config?.sourceUrl
|
|
519
588
|
? normalizeMarkdownSourceUrl(config.sourceUrl, runtime?.site.publicUrl)
|
|
520
|
-
: null, runtime, config?.extent ?? "document", config?.headingOffset ?? 0
|
|
589
|
+
: null, runtime, config?.extent ?? "document", config?.headingOffset ?? 0, {
|
|
590
|
+
...(config?.imageAspectRatio ? { aspectRatio: config.imageAspectRatio } : {}),
|
|
591
|
+
...(config?.imageFloat ? { float: config.imageFloat } : {}),
|
|
592
|
+
});
|
|
521
593
|
}
|
|
522
|
-
async function resolveMarkdownRenderDataFromSource(markdown, translate, headingIdPrefix, sourceLocale, sourceMode = "inline", sourceUrl = null, runtime, extent = "document", headingOffset = 0) {
|
|
594
|
+
async function resolveMarkdownRenderDataFromSource(markdown, translate, headingIdPrefix, sourceLocale, sourceMode = "inline", sourceUrl = null, runtime, extent = "document", headingOffset = 0, imageDefaults = {}) {
|
|
523
595
|
const tree = parseMarkdown(markdown);
|
|
524
596
|
if (extent === "first-paragraph") {
|
|
525
597
|
// Cut by the parser's own reading, never by blank lines: a fence or a list may hold those too.
|
|
526
598
|
const paragraph = tree.children?.find((node) => node.type === "paragraph");
|
|
527
599
|
tree.children = paragraph ? [paragraph] : [];
|
|
528
600
|
}
|
|
601
|
+
let figures = new Map();
|
|
529
602
|
if (sourceMode === "url" && sourceUrl) {
|
|
530
603
|
tree.children = projectExternalMarkdownNodes(tree.children, sourceUrl);
|
|
531
604
|
}
|
|
532
605
|
else if (runtime) {
|
|
533
|
-
await projectInternalMarkdownNodes(tree, runtime);
|
|
606
|
+
figures = await projectInternalMarkdownNodes(tree, runtime);
|
|
534
607
|
}
|
|
535
608
|
const context = {
|
|
536
609
|
headings: [],
|
|
@@ -539,7 +612,7 @@ async function resolveMarkdownRenderDataFromSource(markdown, translate, headingI
|
|
|
539
612
|
headingOffset,
|
|
540
613
|
};
|
|
541
614
|
const inlineMap = await buildMarkdownInlineMap(tree, translate, sourceLocale, runtime?.locale.current);
|
|
542
|
-
const blocks = mapBlockNodes(tree.children, context, inlineMap);
|
|
615
|
+
const blocks = promoteMarkdownFigures(protectMarkdownMail(mapBlockNodes(tree.children, context, inlineMap)), figures, imageDefaults);
|
|
543
616
|
return { blocks, headings: context.headings };
|
|
544
617
|
}
|
|
545
618
|
/** remark-gfm states `left`, `center`, `right` or nothing; nothing else can come out of its parser. */
|
|
@@ -552,3 +625,45 @@ function readMarkdownTableAlign(value) {
|
|
|
552
625
|
}
|
|
553
626
|
throw new Error(`Unknown Markdown table alignment "${value}".`);
|
|
554
627
|
}
|
|
628
|
+
/*
|
|
629
|
+
* Every address in the finished blocks, protected (`helpers/protected-mail.ts`): a `mailto:` link's
|
|
630
|
+
* target, and an address written as text, a link's own label among them. Once, over the blocks, because
|
|
631
|
+
* they are built along two roads -- straight from the tree and back out of a translation.
|
|
632
|
+
*/
|
|
633
|
+
function protectMarkdownMail(blocks) {
|
|
634
|
+
return blocks.map((block) => {
|
|
635
|
+
switch (block.kind) {
|
|
636
|
+
case "heading":
|
|
637
|
+
case "paragraph":
|
|
638
|
+
return { ...block, inlines: protectMarkdownInlineMail(block.inlines) };
|
|
639
|
+
case "blockquote":
|
|
640
|
+
return { ...block, children: protectMarkdownMail(block.children) };
|
|
641
|
+
case "list":
|
|
642
|
+
return { ...block, items: block.items.map(protectMarkdownMail) };
|
|
643
|
+
case "table":
|
|
644
|
+
return {
|
|
645
|
+
...block,
|
|
646
|
+
header: block.header.map(protectMarkdownInlineMail),
|
|
647
|
+
rows: block.rows.map((cells) => cells.map(protectMarkdownInlineMail)),
|
|
648
|
+
};
|
|
649
|
+
default:
|
|
650
|
+
return block;
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
function protectMarkdownInlineMail(inlines) {
|
|
655
|
+
return inlines.flatMap((inline) => {
|
|
656
|
+
switch (inline.kind) {
|
|
657
|
+
case "text":
|
|
658
|
+
return splitPhiMailAddresses(inline.text).map((segment) => segment.kind === "mail" ? { kind: "mail_text", token: segment.token } : { kind: "text", text: segment.text });
|
|
659
|
+
case "link":
|
|
660
|
+
return [{ ...inline, href: protectPhiMailHref(inline.href), children: protectMarkdownInlineMail(inline.children) }];
|
|
661
|
+
case "strong":
|
|
662
|
+
case "emphasis":
|
|
663
|
+
case "delete":
|
|
664
|
+
return [{ ...inline, children: protectMarkdownInlineMail(inline.children) }];
|
|
665
|
+
default:
|
|
666
|
+
return [inline];
|
|
667
|
+
}
|
|
668
|
+
});
|
|
669
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { PhiMarkdownBlock } from "./markdown-body-client";
|
|
2
|
+
/** Whether the text's sections fold, and how: each on its own, or one open at a time. */
|
|
3
|
+
export declare const PHI_MARKDOWN_FOLD_SECTIONS: readonly ["none", "independent", "accordion"];
|
|
4
|
+
export type PhiMarkdownFoldSections = (typeof PHI_MARKDOWN_FOLD_SECTIONS)[number];
|
|
5
|
+
export declare function readPhiMarkdownFoldSections(value: unknown): PhiMarkdownFoldSections | undefined;
|
|
6
|
+
type PhiMarkdownHeadingBlock = Extract<PhiMarkdownBlock, {
|
|
7
|
+
kind: "heading";
|
|
8
|
+
}>;
|
|
9
|
+
export type PhiMarkdownSection = {
|
|
10
|
+
heading: PhiMarkdownHeadingBlock;
|
|
11
|
+
blocks: PhiMarkdownBlock[];
|
|
12
|
+
};
|
|
13
|
+
export type PhiMarkdownSegment = {
|
|
14
|
+
kind: "text";
|
|
15
|
+
blocks: PhiMarkdownBlock[];
|
|
16
|
+
} | {
|
|
17
|
+
kind: "sections";
|
|
18
|
+
sections: PhiMarkdownSection[];
|
|
19
|
+
};
|
|
20
|
+
/** The level that folds: `##` as written, after the text's own offset; a heading never goes below 5. */
|
|
21
|
+
export declare function resolvePhiMarkdownFoldLevel(headingOffset: number | undefined): number;
|
|
22
|
+
/** The text in order: open runs of blocks, and runs of sections that fold. */
|
|
23
|
+
export declare function splitPhiMarkdownSegments(blocks: readonly PhiMarkdownBlock[], level: number): PhiMarkdownSegment[];
|
|
24
|
+
/**
|
|
25
|
+
* The folding sections as schema.org `FAQPage` data: each heading a question, what follows it the answer.
|
|
26
|
+
* Absent when the text has no section with an answer -- an empty FAQ is not a claim worth making.
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildPhiMarkdownFaqStructuredData(blocks: readonly PhiMarkdownBlock[], level: number): {
|
|
29
|
+
"@context": string;
|
|
30
|
+
"@type": string;
|
|
31
|
+
mainEntity: {
|
|
32
|
+
"@type": string;
|
|
33
|
+
name: string;
|
|
34
|
+
acceptedAnswer: {
|
|
35
|
+
"@type": string;
|
|
36
|
+
text: string;
|
|
37
|
+
};
|
|
38
|
+
}[];
|
|
39
|
+
} | null;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* A Markdown text read as sections that fold (`foldSections` on the Markdown Widget): every heading of the
|
|
3
|
+
* text's second level -- `##` as written, moved down with the text's `headingOffset` -- opens a section
|
|
4
|
+
* that runs to the next heading of that level or above. What stands before the first one, and what follows
|
|
5
|
+
* a heading above the level, stays open text. The FAQ case: a question is a `##`, its answer what follows.
|
|
6
|
+
*
|
|
7
|
+
* Pure, and apart from the Client half, because both halves read it: the Client draws the sections, the
|
|
8
|
+
* server writes the same questions and answers as schema.org `FAQPage` data.
|
|
9
|
+
*/
|
|
10
|
+
/** Whether the text's sections fold, and how: each on its own, or one open at a time. */
|
|
11
|
+
export const PHI_MARKDOWN_FOLD_SECTIONS = ["none", "independent", "accordion"];
|
|
12
|
+
export function readPhiMarkdownFoldSections(value) {
|
|
13
|
+
return PHI_MARKDOWN_FOLD_SECTIONS.find((mode) => mode === value);
|
|
14
|
+
}
|
|
15
|
+
/** The level that folds: `##` as written, after the text's own offset; a heading never goes below 5. */
|
|
16
|
+
export function resolvePhiMarkdownFoldLevel(headingOffset) {
|
|
17
|
+
return Math.min(5, 2 + Math.max(0, headingOffset ?? 0));
|
|
18
|
+
}
|
|
19
|
+
/** The text in order: open runs of blocks, and runs of sections that fold. */
|
|
20
|
+
export function splitPhiMarkdownSegments(blocks, level) {
|
|
21
|
+
const segments = [];
|
|
22
|
+
let current = null;
|
|
23
|
+
const textRun = () => {
|
|
24
|
+
const last = segments.at(-1);
|
|
25
|
+
if (last?.kind === "text")
|
|
26
|
+
return last.blocks;
|
|
27
|
+
const run = [];
|
|
28
|
+
segments.push({ kind: "text", blocks: run });
|
|
29
|
+
return run;
|
|
30
|
+
};
|
|
31
|
+
for (const block of blocks) {
|
|
32
|
+
if (block.kind === "heading" && block.level === level) {
|
|
33
|
+
current = { heading: block, blocks: [] };
|
|
34
|
+
const last = segments.at(-1);
|
|
35
|
+
if (last?.kind === "sections")
|
|
36
|
+
last.sections.push(current);
|
|
37
|
+
else
|
|
38
|
+
segments.push({ kind: "sections", sections: [current] });
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (block.kind === "heading" && block.level < level)
|
|
42
|
+
current = null;
|
|
43
|
+
if (current)
|
|
44
|
+
current.blocks.push(block);
|
|
45
|
+
else
|
|
46
|
+
textRun().push(block);
|
|
47
|
+
}
|
|
48
|
+
return segments;
|
|
49
|
+
}
|
|
50
|
+
/** The words of a run of inlines, as a reader would read them aloud; a protected address is left out. */
|
|
51
|
+
function readPhiMarkdownInlineText(inlines) {
|
|
52
|
+
return inlines.map((inline) => {
|
|
53
|
+
switch (inline.kind) {
|
|
54
|
+
case "text":
|
|
55
|
+
case "inline_code":
|
|
56
|
+
return inline.text;
|
|
57
|
+
case "strong":
|
|
58
|
+
case "emphasis":
|
|
59
|
+
case "delete":
|
|
60
|
+
case "link":
|
|
61
|
+
return readPhiMarkdownInlineText(inline.children);
|
|
62
|
+
case "image":
|
|
63
|
+
return inline.alt;
|
|
64
|
+
case "break":
|
|
65
|
+
return "\n";
|
|
66
|
+
default:
|
|
67
|
+
return "";
|
|
68
|
+
}
|
|
69
|
+
}).join("");
|
|
70
|
+
}
|
|
71
|
+
function readPhiMarkdownBlockText(block) {
|
|
72
|
+
switch (block.kind) {
|
|
73
|
+
case "heading":
|
|
74
|
+
case "paragraph":
|
|
75
|
+
return readPhiMarkdownInlineText(block.inlines);
|
|
76
|
+
case "blockquote":
|
|
77
|
+
return block.children.map(readPhiMarkdownBlockText).join("\n");
|
|
78
|
+
case "list":
|
|
79
|
+
return block.items.map((item) => item.map(readPhiMarkdownBlockText).join(" ")).join("\n");
|
|
80
|
+
case "table":
|
|
81
|
+
return [block.header, ...block.rows].map((cells) => cells.map(readPhiMarkdownInlineText).join(" | ")).join("\n");
|
|
82
|
+
case "image":
|
|
83
|
+
return block.image.alt;
|
|
84
|
+
default:
|
|
85
|
+
return "";
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The folding sections as schema.org `FAQPage` data: each heading a question, what follows it the answer.
|
|
90
|
+
* Absent when the text has no section with an answer -- an empty FAQ is not a claim worth making.
|
|
91
|
+
*/
|
|
92
|
+
export function buildPhiMarkdownFaqStructuredData(blocks, level) {
|
|
93
|
+
const questions = splitPhiMarkdownSegments(blocks, level)
|
|
94
|
+
.flatMap((segment) => segment.kind === "sections" ? segment.sections : [])
|
|
95
|
+
.map((section) => ({
|
|
96
|
+
name: readPhiMarkdownInlineText(section.heading.inlines).trim(),
|
|
97
|
+
text: section.blocks.map(readPhiMarkdownBlockText).filter((line) => line.trim()).join("\n").trim(),
|
|
98
|
+
}))
|
|
99
|
+
.filter((entry) => entry.name && entry.text);
|
|
100
|
+
if (questions.length === 0)
|
|
101
|
+
return null;
|
|
102
|
+
return {
|
|
103
|
+
"@context": "https://schema.org",
|
|
104
|
+
"@type": "FAQPage",
|
|
105
|
+
mainEntity: questions.map((entry) => ({
|
|
106
|
+
"@type": "Question",
|
|
107
|
+
name: entry.name,
|
|
108
|
+
acceptedAnswer: { "@type": "Answer", text: entry.text },
|
|
109
|
+
})),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
@@ -47,6 +47,8 @@ export declare const PhiCmsWidgetType: {
|
|
|
47
47
|
readonly VideoEmbed: string;
|
|
48
48
|
readonly TourButton: string;
|
|
49
49
|
readonly Result: string;
|
|
50
|
+
readonly SearchBox: string;
|
|
51
|
+
readonly SearchResults: string;
|
|
50
52
|
readonly Pagination: string;
|
|
51
53
|
readonly Segmented: string;
|
|
52
54
|
readonly SelectBox: string;
|
|
@@ -101,6 +101,8 @@ const PHI_CMS_WIDGET_MODULE_BY_TYPE_KEY = {
|
|
|
101
101
|
"record": "core",
|
|
102
102
|
"rate": "core",
|
|
103
103
|
"result": "core",
|
|
104
|
+
"search-box": "core",
|
|
105
|
+
"search-results": "core",
|
|
104
106
|
"segmented": "core",
|
|
105
107
|
"select-box": "core",
|
|
106
108
|
"sidebar-navigation": "core",
|
|
@@ -175,6 +177,8 @@ export const PhiCmsWidgetType = {
|
|
|
175
177
|
VideoEmbed: defineWidgetType(resolvePhiCmsWidgetPluginKey("video-embed"), "video-embed"),
|
|
176
178
|
TourButton: defineWidgetType(resolvePhiCmsWidgetPluginKey("tour-button"), "tour-button"),
|
|
177
179
|
Result: defineWidgetType(resolvePhiCmsWidgetPluginKey("result"), "result"),
|
|
180
|
+
SearchBox: defineWidgetType(resolvePhiCmsWidgetPluginKey("search-box"), "search-box"),
|
|
181
|
+
SearchResults: defineWidgetType(resolvePhiCmsWidgetPluginKey("search-results"), "search-results"),
|
|
178
182
|
Pagination: defineWidgetType(resolvePhiCmsWidgetPluginKey("pagination"), "pagination"),
|
|
179
183
|
Segmented: defineWidgetType(resolvePhiCmsWidgetPluginKey("segmented"), "segmented"),
|
|
180
184
|
SelectBox: defineWidgetType(resolvePhiCmsWidgetPluginKey("select-box"), "select-box"),
|
package/gateway/site-area.d.ts
CHANGED
|
@@ -15,27 +15,30 @@ export type GetExactSiteAreaOptions = {
|
|
|
15
15
|
sourcePreset: PhiCmsPresetIdentity;
|
|
16
16
|
};
|
|
17
17
|
export declare const getExactSiteArea: (options: GetExactSiteAreaOptions) => Promise<PhiResolvedCmsAreaPresetPayload | null>;
|
|
18
|
-
export type
|
|
18
|
+
export type PhiPublishedPage = {
|
|
19
19
|
path: string | null;
|
|
20
20
|
ownerModuleId: string | null;
|
|
21
21
|
presetKey: string | null;
|
|
22
22
|
revisionId: number;
|
|
23
23
|
publishedAt: string;
|
|
24
24
|
};
|
|
25
|
-
export type
|
|
26
|
-
/** Null while the
|
|
25
|
+
export type PhiAreaWithPublishedPages = {
|
|
26
|
+
/** Null while the Area has never been published; the code-owned preset answers then. */
|
|
27
27
|
area: PhiResolvedCmsAreaPresetPayload | null;
|
|
28
|
-
publishedPages:
|
|
28
|
+
publishedPages: PhiPublishedPage[];
|
|
29
29
|
};
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* A published Area together with its published Pages, as the sitemap and the search index read them.
|
|
32
32
|
*
|
|
33
33
|
* One request for both: the sitemap needs the Area's `index` and `sitemap` switches and the Pages it
|
|
34
34
|
* may list, and the server adds the second to the first on `include=publishedPages`. The Pages are
|
|
35
35
|
* candidates, not answers -- whether one is listed the caller finds out by resolving it. Live and
|
|
36
|
-
* anonymous only, so no cookie is sent and no draft can be asked for.
|
|
36
|
+
* anonymous only, so no cookie is sent and no draft can be asked for. Core answers it for the Public
|
|
37
|
+
* and the App Area, the two anything indexes (SEARCH.md).
|
|
37
38
|
*/
|
|
38
|
-
export declare function
|
|
39
|
+
export declare function getSiteAreaWithPublishedPages({ apiBaseUrl, internalToken, siteKey, locale, sourcePreset, area, }: Pick<GetExactSiteAreaOptions, "apiBaseUrl" | "internalToken" | "siteKey" | "locale" | "sourcePreset"> & {
|
|
40
|
+
area?: "public" | "app";
|
|
41
|
+
}): Promise<PhiAreaWithPublishedPages>;
|
|
39
42
|
type PhiSiteAreaStructureRequest = {
|
|
40
43
|
area: string;
|
|
41
44
|
ownerModuleId: string;
|