Created
January 23, 2018 12:55
-
-
Save ddombrow/e8c199da54e60867986aa53f71f71258 to your computer and use it in GitHub Desktop.
make frontmatter for md files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { promisify } = require("util"); | |
const fs = require("fs"); | |
const readFileAsync = promisify(fs.readFile); | |
const writeFileAsync = promisify(fs.writeFile); | |
const readDirAsync = promisify(fs.readdir); | |
async function doIt() { | |
let fileList = await readDirAsync(__dirname); | |
fileList = fileList.filter(f => { | |
return f.endsWith(".md"); | |
}); | |
const modified = []; | |
for (f of fileList) { | |
let fileContent = await readFileAsync(__dirname + "/" + f); | |
if (!fileContent.toString().startsWith("---")) { | |
const pageName = f.toString().replace(".md", ""); | |
const title = pageName.substr(0, 1).toUpperCase() + pageName.substr(1, pageName.length); | |
const frontMatter = `--- | |
path: "/css-docs/${pageName}" | |
date: "20178-01-23" | |
title: "${title}" | |
--- | |
`; | |
fileContent = frontMatter + fileContent; | |
await writeFileAsync(__dirname + "/fm-" + f, fileContent); | |
modified.push(f); | |
} | |
} | |
return modified; | |
} | |
doIt() | |
.then(modded => { | |
console.log("These files got frontmatter added: \n", modded); | |
}) | |
.catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment