mdorigin 0.7.0 → 0.7.2
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 +3 -0
- package/dist/core/markdown.js +9 -5
- package/dist/core/request-handler.js +14 -3
- package/dist/core/seo.d.ts +6 -1
- package/dist/core/seo.js +15 -5
- package/package.json +1 -1
package/dist/core/markdown.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import matter from 'gray-matter';
|
|
1
2
|
import type { ContentEntry } from './content-store.js';
|
|
2
3
|
import { type PageRobots } from './seo.js';
|
|
3
4
|
export interface ParsedDocumentMeta {
|
|
@@ -53,6 +54,8 @@ export declare function getDocumentTitle(meta: ParsedDocumentMeta, body: string,
|
|
|
53
54
|
export declare function getDocumentSummary(meta: ParsedDocumentMeta, body: string): string | undefined;
|
|
54
55
|
export declare function parseMarkdownDocument(sourcePath: string, markdown: string): Promise<ParsedDocument>;
|
|
55
56
|
export declare function parseDocumentMeta(sourcePath: string, markdown: string): ParsedDocumentLite;
|
|
57
|
+
/** Read original scalar values without applying page metadata normalization. */
|
|
58
|
+
export declare function parseMarkdownFrontmatter(markdown: string): matter.GrayMatterFile<string>;
|
|
56
59
|
/**
|
|
57
60
|
* Parse a store entry's frontmatter metadata, memoized by entry identity.
|
|
58
61
|
* Immutable in-memory stores return the same entry object per path, so
|
package/dist/core/markdown.js
CHANGED
|
@@ -26,17 +26,21 @@ export async function parseMarkdownDocument(sourcePath, markdown) {
|
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
export function parseDocumentMeta(sourcePath, markdown) {
|
|
29
|
-
const parsed =
|
|
30
|
-
engines: {
|
|
31
|
-
yaml: (source) => yaml.safeLoad(source, { schema: FRONTMATTER_SCHEMA }),
|
|
32
|
-
},
|
|
33
|
-
});
|
|
29
|
+
const parsed = parseMarkdownFrontmatter(markdown);
|
|
34
30
|
return {
|
|
35
31
|
sourcePath,
|
|
36
32
|
body: parsed.content,
|
|
37
33
|
meta: normalizeMeta(parsed.data),
|
|
38
34
|
};
|
|
39
35
|
}
|
|
36
|
+
/** Read original scalar values without applying page metadata normalization. */
|
|
37
|
+
export function parseMarkdownFrontmatter(markdown) {
|
|
38
|
+
return matter(markdown, {
|
|
39
|
+
engines: {
|
|
40
|
+
yaml: (source) => yaml.safeLoad(source, { schema: FRONTMATTER_SCHEMA }),
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
40
44
|
const entryDocumentMetaCache = new WeakMap();
|
|
41
45
|
/**
|
|
42
46
|
* Parse a store entry's frontmatter metadata, memoized by entry identity.
|
|
@@ -2,9 +2,9 @@ import path from 'node:path';
|
|
|
2
2
|
import { isIgnoredContentName } from './content-store.js';
|
|
3
3
|
import { inferDirectoryContentType, resolveContentType, } from './content-type.js';
|
|
4
4
|
import { getDirectoryIndexCandidates, isCanonicalContentSource } from './directory-index.js';
|
|
5
|
-
import { extractManagedIndexEntries, getDocumentSummary, getDocumentTitle as getParsedDocumentTitle, parseEntryDocumentMeta, parseMarkdownDocument, stripManagedIndexBlock, stripManagedIndexLinks, stripMachineOnlyMarkdownComments, } from './markdown.js';
|
|
5
|
+
import { extractManagedIndexEntries, getDocumentSummary, getDocumentTitle as getParsedDocumentTitle, parseEntryDocumentMeta, parseMarkdownDocument, parseMarkdownFrontmatter, stripManagedIndexBlock, stripManagedIndexLinks, stripMachineOnlyMarkdownComments, } from './markdown.js';
|
|
6
6
|
import { ensureTrailingSlash, trimLeadingSlash } from './site-url.js';
|
|
7
|
-
import { buildPageStructuredData, serializePageRobots } from './seo.js';
|
|
7
|
+
import { buildPageStructuredData, normalizeContentDate, serializePageRobots } from './seo.js';
|
|
8
8
|
import { resolveSearchCitation } from './search-citations.js';
|
|
9
9
|
import { applyIndexTransforms, renderFooterOverride, renderHeaderOverride, renderPageWithPlugins, transformHtmlWithPlugins, } from './extensions.js';
|
|
10
10
|
import { handleApiRoute } from './api.js';
|
|
@@ -912,6 +912,16 @@ function getDocumentTitle(parsed) {
|
|
|
912
912
|
: basename;
|
|
913
913
|
return getParsedDocumentTitle(parsed.meta, parsed.body, fallback);
|
|
914
914
|
}
|
|
915
|
+
function normalizeSitemapDate(value) {
|
|
916
|
+
if (value instanceof Date) {
|
|
917
|
+
return Number.isNaN(value.getTime()) ? undefined : value.toISOString().slice(0, 10);
|
|
918
|
+
}
|
|
919
|
+
if (typeof value !== 'string')
|
|
920
|
+
return undefined;
|
|
921
|
+
// Keep the author's calendar day, even for legacy timestamps without a timezone.
|
|
922
|
+
const match = /^(\d{4}-\d{2}-\d{2})(?:[ T](?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)?)?$/.exec(value);
|
|
923
|
+
return match ? normalizeContentDate(match[1]) : undefined;
|
|
924
|
+
}
|
|
915
925
|
async function collectSitemapEntries(store, directoryPath, options) {
|
|
916
926
|
const entries = await store.listDirectory(directoryPath);
|
|
917
927
|
if (entries === null) {
|
|
@@ -937,11 +947,12 @@ async function collectSitemapEntries(store, directoryPath, options) {
|
|
|
937
947
|
}
|
|
938
948
|
if (!isCanonicalContentSource(entry.path, availablePaths))
|
|
939
949
|
continue;
|
|
950
|
+
const { data } = parseMarkdownFrontmatter(document.text);
|
|
940
951
|
sitemapEntries.push({
|
|
941
952
|
path: getCanonicalHtmlPathForContentPath(entry.path),
|
|
942
953
|
sourcePath: entry.path,
|
|
943
954
|
title: getDocumentTitle(parsed),
|
|
944
|
-
lastmod:
|
|
955
|
+
lastmod: normalizeSitemapDate(data.updated) ?? normalizeSitemapDate(data.date),
|
|
945
956
|
});
|
|
946
957
|
}
|
|
947
958
|
sitemapEntries.sort((left, right) => left.path.localeCompare(right.path));
|
package/dist/core/seo.d.ts
CHANGED
|
@@ -16,7 +16,12 @@ export interface SiteRobots {
|
|
|
16
16
|
}
|
|
17
17
|
export declare function normalizePageRobots(value: unknown): PageRobots | undefined;
|
|
18
18
|
export declare function serializePageRobots(robots: PageRobots | undefined): string | undefined;
|
|
19
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* ISO calendar dates and timestamps are accepted. Legacy YAML timestamps that spell
|
|
21
|
+
* the date/time separator as a space or a lowercase `t` are normalized to `T`, and
|
|
22
|
+
* timestamps without an explicit timezone are interpreted as UTC so output never
|
|
23
|
+
* depends on the build machine's timezone.
|
|
24
|
+
*/
|
|
20
25
|
export declare function normalizeContentDate(value: unknown): string | undefined;
|
|
21
26
|
export declare function normalizeSiteRobots(value: unknown): SiteRobots | undefined;
|
|
22
27
|
export declare function buildPageStructuredData(input: {
|
package/dist/core/seo.js
CHANGED
|
@@ -56,7 +56,12 @@ export function serializePageRobots(robots) {
|
|
|
56
56
|
parts.push(`max-video-preview:${robots.maxVideoPreview}`);
|
|
57
57
|
return parts.length > 0 ? parts.join(', ') : undefined;
|
|
58
58
|
}
|
|
59
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* ISO calendar dates and timestamps are accepted. Legacy YAML timestamps that spell
|
|
61
|
+
* the date/time separator as a space or a lowercase `t` are normalized to `T`, and
|
|
62
|
+
* timestamps without an explicit timezone are interpreted as UTC so output never
|
|
63
|
+
* depends on the build machine's timezone.
|
|
64
|
+
*/
|
|
60
65
|
export function normalizeContentDate(value) {
|
|
61
66
|
if (value instanceof Date) {
|
|
62
67
|
if (Number.isNaN(value.getTime()))
|
|
@@ -66,16 +71,21 @@ export function normalizeContentDate(value) {
|
|
|
66
71
|
}
|
|
67
72
|
if (typeof value !== 'string')
|
|
68
73
|
return undefined;
|
|
69
|
-
|
|
74
|
+
// Legacy YAML timestamps may spell the ISO date/time separator as a space or a lowercase t.
|
|
75
|
+
const spelling = /^(\d{4}-\d{2}-\d{2})[ t]/.test(value) ? `${value.slice(0, 10)}T${value.slice(11)}` : value;
|
|
76
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})(?:T\d{2}:\d{2}:\d{2}(?:\.\d+)?(Z|[+-]\d{2}:\d{2})?)?$/.exec(spelling);
|
|
70
77
|
if (!match)
|
|
71
78
|
return undefined;
|
|
72
79
|
const day = new Date(`${match[1]}-${match[2]}-${match[3]}T00:00:00Z`);
|
|
73
|
-
if (Number.isNaN(day.getTime()) || day.toISOString().slice(0, 10) !==
|
|
80
|
+
if (Number.isNaN(day.getTime()) || day.toISOString().slice(0, 10) !== spelling.slice(0, 10))
|
|
74
81
|
return undefined;
|
|
75
|
-
|
|
82
|
+
if (spelling.length === 10)
|
|
83
|
+
return spelling;
|
|
84
|
+
// A timestamp without an explicit timezone is interpreted as UTC, never as local time.
|
|
85
|
+
const timestamp = Date.parse(match[4] ? spelling : `${spelling}Z`);
|
|
76
86
|
if (!Number.isFinite(timestamp))
|
|
77
87
|
return undefined;
|
|
78
|
-
return
|
|
88
|
+
return new Date(timestamp).toISOString();
|
|
79
89
|
}
|
|
80
90
|
export function normalizeSiteRobots(value) {
|
|
81
91
|
if (!value || typeof value !== 'object' || !('rules' in value) || !Array.isArray(value.rules)) {
|