Last active
July 11, 2021 01:20
-
-
Save shedali/8e90a0fa0c027b7c0f4b437225e426b3 to your computer and use it in GitHub Desktop.
ia markdown content blocks transclude
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 fs = require("fs"); | |
const path = require("path"); | |
const isDirectory = require("is-directory"); | |
const isFile = require("is-file"); | |
const fm = require("front-matter"); | |
const arg = path.join(__dirname, process.argv[2]); | |
const regex = /^\/.*\.*/; | |
const readline = require("readline"); | |
const iscontentblock = (str) => regex.test(str); | |
async function processLineByLine(file) { | |
const fileStream = fs.createReadStream(file); | |
const rl = readline.createInterface({ | |
input: fileStream, | |
crlfDelay: Infinity, | |
}); | |
for await (const line of rl) { | |
if (iscontentblock(line)) { | |
const possiblefile = path.join(path.dirname(arg), line); | |
isFile.sync(possiblefile) && (await processLineByLine(possiblefile)); | |
} else { | |
if (line.indexOf("#") > -1) { | |
console.log("\n\n"); | |
} | |
console.log(line); | |
} | |
} | |
} | |
isFile.sync(arg) && (await processLineByLine(arg)); | |
isDirectory.sync(arg) && | |
fs | |
.readdirSync(arg) | |
.filter((s) => s.indexOf(".md") > -1) | |
.map((s) => processfile(s)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment