diff options
author | ache <ache@ache.one> | 2022-12-10 08:15:05 +0100 |
---|---|---|
committer | ache <ache@ache.one> | 2022-12-10 08:15:05 +0100 |
commit | 88ef31743b7c59214b3bf4aaeef51af3f2fcb8f7 (patch) | |
tree | b747b11c328cb6e4b89d2cede9f7b11d077ca792 /src/build/index.mjs | |
parent | Put title as underligned (diff) |
Show date on each article
Diffstat (limited to 'src/build/index.mjs')
-rw-r--r-- | src/build/index.mjs | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/build/index.mjs b/src/build/index.mjs index ce490cf..a8fac14 100644 --- a/src/build/index.mjs +++ b/src/build/index.mjs @@ -5,31 +5,37 @@ import {h} from 'hastscript'; import {select} from 'hast-util-select'; import {toString as hastToString} from 'mdast-util-to-string'; import cssesc from 'cssesc'; +import toml from '@ltd/j-toml'; import {toHtmlRaw, toString, toMdRaw, mdToHtmlRaw} from './to-html.mjs'; import loadSVG from './load-svg.mjs'; import listArticles from './list-articles.mjs'; import getRSS from './rss.mjs'; -import toml from '@ltd/j-toml'; function getArticleYear(article) { - if(article.metaData.pubDate.getFullYear) { + if (article.metaData.pubDate.getFullYear) { return article.metaData.pubDate.getFullYear(); - } else if(article.metaData.pubDate.getUTCFullYear) { + } + + if (article.metaData.pubDate.getUTCFullYear) { return article.metaData.pubDate.getUTCFullYear(); } return 0; } + function getArticleDate(article) { - if(article.metaData.pubDate.getDate) { + if (article.metaData.pubDate.getDate) { return article.metaData.pubDate.getFullYear() * 100 + article.metaData.pubDate.getDate(); - } else if(article.metaData.pubDate.getUTCDate) { + } + + if (article.metaData.pubDate.getUTCDate) { return article.metaData.pubDate.getUTCFullYear() * 100 + article.metaData.pubDate.getDate(); } return 0; } + function cmpArticles(a, b) { return getArticleDate(b) - getArticleDate(a); } @@ -58,9 +64,7 @@ const loadMD = (listFile, suffix) => { const logoP = select('source', intro); if (logoP !== null) { - console.log(logoP) - logoP.properties.srcSet= `${suffix}/${logoP.properties.srcSet}`; - console.log(logoP) + logoP.properties.srcSet = `${suffix}/${logoP.properties.srcSet}`; } titleHtml.children[0].properties.href = `${suffix}/${file.slice(0, -3)}`; @@ -73,6 +77,14 @@ const loadMD = (listFile, suffix) => { readMore.properties.href = `${suffix}/${file.slice(0, -3)}`; const pubYear = getArticleYear({metaData}); + if (metaData.pubDate) { + try { + metaData.pubDateISO = metaData.pubDate.toISOString(); + } catch (error) { + console.error(`Error on file ${file} with pubDate (${metaData.pubDate}): ${error}`); + } + } + listContent.push({ name: file.slice(0, -3), content: htmlRender, |