From e77051ccc4b47951bfa4fde2be436b1bb2fb113b Mon Sep 17 00:00:00 2001 From: Christoph Cullmann Date: Sun, 28 Apr 2024 17:33:09 +0200 Subject: use https://github.com/nunocoracao/blowfish.git --- themes/blowfish/genLangLinks.js | 66 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 themes/blowfish/genLangLinks.js (limited to 'themes/blowfish/genLangLinks.js') diff --git a/themes/blowfish/genLangLinks.js b/themes/blowfish/genLangLinks.js new file mode 100644 index 0000000..6b5925b --- /dev/null +++ b/themes/blowfish/genLangLinks.js @@ -0,0 +1,66 @@ +const fs = require('fs'); + +const configDir = "./exampleSite/config/_default"; +const contentDir = "./exampleSite/content"; +const defaultLang = "en"; + +var targetLangs = [] + +function readConfigs() { + const files = fs.readdirSync(configDir); + files.forEach(file => { + console.log(file) + if(file.indexOf("languages.") > -1) { + var lang = file.split(".")[1]; + console.log(lang) + if(lang != defaultLang) { + targetLangs.push(lang); + } + } + }); +} + +async function processFile(filePath, file) { + if (filePath.indexOf("index.md") > -1) { + + console.log("processing", filePath) + + for(var i in targetLangs) { + const targetLang = targetLangs[i]; + var targetFilePath = filePath.replace(".md", "." + targetLang + ".md"); + //var targetFileName = file.replace(".md", "." + targetLang + ".md"); + + if(fs.existsSync(targetFilePath)) { + console.log("file already exists", targetFilePath); + }else{ + console.log("creating file", targetFilePath); + //fs.symlinkSync(file, targetFilePath, 'junction'); + fs.copyFileSync(filePath, targetFilePath); + } + } + + } else + return +} + +async function processFolder(folderPath) { + const files = fs.readdirSync(folderPath); + + for (var i in files) { + const file = files[i]; + const filePath = `${folderPath}/${file}`; + const isDir = fs.lstatSync(filePath).isDirectory(); + if (isDir) { + await processFolder(filePath); + } else { + await processFile(filePath, file); + } + } +} + +async function createLinks() { + processFolder(contentDir); +} + +readConfigs(); +createLinks(); \ No newline at end of file -- cgit v1.2.3