generate a block index

This commit is contained in:
Loren Norman 2025-07-24 13:43:48 -04:00
parent 8adf43ed7b
commit dd34206376
6 changed files with 74 additions and 11 deletions

View file

@ -41,14 +41,14 @@ export default defineConfig({
{ text: '🧩', link: '/sandbox' },
{ text: 'Home', link: '/' },
{ text: 'Getting Started', link: '/getting-started' },
{ text: 'Block List', link: '/block-index' },
{ text: 'Block List', link: '/blocks/index' },
{ text: 'Contributing', link: '/contributing' },
// { text: 'Examples', link: '/automation-examples' }
],
sidebar: {
// covers /blocks/* and /block-index
"/block": [ blocksSidebar ],
// block index and pages
"/blocks/": [ blocksSidebar ],
// devtools for the sandbox
"/sandbox": [

View file

@ -1,7 +0,0 @@
---
title: Block List
---
# Block List
Coming soon...

View file

@ -12,7 +12,7 @@ hero:
link: /getting-started.md
- theme: alt
text: Block List
link: /block-index.md
link: /blocks/index.md
features:
- icon: 📚

View file

@ -36,6 +36,7 @@ const
await exportTo("docs", definitions, exportItem => {
exportItem.sidebar("blocks/_blocks_sidebar.json")
exportItem.blockIndex("blocks/index.md")
exportItem.blockPages()
// exportItem.blockExamples(block => "blocks/${block.definitionPath}/examples.json")
})

View file

@ -0,0 +1,67 @@
import { writeFileSync } from 'fs'
import { forEach, isString } from 'lodash-es'
export default class BlockIndexExporter {
definitionSet = null
destination = null
constructor(definitionSet, destination) {
this.definitionSet = definitionSet
this.destination = destination
}
export(givenOptions = {}) {
const
options = {
toFile: false,
filenameFunc: blockDef => blockDef.documentationPath(),
...givenOptions
},
categories = this.definitionSet.getCategories(),
index = []
index.push(`---
title: "Block List"
editLink: false
---
# Block List`)
// index.push(`All available blocks`)
categories.forEach(category => {
index.push(`## ${category.name}`)
index.push(
this.definitionSet.blocks.reduce((acc, def) => {
if(category.contents?.includes(def) || category.usesBlocks?.includes(def.type)) {
// block name and link
acc.push(`### [${ def.name }](/${ def.documentationPath() })`)
// block image
// acc.push(``) // TODO
// block short description
acc.push(`_${def.tooltip}_`)
}
return acc
}, []).join("\n")
)
})
const finalMarkdown = index.join("\n\n")
if(!options.toFile) {
return finalMarkdown
}
const filename = isString(options.toFile)
? options.toFile
: `index.md`
writeFileSync(`${this.destination}/${filename}`, finalMarkdown)
}
exportToFile = (toFile=true) => {
this.export({ toFile })
}
}

View file

@ -3,6 +3,7 @@ import ToolboxExporter from "./toolbox_exporter.js"
import WorkspaceExporter from "./workspace_exporter.js"
import ScriptExporter from "./script_exporter.js"
import SidebarExporter from "./sidebar_exporter.js"
import BlockIndexExporter from "./block_index_exporter.js"
import BlockPageExporter from "./block_page_exporter.js"
@ -24,6 +25,7 @@ export const exportTo = async (destination, definitions, exportFunc) => {
script: new ScriptExporter(definitions, destination).exportToFile,
// docs exporters
sidebar: new SidebarExporter(definitions, destination).exportToFile,
blockIndex: new BlockIndexExporter(definitions, destination).exportToFile,
blockPages: new BlockPageExporter(definitions, destination).exportToFile,
}