diff options
Diffstat (limited to 'src/build/index.mjs')
-rw-r--r-- | src/build/index.mjs | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/build/index.mjs b/src/build/index.mjs index ad126a8..fa5f450 100644 --- a/src/build/index.mjs +++ b/src/build/index.mjs @@ -7,6 +7,10 @@ import loadMD from './loadMD.mjs'; import {cmpArticles} from './article.mjs'; import i18n from './i18n.mjs'; import {addDescription} from './i18n.mjs'; +import {minifyHTML} from './utils.mjs'; + +import { SitemapStream, streamToPromise } from 'sitemap' +import { Readable } from 'stream' const leftPanelTmpl = fs.readFileSync('src/templates/left.tmpl', 'utf8'); const likesTmpl = fs.readFileSync('src/templates/likes.tmpl', 'utf8'); @@ -27,6 +31,8 @@ const partials = { // Load global variables const svg = loadSVG(); +let links = []; + for (const lang in i18n) { const tagsArticle = new Map(); const filter = process.argv.slice(2); @@ -45,11 +51,13 @@ for (const lang in i18n) { title: i18n[lang].title, metaData: article.metaData, alt_lang: addDescription(article.metaData.alt_lang), + description: i18n[lang].intro, }; const output = mustache.render(articleTmpl, context, partials); console.log(`Create : ${article.title}`); - fs.writeFileSync(`articles/${article.name}.html`, output); + fs.writeFileSync(`articles/${article.name}.html`, minifyHTML(output)); + links.push({url: context.canonical, changefreq: 'yearly', priority: 0.6, img: [{url: context.metaData.imageUrl}]}) for (const tag of article.metaData.tags) { if (tagsArticle.has(tag)) { @@ -61,7 +69,6 @@ for (const lang in i18n) { } // Set of pages language dependant - try { fs.mkdirSync(`${lang}/tag`, {recursive: true}); } catch { @@ -81,15 +88,18 @@ for (const lang in i18n) { lang, tag, articles, + description: `${i18n[lang]['tag_desc']} ${tag}.`, }; const output = mustache.render(tagTmpl, context, partials); - fs.writeFileSync(`${lang}/tag/${tag}.html`, output); + fs.writeFileSync(`${lang}/tag/${tag}.html`, minifyHTML(output)); + links.push({url: `${baseUrl}${lang}/tag/${tag}`, changefreq: 'monthly', priority: 0.3}) } console.log(`Create RSS Flux: ${lang}/rss.xml`); const xmlFeed = getRSS(articles, baseUrl, lang); fs.writeFileSync(`${lang}/rss.xml`, xmlFeed); + links.push({url: `${baseUrl}${lang}/rss.xml`, changefreq: 'monthly', priority: 0.3}) { const alt_lang = { @@ -107,14 +117,26 @@ for (const lang in i18n) { title: i18n[lang].title, intro: i18n[lang].intro, lang, - canonical: baseUrl, + canonical: `${baseUrl}${lang}`, svg, articles, alt_lang: [alt_lang[lang]], + description: i18n[lang].index_desc, }; console.log(`Create : Home page ${lang}`); const output = mustache.render(indexTmpl, context, partials); - fs.writeFileSync(`${lang}/index.html`, output); + fs.writeFileSync(`${lang}/index.html`, minifyHTML(output)); + links.push({url: `${baseUrl}${lang}`, changefreq: 'monthly', priority: 0.7, img: [{url: "https://ache.one/res/ache.svg"}]}) } } + +console.log(`Create: sitemap.xml`); +// Create a stream to write to +const stream = new SitemapStream({hostname: 'https://ache.one'}) + +// Return a promise that resolves with your XML string +streamToPromise(Readable.from(links).pipe(stream)).then((data) => + data.toString() +).then(sitemapXML => fs.writeFileSync("sitemap.xml", sitemapXML)); + |