mdorigin 0.5.4 → 0.6.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/dist/core/markdown.d.ts +6 -0
- package/dist/core/markdown.js +7 -0
- package/dist/core/request-handler.js +18 -1
- package/dist/html/template.js +28 -10
- package/package.json +1 -1
package/dist/core/markdown.d.ts
CHANGED
|
@@ -9,6 +9,12 @@ export interface ParsedDocumentMeta {
|
|
|
9
9
|
type?: string;
|
|
10
10
|
order?: number;
|
|
11
11
|
aliases?: string[];
|
|
12
|
+
/**
|
|
13
|
+
* Canonical social sharing image for this document, normalized from the
|
|
14
|
+
* `socialImage` frontmatter field, with `image` and `cover` accepted as
|
|
15
|
+
* aliases. Consumers should read this field instead of the raw alias fields.
|
|
16
|
+
*/
|
|
17
|
+
socialImage?: string;
|
|
12
18
|
[key: string]: unknown;
|
|
13
19
|
}
|
|
14
20
|
export interface ManagedIndexEntry {
|
package/dist/core/markdown.js
CHANGED
|
@@ -184,6 +184,13 @@ function normalizeMeta(data) {
|
|
|
184
184
|
if (Array.isArray(data.aliases)) {
|
|
185
185
|
meta.aliases = data.aliases.filter((value) => typeof value === 'string' && value !== '');
|
|
186
186
|
}
|
|
187
|
+
const socialImage = firstNonEmptyString(data.socialImage, data.image, data.cover);
|
|
188
|
+
if (socialImage !== undefined) {
|
|
189
|
+
meta.socialImage = socialImage;
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
delete meta.socialImage;
|
|
193
|
+
}
|
|
187
194
|
return meta;
|
|
188
195
|
}
|
|
189
196
|
function rewriteMarkdownHref(href) {
|
|
@@ -189,6 +189,22 @@ function normalizePositiveInteger(value) {
|
|
|
189
189
|
const parsed = Number.parseInt(value, 10);
|
|
190
190
|
return Number.isInteger(parsed) && parsed > 0 ? parsed : null;
|
|
191
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Dummy absolute base used only to resolve page-relative social image hrefs
|
|
194
|
+
* into site-root-relative paths; the host itself is never emitted.
|
|
195
|
+
*/
|
|
196
|
+
const SOCIAL_IMAGE_RESOLUTION_BASE = 'http://mdorigin.local';
|
|
197
|
+
function resolvePageSocialImage(href, requestPath) {
|
|
198
|
+
if (!href) {
|
|
199
|
+
return undefined;
|
|
200
|
+
}
|
|
201
|
+
if (href.startsWith('/') || /^[a-zA-Z][a-zA-Z\d+.-]*:/.test(href)) {
|
|
202
|
+
return href;
|
|
203
|
+
}
|
|
204
|
+
const directory = requestPath.slice(0, requestPath.lastIndexOf('/') + 1) || '/';
|
|
205
|
+
const resolved = new URL(href, `${SOCIAL_IMAGE_RESOLUTION_BASE}${directory}`);
|
|
206
|
+
return `${resolved.pathname}${resolved.search}${resolved.hash}`;
|
|
207
|
+
}
|
|
192
208
|
function buildPageRenderModel(options) {
|
|
193
209
|
return {
|
|
194
210
|
kind: options.listingEntries.length > 0 ? 'listing' : 'page',
|
|
@@ -200,7 +216,8 @@ function buildPageRenderModel(options) {
|
|
|
200
216
|
siteDescription: options.siteDescription ?? options.siteConfig.siteDescription,
|
|
201
217
|
siteUrl: options.siteConfig.siteUrl,
|
|
202
218
|
favicon: options.siteConfig.favicon,
|
|
203
|
-
socialImage: options.
|
|
219
|
+
socialImage: resolvePageSocialImage(options.parsed.meta.socialImage, options.resolvedRequestPath) ??
|
|
220
|
+
options.siteConfig.socialImage,
|
|
204
221
|
logo: options.siteConfig.logo,
|
|
205
222
|
title: getDocumentTitle(options.parsed),
|
|
206
223
|
meta: options.parsed.meta,
|
package/dist/html/template.js
CHANGED
|
@@ -8,23 +8,41 @@ export function renderDocument(options) {
|
|
|
8
8
|
const siteDescription = options.siteDescription
|
|
9
9
|
? escapeHtml(options.siteDescription)
|
|
10
10
|
: undefined;
|
|
11
|
+
const socialDescription = options.summary ?? options.siteDescription;
|
|
11
12
|
const summaryMeta = options.summary
|
|
12
13
|
? `<meta name="description" content="${escapeHtml(options.summary)}">`
|
|
13
14
|
: '';
|
|
14
|
-
const
|
|
15
|
-
?
|
|
15
|
+
const canonicalUrl = options.siteUrl && options.canonicalPath
|
|
16
|
+
? `${options.siteUrl}${options.canonicalPath}`
|
|
17
|
+
: undefined;
|
|
18
|
+
const canonicalMeta = canonicalUrl
|
|
19
|
+
? `<link rel="canonical" href="${escapeHtml(canonicalUrl)}">`
|
|
16
20
|
: '';
|
|
17
21
|
const faviconMeta = options.favicon
|
|
18
22
|
? `<link rel="icon" href="${escapeHtml(options.favicon)}">`
|
|
19
23
|
: '';
|
|
20
24
|
const absoluteSocialImageUrl = getAbsoluteSiteAssetUrl(options.siteUrl, options.socialImage);
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
const socialMeta = [
|
|
26
|
+
`<meta property="og:title" content="${title}">`,
|
|
27
|
+
socialDescription
|
|
28
|
+
? `<meta property="og:description" content="${escapeHtml(socialDescription)}">`
|
|
29
|
+
: '',
|
|
30
|
+
canonicalUrl
|
|
31
|
+
? `<meta property="og:url" content="${escapeHtml(canonicalUrl)}">`
|
|
32
|
+
: '',
|
|
33
|
+
'<meta property="og:type" content="website">',
|
|
34
|
+
`<meta name="twitter:title" content="${title}">`,
|
|
35
|
+
socialDescription
|
|
36
|
+
? `<meta name="twitter:description" content="${escapeHtml(socialDescription)}">`
|
|
37
|
+
: '',
|
|
38
|
+
absoluteSocialImageUrl
|
|
39
|
+
? [
|
|
40
|
+
`<meta property="og:image" content="${escapeHtml(absoluteSocialImageUrl)}">`,
|
|
41
|
+
'<meta name="twitter:card" content="summary_large_image">',
|
|
42
|
+
`<meta name="twitter:image" content="${escapeHtml(absoluteSocialImageUrl)}">`,
|
|
43
|
+
].join('')
|
|
44
|
+
: '',
|
|
45
|
+
].join('');
|
|
28
46
|
const alternateMarkdownMeta = options.alternateMarkdownPath
|
|
29
47
|
? `<link rel="alternate" type="text/markdown" href="${escapeHtml(options.alternateMarkdownPath)}">`
|
|
30
48
|
: '';
|
|
@@ -133,7 +151,7 @@ export function renderDocument(options) {
|
|
|
133
151
|
summaryMeta,
|
|
134
152
|
canonicalMeta,
|
|
135
153
|
faviconMeta,
|
|
136
|
-
|
|
154
|
+
socialMeta,
|
|
137
155
|
alternateMarkdownMeta,
|
|
138
156
|
rssMeta,
|
|
139
157
|
hreflangMeta,
|