From 63e297da167713e17fd271958b4109ea44e7075a Mon Sep 17 00:00:00 2001 From: ache Date: Fri, 9 Aug 2024 04:12:37 +0200 Subject: Lint JavaScript --- src/build/index.mjs | 108 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 62 insertions(+), 46 deletions(-) (limited to 'src/build/index.mjs') diff --git a/src/build/index.mjs b/src/build/index.mjs index a14cdc7..cb918b7 100644 --- a/src/build/index.mjs +++ b/src/build/index.mjs @@ -1,26 +1,25 @@ -import process from 'node:process'; -import fs from 'node:fs'; -import mustache from 'mustache'; -import loadSVG from './load-svg.mjs'; -import getRSS from './rss.mjs'; -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'); -const headerTmpl = fs.readFileSync('src/templates/header.tmpl', 'utf8'); -const articleTmpl = fs.readFileSync('src/templates/article.tmpl', 'utf8'); -const indexTmpl = fs.readFileSync('src/templates/index.tmpl', 'utf8'); -const tagTmpl = fs.readFileSync('src/templates/tag.tmpl', 'utf8'); -const hidTmpl = fs.readFileSync('src/templates/hid.tmpl', 'utf8'); -const baseUrl = 'https://ache.one/'; +import process from "node:process"; +import fs from "node:fs"; +import mustache from "mustache"; +import loadSVG from "./load-svg.mjs"; +import getRSS from "./rss.mjs"; +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"); +const headerTmpl = fs.readFileSync("src/templates/header.tmpl", "utf8"); +const articleTmpl = fs.readFileSync("src/templates/article.tmpl", "utf8"); +const indexTmpl = fs.readFileSync("src/templates/index.tmpl", "utf8"); +const tagTmpl = fs.readFileSync("src/templates/tag.tmpl", "utf8"); +const hidTmpl = fs.readFileSync("src/templates/hid.tmpl", "utf8"); +const baseUrl = "https://ache.one/"; const partials = { header: headerTmpl, @@ -37,8 +36,11 @@ let links = []; for (const lang in i18n) { const tagsArticle = new Map(); const filter = process.argv.slice(2); - const listArticle = (filter.length > 0) ? i18n[lang].articles.filter((article) => filter.includes(article.name)) : i18n[lang].articles; - const articles = loadMD(listArticle, 'articles', lang); + const listArticle = + filter.length > 0 + ? i18n[lang].articles.filter((article) => filter.includes(article.name)) + : i18n[lang].articles; + const articles = loadMD(listArticle, "articles", lang); for (const article of articles) { const context = { @@ -61,7 +63,12 @@ for (const lang in i18n) { console.log(`Create : ${article.title}`); fs.writeFileSync(`articles/${article.name}.html`, minifyHTML(output)); - links.push({url: context.canonical, changefreq: 'yearly', priority: 0.6, img: [{url: article.imageUrl}]}) + links.push({ + url: context.canonical, + changefreq: "yearly", + priority: 0.6, + img: [{ url: article.imageUrl }], + }); for (const tag of article.metaData.tags) { if (tagsArticle.has(tag)) { @@ -72,12 +79,12 @@ for (const lang in i18n) { } } -// Set of pages language dependant + // Set of pages language dependant try { - fs.mkdirSync(`${lang}/tag`, {recursive: true}); + fs.mkdirSync(`${lang}/tag`, { recursive: true }); } catch { - fs.rmSync(`${lang}/tag`, {force: true, recursive: true}); - fs.mkdirSync(`${lang}/tag`, {recursive: true}); + fs.rmSync(`${lang}/tag`, { force: true, recursive: true }); + fs.mkdirSync(`${lang}/tag`, { recursive: true }); } for (const [tag, articles] of tagsArticle.entries()) { @@ -92,28 +99,36 @@ for (const lang in i18n) { lang, tag, articles, - description: `${i18n[lang]['tag_desc']} ${tag}.`, + description: `${i18n[lang]["tag_desc"]} ${tag}.`, }; const output = mustache.render(tagTmpl, context, partials); fs.writeFileSync(`${lang}/tag/${tag}.html`, minifyHTML(output)); - links.push({url: `${baseUrl}${lang}/tag/${tag}`, changefreq: 'monthly', priority: 0.3}) + 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}) + links.push({ + url: `${baseUrl}${lang}/rss.xml`, + changefreq: "monthly", + priority: 0.3, + }); { const alt_lang = { fr: { - lang: 'en', - url: '/en/', + lang: "en", + url: "/en/", }, en: { - lang: 'fr', - url: '/fr/', + lang: "fr", + url: "/fr/", }, }; const context = { @@ -131,20 +146,21 @@ for (const lang in i18n) { console.log(`Create : Home page ${lang}`); const output = mustache.render(indexTmpl, context, partials); 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"}]}) + 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'}); +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) -); - +streamToPromise(Readable.from(links).pipe(stream)) + .then((data) => data.toString()) + .then((sitemapXML) => fs.writeFileSync("sitemap.xml", sitemapXML)); -- cgit v1.2.3-70-g09d2