reallysimpledocs 1.0.12 → 1.0.14

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reallysimpledocs",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "A simple documentation system for Astro, built with Basecoat and Tailwind CSS.",
5
5
  "author": {
6
6
  "name": "hunvreus",
@@ -63,7 +63,7 @@ const actionItems = [
63
63
 
64
64
  <BaseLayout
65
65
  title={page.title}
66
- description={site.description}
66
+ description={page.description || site.description}
67
67
  pagePath={page.path}
68
68
  >
69
69
  <CommandDialog />
@@ -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
  }
@@ -17,7 +17,7 @@ export function GET({ site }) {
17
17
  const addSlug = (slug) => {
18
18
  const doc = bySlug.get(slug);
19
19
  if (!doc) return;
20
- const url = `${siteUrl}${doc.path}`;
20
+ const url = `${siteUrl}${doc.markdownPath}`;
21
21
  lines.push(`- [${doc.title}](${url})`);
22
22
  };
23
23