فهرست منبع

Refactor index builder

Craig Fletcher 2 هفته پیش
والد
کامیت
e1f244a21c

+ 5 - 4
README.md

@@ -231,6 +231,7 @@ async function myAction({ config, jobConfig, meta }) {
 The following actions are available from `actions`:
 - `compileSass`: Compiles SCSS files to compressed CSS
 - `renderMarkdownToHtml`: Parses markdown into HTML and returns it as task detail
+- `renderMarkdownToMeta`: Parses markdown into frontmatter metadata only
 - `renderTemplate`: Renders Handlebars templates with the current task state
 - `renderIndex`: Renders index pages and index list pages
 - `renderMarkdownWithTemplate`: Renders markdown with Handlebars templates, includes frontmatter support
@@ -259,8 +260,8 @@ The default configuration includes:
    - `favicons`: Generates favicon sets from source images
 
 2. **Sequential tasks:**
-   - `blog-markdown`: Parses blog markdown into HTML detail
-   - `markdown`: Parses general markdown into HTML detail
+   - `blog-markdown`: Parses blog frontmatter metadata (no HTML rendering)
+   - `markdown`: Parses general frontmatter metadata (no HTML rendering)
 
 3. **Parallel processing group:**
    - `author-taxonomy`: Builds author groupings from blog entries
@@ -269,8 +270,8 @@ The default configuration includes:
    - `includes`: Renders template includes to HTML
 
 4. **Parallel processing group:**
-   - `render pages`: Renders standard pages from markdown state
-   - `render blog pages`: Renders blog pages from blog markdown state
+   - `render pages`: Renders standard pages from markdown files
+   - `render blog pages`: Renders blog pages from blog markdown files
    - `render author indexes`: Renders author index pages and index list
    - `render tag indexes`: Renders tag index pages and index list
    - `render blog home`: Renders the blog index page

+ 1 - 0
src/actions/index.js

@@ -8,5 +8,6 @@ export { imageToWebP } from "./imageToWebP/index.js"
 export { optimiseSvg } from "./optimiseSvg/index.js"
 export { renderIndex } from "./renderIndex/index.js"
 export { renderMarkdownToHtml } from "./renderMarkdownToHtml/index.js"
+export { renderMarkdownToMeta } from "./renderMarkdownToMeta/index.js"
 export { renderMarkdownWithTemplate } from "./renderMarkdownWithTemplate/index.js"
 export { renderTemplate } from "./renderTemplate/index.js"

+ 1 - 0
src/actions/renderMarkdownToHtml/README.md

@@ -19,3 +19,4 @@ actionConfig: {}
 ## Notes
 - Emits `detail` containing frontmatter, `href`, `content` (HTML), and `fileOutputPath`.
 - Uses `meta.resources.images` to attach responsive image srcsets when available.
+- Respects `opts.markdown.allowHtml` to enable or strip raw HTML in markdown.

+ 20 - 0
src/actions/renderMarkdownToMeta/README.md

@@ -0,0 +1,20 @@
+# renderMarkdownToMeta
+
+Parses a markdown file (with frontmatter) into metadata only and returns it as task detail.
+
+## actionConfig options
+- `filePath` (string, required): Input markdown file path (computed from `jobConfig`).
+- `fileOutputPath` (string, required): Intended output HTML path (computed from `jobConfig`).
+
+## Usage
+```javascript
+action: renderMarkdownToMeta,
+jobConfig: {
+  inputFiles: [{ pattern: "markdown/**/*.md" }],
+  outputFileExtension: ".html"
+},
+actionConfig: {}
+```
+
+## Notes
+- Emits `detail` containing frontmatter, `href`, and `fileOutputPath`.

+ 17 - 0
src/actions/renderMarkdownToMeta/index.js

@@ -0,0 +1,17 @@
+import fs from "fs/promises"
+import matter from "gray-matter"
+import { getHref, slugifyString } from "../../util/index.js"
+
+export async function renderMarkdownToMeta({ config: actionConfig, meta }) {
+  const filePath = actionConfig.filePath
+  const fileOutputPath = actionConfig.fileOutputPath
+  const content = await fs.readFile(filePath, "utf8")
+  const { data } = matter(content)
+  const href = getHref(fileOutputPath, meta)
+  const detail = { ...data, href, fileOutputPath }
+
+  return {
+    detail,
+    ref: slugifyString(filePath),
+  }
+}

+ 3 - 0
src/actions/renderMarkdownWithTemplate/README.md

@@ -6,6 +6,7 @@ Renders markdown with frontmatter into a Handlebars template and writes HTML out
 - `filePath` (string, required): Input markdown file path (computed from `jobConfig`).
 - `fileOutputPath` (string, required): Output HTML file path (computed from `jobConfig`).
 - `templateDirs` (string[], required): Directories to search for Handlebars templates.
+- `partialDirs` (string[], optional): Directories to search for Handlebars partials.
 - `defaultTemplate` (string, required unless frontmatter sets `template`): Template name fallback.
 
 ## Usage
@@ -17,6 +18,7 @@ jobConfig: {
 },
 actionConfig: {
   templateDirs: ["templates/"],
+  partialDirs: ["partials/"],
   defaultTemplate: "page"
 }
 ```
@@ -24,3 +26,4 @@ actionConfig: {
 ## Notes
 - Uses frontmatter `template` when present, otherwise `defaultTemplate`.
 - Writes minified HTML to `fileOutputPath` and records the template as a dependency.
+- Respects `opts.markdown.allowHtml` to enable or strip raw HTML in markdown.

+ 3 - 2
src/actions/renderMarkdownWithTemplate/index.js

@@ -3,7 +3,7 @@ import { minify } from "html-minifier-terser"
 import matter from "gray-matter"
 import { getHref, slugifyString, writeFile } from "../../util/index.js"
 import { createMarkdownRenderer } from "../_shared/markdown.js"
-import { getTemplateByName } from "../_shared/template-cache.js"
+import { getTemplateByName, loadPartials } from "../_shared/template-cache.js"
 
 export async function renderMarkdownWithTemplate({ config: actionConfig, meta }) {
   const filePath = actionConfig.filePath
@@ -13,6 +13,7 @@ export async function renderMarkdownWithTemplate({ config: actionConfig, meta })
   const templateName = data.template || actionConfig.defaultTemplate
   const href = getHref(fileOutputPath, meta)
 
+  const partialPaths = await loadPartials(actionConfig.partialDirs)
   const template = await getTemplateByName(actionConfig.templateDirs, templateName)
   const renderer = createMarkdownRenderer(meta)
   const html = template.renderer({
@@ -36,7 +37,7 @@ export async function renderMarkdownWithTemplate({ config: actionConfig, meta })
     detail: { ...data, href },
     paths: [fileOutputPath],
     deps: {
-      paths: [template.path],
+      paths: [template.path, ...partialPaths],
     },
     ref: slugifyString(fileOutputPath),
   }

+ 12 - 9
src/defaults.js

@@ -6,7 +6,8 @@ import {
   optimiseSvg,
   renderTemplate,
   renderIndex,
-  renderMarkdownToHtml,
+  renderMarkdownToMeta,
+  renderMarkdownWithTemplate,
   generateTaxonomy,
 } from "./actions/index.js"
 
@@ -78,7 +79,7 @@ export const tasks = [
   ],
   {
     name: "blog-markdown",
-    action: renderMarkdownToHtml,
+    action: renderMarkdownToMeta,
     jobConfig: {
       inputFiles: [{ pattern: "markdown/blog/*.md" }],
       stripPaths: ["markdown/"],
@@ -88,7 +89,7 @@ export const tasks = [
   },
   {
     name: "markdown",
-    action: renderMarkdownToHtml,
+    action: renderMarkdownToMeta,
     jobConfig: {
       inputFiles: [{ pattern: "markdown/*.md" }],
       stripPaths: ["markdown/"],
@@ -161,12 +162,13 @@ export const tasks = [
   [
     {
       name: "render pages",
-      action: renderTemplate,
+      action: renderMarkdownWithTemplate,
       jobConfig: {
-        stateSelectors: ["resources.markdown"],
+        inputFiles: [{ pattern: "markdown/*.md" }],
+        stripPaths: ["markdown/"],
+        outputFileExtension: ".html",
       },
       actionConfig: {
-        writeOut: true,
         templateDirs: ["templates/", "~/.rhedyn/templates/"],
         partialDirs: ["partials/", "~/.rhedyn/partials/"],
         defaultTemplate: "page",
@@ -174,12 +176,13 @@ export const tasks = [
     },
     {
       name: "render blog pages",
-      action: renderTemplate,
+      action: renderMarkdownWithTemplate,
       jobConfig: {
-        stateSelectors: ["resources.blog-markdown"],
+        inputFiles: [{ pattern: "markdown/blog/*.md" }],
+        stripPaths: ["markdown/"],
+        outputFileExtension: ".html",
       },
       actionConfig: {
-        writeOut: true,
         templateDirs: ["templates/", "~/.rhedyn/templates/"],
         partialDirs: ["partials/", "~/.rhedyn/partials/"],
         defaultTemplate: "article",