Created
June 2, 2022 23:11
-
-
Save Zxce3/ffceee45f845cdc2900aa1714eacf329 to your computer and use it in GitHub Desktop.
automate create folder from data json
This file contains hidden or 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 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); | |
| }); |
This file contains hidden or 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
| { | |
| "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