From 88ef31743b7c59214b3bf4aaeef51af3f2fcb8f7 Mon Sep 17 00:00:00 2001 From: ache Date: Sat, 10 Dec 2022 08:15:05 +0100 Subject: Show date on each article --- src/build/index.mjs | 28 ++++++++++++++++++++-------- src/build/rss.mjs | 4 +--- src/css/_contenu.scss | 5 +++++ 3 files changed, 26 insertions(+), 11 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, diff --git a/src/build/rss.mjs b/src/build/rss.mjs index e890152..04b0393 100644 --- a/src/build/rss.mjs +++ b/src/build/rss.mjs @@ -14,8 +14,6 @@ const getRSS = (articles, baseUrl) => { language: 'fr', pubDate: (new Date().toLocaleString()), ttl: '1440', - // eslint-disable-next-line camelcase - custom_elements: [''], }); for (const article of articles.slice(0, 10)) { @@ -27,7 +25,7 @@ const getRSS = (articles, baseUrl) => { url: `${baseUrl}articles/${article.name}`, guid: article.domTitle, author: 'ache', - date: article.metaData.pubDate.toISOString(), + date: article.metaData.pubDateISO, categories: article.metaData.tags, // eslint-disable-next-line camelcase custom_elements: [ diff --git a/src/css/_contenu.scss b/src/css/_contenu.scss index 3aa56d1..4dab365 100755 --- a/src/css/_contenu.scss +++ b/src/css/_contenu.scss @@ -20,6 +20,10 @@ article { line-height: 1.6rem; .pubdate { + text-align: right; + font-size: 0.75em; + color: #999; + /* position: absolute; top: 0; right: 0; @@ -29,6 +33,7 @@ article { overflow: clip; color: pink; text-align: right; + */ } ul { line-height: 1.6; -- cgit v1.2.3