Move catalog indexes to Markdown front matter
This commit is contained in:
+6
-10
@@ -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}`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user