reallysimpledocs 1.0.12 → 1.0.13
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/package.json
CHANGED
package/src/runtime/lib/docs.js
CHANGED
|
@@ -67,6 +67,7 @@ export function getPages(config) {
|
|
|
67
67
|
path: routePath(config.routeBase, slug),
|
|
68
68
|
markdownPath: markdownPath(config.routeBase, slug),
|
|
69
69
|
title: parsed.title,
|
|
70
|
+
description: parsed.description,
|
|
70
71
|
};
|
|
71
72
|
});
|
|
72
73
|
}
|
|
@@ -319,23 +320,41 @@ export function getPageItemSlug(item) {
|
|
|
319
320
|
}
|
|
320
321
|
|
|
321
322
|
function parseDocMarkdown(source, fallbackTitle) {
|
|
323
|
+
const frontmatter = parseFrontmatter(source);
|
|
322
324
|
const content = normalizeDocSource(source);
|
|
323
325
|
const tokens = marked.lexer(content);
|
|
324
326
|
const first = tokens[0];
|
|
325
327
|
|
|
326
328
|
if (first?.type !== "heading" || first.depth !== 1) {
|
|
327
329
|
return {
|
|
328
|
-
title: fallbackTitle,
|
|
330
|
+
title: frontmatter.title || fallbackTitle,
|
|
331
|
+
description: frontmatter.description,
|
|
329
332
|
body: content,
|
|
330
333
|
};
|
|
331
334
|
}
|
|
332
335
|
|
|
333
336
|
return {
|
|
334
|
-
title: plainText(first.tokens || []).trim() || fallbackTitle,
|
|
337
|
+
title: frontmatter.title || plainText(first.tokens || []).trim() || fallbackTitle,
|
|
338
|
+
description: frontmatter.description,
|
|
335
339
|
body: content.slice(first.raw.length).trimStart(),
|
|
336
340
|
};
|
|
337
341
|
}
|
|
338
342
|
|
|
343
|
+
function parseFrontmatter(source) {
|
|
344
|
+
const match = String(source || "").trimStart().match(/^---\s*\n([\s\S]*?)\n---\s*(?:\n|$)/);
|
|
345
|
+
if (!match) return {};
|
|
346
|
+
|
|
347
|
+
const values = {};
|
|
348
|
+
for (const line of match[1].split("\n")) {
|
|
349
|
+
const field = line.match(/^([A-Za-z][\w-]*)\s*:\s*(.*)$/);
|
|
350
|
+
if (!field) continue;
|
|
351
|
+
const key = field[1];
|
|
352
|
+
const value = field[2].trim().replace(/^(['"])(.*)\1$/, "$2");
|
|
353
|
+
if (key === "title" || key === "description") values[key] = value;
|
|
354
|
+
}
|
|
355
|
+
return values;
|
|
356
|
+
}
|
|
357
|
+
|
|
339
358
|
function markdownPlainText(markdown) {
|
|
340
359
|
return tokensText(marked.lexer(renderNunjucksCompat(normalizeDocSource(markdown))));
|
|
341
360
|
}
|