Skip to content

Commit

Permalink
fix time id format
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuanqi Sun committed Sep 2, 2023
1 parent 2077550 commit 7f62b2f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 2 additions & 5 deletions packages/tools/markdown-converter/haiku-to-md.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,12 @@ async function main(inputDir) {
const { headerLines, bodyLines } = fileToLines(data);

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

// TODO pass through markdown and yaml parser

await fs.writeFile(
path.join(__dirname, `./output/${haikuFile.replace(".haiku", ".md")}`),
`${frontmatter}\n\n${body}\n`
);
await fs.writeFile(path.join(__dirname, `./output/${timeId}.md`), `${frontmatter}\n\n${body}\n`);
});
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/tools/markdown-converter/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ export function handleHeaderLines(haikuFile, headerLines) {
throw e;
}
assert(parsedYaml.title, `${haikuFile} has no title`);
assert(parsedYaml.created, `${haikuFile} has no timestamp`);
const timeId = new Date(parsedYaml.created).toISOString().replace(/-|T|:/g, "").slice(0, 14);

const frontmatter = `---\n${frontmatterLines.join("\n")}\n---`;

return frontmatter;
return { timeId, frontmatter };
}

/**
Expand Down

0 comments on commit 7f62b2f

Please sign in to comment.