Skip to content

Instantly share code, notes, and snippets.

@Zxce3
Created June 2, 2022 23:11
Show Gist options
  • Select an option

  • Save Zxce3/ffceee45f845cdc2900aa1714eacf329 to your computer and use it in GitHub Desktop.

Select an option

Save Zxce3/ffceee45f845cdc2900aa1714eacf329 to your computer and use it in GitHub Desktop.
automate create folder from data json
const path = require("path");
const fs = require("fs");
// Specific a path for output json
const spFile = path.join("folder", "page.json");
const spFolder = path.join("page");
const spContent = fs.readFileSync(spFile).toString();
const deserializedSpdf = JSON.parse(spContent);
const page = deserializedSpdf.page;
page.forEach(function(sp) {
if (sp === "")
return;
// define layout and title here
const content = "---\nlayout: page\ntitle: " + sp + "\n---";
const file = path.join(spFolder, sp + ".md");
fs.writeFileSync(file, content);
});
{
"page": [
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment