From db6f518520f82288884bc2049e41b45ec41e9c57 Mon Sep 17 00:00:00 2001 From: ache Date: Sat, 10 Aug 2024 06:47:41 +0200 Subject: Support for notes --- src/build/index.mjs | 48 +++++++++++++++++++++++++++++++----------------- src/build/loadMD.mjs | 5 ++++- 2 files changed, 35 insertions(+), 18 deletions(-) (limited to 'src/build') diff --git a/src/build/index.mjs b/src/build/index.mjs index cb918b7..6a05fae 100644 --- a/src/build/index.mjs +++ b/src/build/index.mjs @@ -33,48 +33,58 @@ const svg = loadSVG(); let links = []; +const listNotes = fs + .readdirSync("notes") + .filter((name) => name.endsWith(".md")); +const notesAll = loadMD(listNotes, "notes"); // lang is determined from the note + for (const lang in i18n) { const tagsArticle = new Map(); const filter = process.argv.slice(2); - const listArticle = + const listArticles = filter.length > 0 ? i18n[lang].articles.filter((article) => filter.includes(article.name)) : i18n[lang].articles; - const articles = loadMD(listArticle, "articles", lang); + const articles = loadMD(listArticles, "articles", lang); + + // Same for notes + const notes = notesAll.filter((note) => note.metaData.lang == lang); - for (const article of articles) { + for (const post of [...articles, ...notes]) { const context = { svg, - page_title: `${article.title} - ache`, + page_title: `${post.title} - ache`, title: i18n[lang].title, intro: i18n[lang].intro, lang, - canonical: `${baseUrl}${article.url.slice(1)}`, - content: article.content, + canonical: `${baseUrl}${post.url.slice(1)}`, + content: post.content, title: i18n[lang].title, - metaData: article.metaData, - alt_lang: addDescription(article.metaData.alt_lang), - description: article.intro, + metaData: post.metaData, + alt_lang: addDescription(post.metaData.alt_lang), + description: post.intro, like_title: i18n[lang].like_title, like_text: i18n[lang].like_text, }; const output = mustache.render(articleTmpl, context, partials); - console.log(`Create : ${article.title}`); - fs.writeFileSync(`articles/${article.name}.html`, minifyHTML(output)); + console.log(`Create : ${post.title}`); + const type = post.metaData?.type || "article"; + fs.writeFileSync(`${type}s/${post.name}.html`, minifyHTML(output)); links.push({ url: context.canonical, changefreq: "yearly", priority: 0.6, - img: [{ url: article.imageUrl }], + img: [{ url: post?.imageUrl }], }); - for (const tag of article.metaData.tags) { + for (const tag of post.metaData.tags) { + // Insert the tag, if it already exists add it, otherwise create a object for it. if (tagsArticle.has(tag)) { - tagsArticle.get(tag).push(article); + tagsArticle.get(tag).push(post); } else { - tagsArticle.set(tag, [article]); + tagsArticle.set(tag, [post]); } } } @@ -87,9 +97,12 @@ for (const lang in i18n) { fs.mkdirSync(`${lang}/tag`, { recursive: true }); } - for (const [tag, articles] of tagsArticle.entries()) { + for (const [tag, material] of tagsArticle.entries()) { console.log(`Create tag page : ${lang}/${tag}.html`); - articles.sort(cmpArticles); + material.sort(cmpArticles); + + const articles = material.filter((item) => item.metaData.type != "note"); + const notes = material.filter((item) => item.metaData.type == "note"); const context = { svg, @@ -99,6 +112,7 @@ for (const lang in i18n) { lang, tag, articles, + notes, description: `${i18n[lang]["tag_desc"]} ${tag}.`, }; diff --git a/src/build/loadMD.mjs b/src/build/loadMD.mjs index a1eab3b..8153d37 100644 --- a/src/build/loadMD.mjs +++ b/src/build/loadMD.mjs @@ -20,6 +20,8 @@ const loadMD = (listFile, suffix, lang) => { const metaData = toml.parse(tomlStringValue); const newHTML = mdToHtmlRaw(mdRaw); + const langR = lang || metaData.lang; + const htmlContent = newHTML; const htmlRender = toString(htmlContent); @@ -51,7 +53,8 @@ const loadMD = (listFile, suffix, lang) => { .toLowerCase(), ); // Maybe encodeURI - const readMore = h("a", i18n[lang]["read_more"]); + console.log(langR); + const readMore = h("a", i18n[langR]["read_more"]); readMore.properties.href = `/${suffix}/${file.slice(0, -3)}`; const pubYear = getArticleYear({ metaData }); -- cgit v1.2.3-70-g09d2