Skip to content

Commit

Permalink
collect file name map
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuanqi Sun committed Sep 2, 2023
1 parent 5df5296 commit 5fcbb75
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/tools/markdown-converter/haiku-to-md.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import fs from "fs/promises";
import assert from "node:assert";
import path from "path";
import { fileToLines, handleBodyLines, handleHeaderLines } from "./lib.js";
const __dirname = path.resolve();
const inputDir = path.resolve(__dirname, "./input");

// console.warn = () => {};

const filenameMap = new Map();

async function main(inputDir) {
try {
// clear output
Expand All @@ -16,12 +19,27 @@ async function main(inputDir) {
const haikuFiles = await fs.readdir(inputDir);
console.log("file count: ", haikuFiles.length);

// first pass, analyze all metadata
for (const haikuFile of haikuFiles) {
await fs.readFile(path.resolve(inputDir, haikuFile), "utf-8").then(async (data) => {
const { headerLines } = fileToLines(data);

// convert headerLines to yaml
const { timeId } = handleHeaderLines(haikuFile, headerLines);
const sourceFilename = haikuFile.replace(".haiku", "");
filenameMap.set(sourceFilename, timeId);
});
}

assert(filenameMap.size === haikuFiles.length, "filenameMap size should match haikuFiles length");

for (const haikuFile of haikuFiles) {
await fs.readFile(path.resolve(inputDir, haikuFile), "utf-8").then(async (data) => {
const { headerLines, bodyLines } = fileToLines(data);

// convert headerLines to yaml
const { frontmatter, timeId } = handleHeaderLines(haikuFile, headerLines);

const body = handleBodyLines(haikuFile, bodyLines);

// TODO pass through markdown and yaml parser
Expand Down

0 comments on commit 5fcbb75

Please sign in to comment.