Move catalog indexes to Markdown front matter

This commit is contained in:
2026-08-22 12:42:11 +03:00
parent 188d9f2b18
commit aa8deee35a
65 changed files with 819 additions and 707 deletions
+6 -10
View File
@@ -15,7 +15,8 @@ import {
} from "node:fs/promises";
import path from "node:path";
import process from "node:process";
import { parseDocument, stringify } from "yaml";
import { stringify } from "yaml";
import { readCatalogIndex } from "./catalogIndex.js";
type CatalogFile = {
path?: unknown;
@@ -91,7 +92,7 @@ async function findIndexes(directory: string, result: string[]): Promise<void> {
const entries = await readdir(directory, { withFileTypes: true });
for (const entry of entries) {
const entryPath = path.join(directory, entry.name);
if (entry.isFile() && entry.name === "index.yaml") {
if (entry.isFile() && entry.name === "index.md") {
result.push(entryPath);
} else if (entry.isDirectory() && !ignoredDirectories.has(entry.name)) {
await findIndexes(entryPath, result);
@@ -182,12 +183,7 @@ async function writeAtomically(filePath: string, contents: string): Promise<void
}
async function readProgram(indexPath: string): Promise<ProgramIndex> {
const source = await readFile(indexPath, "utf8");
const document = parseDocument(source, { prettyErrors: true });
if (document.errors.length > 0) {
throw new Error(document.errors.map((error) => error.message).join("; "));
}
return document.toJS() as ProgramIndex;
return (await readCatalogIndex<ProgramIndex>(indexPath)).metadata;
}
async function generateManifest(catalogDirectory: string): Promise<{
@@ -275,7 +271,7 @@ async function main(): Promise<void> {
const displayPath = path.relative(process.cwd(), manifestPath) || manifestPath;
if (currentContents === contents) {
console.log(
`Done. ${displayPath} is up to date. Files: ${Object.keys(manifest.files).length}; index.yaml files: ${indexes}`,
`Done. ${displayPath} is up to date. Files: ${Object.keys(manifest.files).length}; index.md files: ${indexes}`,
);
return;
}
@@ -288,7 +284,7 @@ async function main(): Promise<void> {
await writeAtomically(manifestPath, contents);
console.log(
`Updated ${displayPath}. Files: ${Object.keys(manifest.files).length}; index.yaml files: ${indexes}`,
`Updated ${displayPath}. Files: ${Object.keys(manifest.files).length}; index.md files: ${indexes}`,
);
}