From 973acd70f257778c619749539537f8c7c296c675 Mon Sep 17 00:00:00 2001 From: wholteza Date: Sun, 17 Sep 2023 11:05:03 +0200 Subject: [PATCH] Image link support --- build.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/build.js b/build.js index de4bcc4..11afbc6 100644 --- a/build.js +++ b/build.js @@ -30,6 +30,7 @@ const manifest = directoryNames.map((noteDirectory) => ({ { encoding: "utf-8" } ), assetDirectoryPath: `${paths.notes.root}/${noteDirectory}/${paths.notes.assets}`, + publicAssetDirectoryPath: `/${noteDirectory}_`, })); manifest.forEach((m) => { @@ -37,11 +38,24 @@ manifest.forEach((m) => { let htmlTemplate = fs.readFileSync(notePath, { encoding: "utf-8", }); - htmlTemplate = htmlTemplate.replace("{{markdown}}", toHtml(m.markdown)); + htmlTemplate = htmlTemplate.replace( + "{{markdown}}", + toHtml(m.markdown, m.publicAssetDirectoryPath) + ); fs.writeFileSync(`${paths.output}/${m.directoryName}.html`, htmlTemplate, { encoding: "utf-8", flag: "ax", }); + + if (!fs.existsSync(m.assetDirectoryPath)) return; + const assetsList = fs.readdirSync(m.assetDirectoryPath); + console.log(assetsList); + assetsList.forEach((assetName) => + fs.cpSync( + `${m.assetDirectoryPath}/${assetName}`, + `${paths.output}/${m.name}_${assetName}` + ) + ); }); [paths.templates.notFound].forEach((filename) => {