Skip to content

Commit

Permalink
small update
Browse files Browse the repository at this point in the history
  • Loading branch information
nunocoracao committed Mar 20, 2024
1 parent 0099c88 commit 6b27cdc
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ disableImageOptimization = true
disableTextInHeader = true

defaultFeaturedImage = "/img/background.jpg"
defaultBackgroundImage = "/img/background.jpg"
defaultBackgroundImage = "/img/background.svg"

highlightCurrentMenuArea = true
smartTOC = true
Expand Down
7 changes: 2 additions & 5 deletions genArticle.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ async function convert(text, from, to) {
from: from,
to: to
};
var translated_text = await translate(text, options)
.catch(err => {
console.error(err);
})
return translated_text && translated_text.text? translated_text.text : "";
var translated_text = await translate(text, options);
return translated_text.text;
}

console.log(filePath);
Expand Down
66 changes: 66 additions & 0 deletions genLangLinks.js
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit 6b27cdc

Please sign in to comment.