Преглед изворни кода

Dedicated renderIndex action

Craig Fletcher пре 2 недеља
родитељ
комит
6f89561131
6 измењених фајлова са 56 додато и 8 уклоњено
  1. 2 2
      CONTEXT.md
  2. 1 0
      README.md
  3. 1 0
      src/actions/index.js
  4. 39 0
      src/actions/renderIndex/README.md
  5. 9 0
      src/actions/renderIndex/index.js
  6. 4 6
      src/defaults.js

+ 2 - 2
CONTEXT.md

@@ -36,8 +36,8 @@ with caching based on file hashes and state access.
 ## Actions
 - `src/actions/` contains built-ins:
   - `compileSass`, `renderMarkdownToHtml`, `renderTemplate`,
-    `renderMarkdownWithTemplate`, `optimiseSvg`, `copy`, `imageToWebP`,
-    `generateFavicons`, `generateTaxonomy`.
+    `renderMarkdownWithTemplate`, `renderIndex`, `optimiseSvg`, `copy`,
+    `imageToWebP`, `generateFavicons`, `generateTaxonomy`.
 - Actions receive `{ config, jobConfig, meta }` and return
   `{ detail, paths, deps, ref }`. The `config` value maps to `actionConfig`.
 - Returned `ref` results are exposed via `meta.resources` for later tasks.

+ 1 - 0
README.md

@@ -226,6 +226,7 @@ async function myAction({ config, jobConfig, meta }) {
 
 The following actions are available from `actions`:
 - `compileSass`: Compiles SCSS files to compressed CSS
+- `renderIndex`: Renders index pages and index list pages
 - `renderMarkdownWithTemplate`: Renders markdown with Handlebars templates, includes frontmatter support
 - `optimiseSvg`: Optimizes SVG files using SVGO
 - `copy`: Copies files without processing

+ 1 - 0
src/actions/index.js

@@ -6,6 +6,7 @@ export { generateFavicons } from "./generateFavicons/index.js"
 export { generateTaxonomy } from "./generateTaxonomy/index.js"
 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 { renderMarkdownWithTemplate } from "./renderMarkdownWithTemplate/index.js"
 export { renderTemplate } from "./renderTemplate/index.js"

+ 39 - 0
src/actions/renderIndex/README.md

@@ -0,0 +1,39 @@
+# renderIndex
+
+Renders index pages and index list pages using the standard index template.
+
+## actionConfig options
+- `template` (string, optional): Template name to render (without extension).
+- `defaultTemplate` (string, optional): Fallback template name; defaults to `index`.
+- `templateDirs` (string[], required unless `filePath` is set): Directories to search for templates.
+- `partialDirs` (string[], optional): Directories to search for partials.
+- `writeOut` (boolean, optional): When `true`, writes minified HTML to `fileOutputPath`.
+- `filePath` (string, optional): Explicit template path override.
+- `fileOutputPath` (string, required when `writeOut` is true): Output HTML path.
+- `inputs` (array, computed): Expanded inputs for state jobs, or index list entries when `buildIndexList` is used.
+- `pagination` (object, computed): Pagination metadata for state expansion pages.
+- `stateKey` (string, computed): Key for the current state expansion item.
+- `indexPages` (array, computed): List of index pages when `buildIndexList` is enabled.
+- `isIndexList` (boolean, computed): `true` when rendering the index list page.
+- `indexOn` (string, computed): Lowercased index label for the current index page (e.g. `tag`).
+- `indexPage` (string, computed): Href to the index list page (e.g. `/blog/by-tag/`).
+
+## Usage
+```javascript
+action: renderIndex,
+jobConfig: {
+  stateSelectors: ["resources.tag-taxonomy.detail"],
+  outputFileExtension: ".html",
+  outputDir: "blog/by-tag/",
+  buildFilePath: true,
+  itemsPerPage: 10
+},
+actionConfig: {
+  writeOut: true,
+  templateDirs: ["templates/"],
+  partialDirs: ["partials/"]
+}
+```
+
+## Notes
+- Uses the `index` template by default; override with `template` if needed.

+ 9 - 0
src/actions/renderIndex/index.js

@@ -0,0 +1,9 @@
+import { renderTemplate } from "../renderTemplate/index.js"
+
+export async function renderIndex({ config: actionConfig, meta }) {
+  const indexConfig = {
+    ...actionConfig,
+    defaultTemplate: actionConfig.defaultTemplate || "index",
+  }
+  return renderTemplate({ config: indexConfig, meta })
+}

+ 4 - 6
src/defaults.js

@@ -5,6 +5,7 @@ import {
   imageToWebP,
   optimiseSvg,
   renderTemplate,
+  renderIndex,
   renderMarkdownToHtml,
   generateTaxonomy,
 } from "./actions/index.js"
@@ -186,7 +187,7 @@ export const tasks = [
     },
     {
       name: "render author indexes",
-      action: renderTemplate,
+      action: renderIndex,
       jobConfig: {
         stateSelectors: ["resources.author-taxonomy.detail"],
         outputFileExtension: ".html",
@@ -196,14 +197,13 @@ export const tasks = [
       },
       actionConfig: {
         writeOut: true,
-        template: "index",
         templateDirs: ["templates/", "~/.rhedyn/templates/"],
         partialDirs: ["partials/", "~/.rhedyn/partials/"],
       },
     },
     {
       name: "render tag indexes",
-      action: renderTemplate,
+      action: renderIndex,
       jobConfig: {
         stateSelectors: ["resources.tag-taxonomy.detail"],
         outputFileExtension: ".html",
@@ -213,14 +213,13 @@ export const tasks = [
       },
       actionConfig: {
         writeOut: true,
-        template: "index",
         templateDirs: ["templates/", "~/.rhedyn/templates/"],
         partialDirs: ["partials/", "~/.rhedyn/partials/"],
       },
     },
     {
       name: "render blog home",
-      action: renderTemplate,
+      action: renderIndex,
       jobConfig: {
         stateSelectors: ["resources.blog-latest.detail"],
         outputFileExtension: ".html",
@@ -232,7 +231,6 @@ export const tasks = [
       },
       actionConfig: {
         writeOut: true,
-        template: "index",
         templateDirs: ["templates/", "~/.rhedyn/templates/"],
         partialDirs: ["partials/", "~/.rhedyn/partials/"],
         title: "Blog",