mdorigin 0.5.5 → 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
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,
|