diff options
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | src/build/index.mjs | 17 |
2 files changed, 16 insertions, 2 deletions
diff --git a/package.json b/package.json index 8ae6d77..3c48d31 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "author": "ache", "license": "MIT", "devDependencies": { + "cssesc": "^3.0.0", "hast-util-raw": "^7.2.1", "hast-util-select": "^5.0.1", "hast-util-to-text": "^3.1.1", 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, |