From 6d1cce384d8a4955fdbcd91c8e4013dd8769cd17 Mon Sep 17 00:00:00 2001 From: ache Date: Tue, 3 May 2022 19:30:39 +0200 Subject: Add Read more link --- src/build/index.mjs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/build/index.mjs') diff --git a/src/build/index.mjs b/src/build/index.mjs index 84d4d9a..f9a0d51 100644 --- a/src/build/index.mjs +++ b/src/build/index.mjs @@ -1,8 +1,10 @@ import fs from 'node:fs'; import mustache from 'mustache'; import {u} from 'unist-builder'; +import {h} from 'hastscript'; 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 loadSVG from './load-svg.mjs'; @@ -16,20 +18,31 @@ const loadMD = (listFile, suffix) => { const htmlContent = toHtmlRaw(content); const htmlRender = toString(htmlContent); + const articleHtml = select('article', htmlContent); const titleHtml = select('h1', htmlContent); const intro = select('p', htmlContent); const logo = select('img', htmlContent); 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 = title.replace(/\s+/g, '-').toLowerCase(); // Maybe encodeURI + const domTitle = cssesc(title.replace(/\s+/g, '-').replace(/[\'\"#@]/, '').toLowerCase()); // Maybe encodeURI + console.log(domTitle); + console.log(`Create : ${title}`); + const readMore = h('a', 'Lire plus...'); + + readMore.properties.href = `${suffix}/${file.slice(0, -3)}.html` + readMore.properties.role = 'expend'; + readMore.properties.for = domTitle; + listContent.push({ name: file.slice(0, -3), content: htmlRender, - intro: toString(u('root', [titleHtml, intro])), + intro: toString(u('root', [titleHtml, intro, readMore])), introDesc: hastToString(intro), imageUrl: logo.properties.src, title, -- cgit v1.2.3