summaryrefslogtreecommitdiff
path: root/src/build
diff options
context:
space:
mode:
Diffstat (limited to 'src/build')
-rw-r--r--src/build/index.mjs25
-rw-r--r--src/build/rss.mjs2
-rw-r--r--src/build/to-html.mjs24
3 files changed, 42 insertions, 9 deletions
diff --git a/src/build/index.mjs b/src/build/index.mjs
index f9a0d51..d6f1a8a 100644
--- a/src/build/index.mjs
+++ b/src/build/index.mjs
@@ -6,36 +6,41 @@ import {select} from 'hast-util-select';
import {toString as hastToString} from 'mdast-util-to-string';
import cssesc from 'cssesc';
-import {toHtmlRaw, toString} from './to-html.mjs';
+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';
const loadMD = (listFile, suffix) => {
const listContent = [];
for (const file of listFile) {
+ console.log(`Working on ${file}`);
const content = fs.readFileSync(`${suffix}/${file}`, 'utf8');
- const htmlContent = toHtmlRaw(content);
+ const mdRaw = toMdRaw(content);
+ const tomlStringValue = mdRaw.children[0].value;
+ const metaData = toml.parse(tomlStringValue);
+ const newHTML = mdToHtmlRaw(mdRaw);
+
+ const htmlContent = newHTML;
const htmlRender = toString(htmlContent);
- const articleHtml = select('article', htmlContent);
const titleHtml = select('h1', htmlContent);
const intro = select('p', htmlContent);
- const logo = select('img', htmlContent);
+ intro.children = intro.children.filter(child => child.tagName !== 'br');
+
+ const logo = select('img', intro);
logo.properties.src = `${suffix}/${logo.properties.src}`;
logo.properties.height = '150px';
logo.properties.width = '150px';
titleHtml.children[0].properties.href = `${suffix}/${file.slice(0, -3)}.html`;
const title = hastToString(titleHtml);
- const domTitle = cssesc(title.replace(/\s+/g, '-').replace(/[\'\"#@]/, '').toLowerCase()); // Maybe encodeURI
- console.log(domTitle);
-
- console.log(`Create : ${title}`);
+ const domTitle = cssesc(title.replace(/\s+/g, '-').replace(/['"#@]/, '').toLowerCase()); // Maybe encodeURI
const readMore = h('a', 'Lire plus...');
- readMore.properties.href = `${suffix}/${file.slice(0, -3)}.html`
+ readMore.properties.href = `${suffix}/${file.slice(0, -3)}.html`;
readMore.properties.role = 'expend';
readMore.properties.for = domTitle;
@@ -45,6 +50,7 @@ const loadMD = (listFile, suffix) => {
intro: toString(u('root', [titleHtml, intro, readMore])),
introDesc: hastToString(intro),
imageUrl: logo.properties.src,
+ metaData,
title,
domTitle,
});
@@ -76,6 +82,7 @@ for (const article of articles) {
};
const output = mustache.render(articleTmpl, context, partials);
+ console.log(`Create : ${article.title}`);
fs.writeFileSync(`articles/${article.name}.html`, output);
}
diff --git a/src/build/rss.mjs b/src/build/rss.mjs
index 606cdef..e468e3d 100644
--- a/src/build/rss.mjs
+++ b/src/build/rss.mjs
@@ -28,6 +28,8 @@ const getRSS = articles => {
url: `${siteUrl}/articles/${article.domTitle}`,
guid: article.domTitle,
author: 'ache',
+ date: article.metaData.pubDate.toISOString(),
+ categories: article.metaData.tags,
// eslint-disable-next-line camelcase
custom_elements: [
{logo: article.imageUrl},
diff --git a/src/build/to-html.mjs b/src/build/to-html.mjs
index a418b1f..4bc3c06 100644
--- a/src/build/to-html.mjs
+++ b/src/build/to-html.mjs
@@ -4,6 +4,7 @@ import remarkGfm from 'remark-gfm';
import remarkToc from 'remark-toc';
import remarkDirective from 'remark-directive';
import remarkMath from 'remark-math';
+import remarkFrontmatter from 'remark-frontmatter';
import remarkRehype from 'remark-rehype';
import rehypeSlug from 'rehype-slug';
import rehypeKaTeX from 'rehype-katex';
@@ -29,6 +30,26 @@ const generator = unified()
.use(remarkMath)
.use(remarkDirective)
.use(remarkSpecialBox)
+ .use(remarkFrontmatter, {type: 'toml', marker: '-'})
+ .use(remarkRehype, {allowDangerousHtml: true})
+ .use(rehypeRaw)
+ .use(remarkRemoveFootnoteHeader)
+ .use(rehypeKaTeX)
+ .use(rehypeSlug)
+ .use(rehypeHighlight)
+ .use(rehypeAutolinkHeadings, autoLinkOption)
+ .use(rehypeStringify);
+
+const generatorMd = unified()
+ .use(remarkParse)
+ .use(remarkGfm)
+ .use(remarkToc, {heading: 'Sommaire', tight: true, ordered: true})
+ .use(remarkMath)
+ .use(remarkDirective)
+ .use(remarkSpecialBox)
+ .use(remarkFrontmatter, {type: 'toml', marker: '-'});
+
+const generatorHTML = unified()
.use(remarkRehype, {allowDangerousHtml: true})
.use(rehypeRaw)
.use(remarkRemoveFootnoteHeader)
@@ -40,6 +61,9 @@ const generator = unified()
const toHtml = content => generator.processSync(content);
+export const toMdRaw = content => generatorMd.runSync(generatorMd.parse(content));
+export const mdToHtmlRaw = content => generatorHTML.runSync(content);
+
export const toHtmlRaw = content => generator.runSync(generator.parse(content));
export const toString = content => generator.stringify(content);
export default toHtml;