mdorigin 0.7.0 → 0.7.1

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.
@@ -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
@@ -26,17 +26,21 @@ export async function parseMarkdownDocument(sourcePath, markdown) {
26
26
  };
27
27
  }
28
28
  export function parseDocumentMeta(sourcePath, markdown) {
29
- const parsed = matter(markdown, {
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: parsed.meta.updated ?? parsed.meta.date,
955
+ lastmod: normalizeSitemapDate(data.updated) ?? normalizeSitemapDate(data.date),
945
956
  });
946
957
  }
947
958
  sitemapEntries.sort((left, right) => left.path.localeCompare(right.path));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdorigin",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "type": "module",
5
5
  "description": "Markdown-first publishing for humans and agents.",
6
6
  "repository": {