import fs from 'node:fs/promises' import path from 'node:path' import nunjucks from 'nunjucks' import HighlightJS from 'highlight.js' import readPage from '../read-page/index.js' import googleFonts from './util/google-fonts.js' import featherIcons from './util/feather-icons.js' const pages = { '/': './pages/index.tce', '/about/': './pages/about.tce' } async function render() { // await fs.rm('dist', { recursive: true }) for (const [urlPath, filePath] of Object.entries(pages)) { const env = nunjucks.configure('renderer/', { autoescape: false }) env.addGlobal('googleFonts', googleFonts) env.addGlobal('featherIcons', featherIcons) HighlightJS.registerLanguage('terrace', () => ({ name: 'Terrace', contains: [ { className: 'keyword', begin: /^\s*(.*?)(?:\s|$)/, relevance: 1 } ] })) env.addFilter("highlight", (value, language) => { return HighlightJS.highlight(value, { language }).value }) const page = await readPage(filePath) const result = env.render('layout.njk', { page, url: urlPath, file: filePath }) await fs.mkdir(path.join('dist', urlPath), { recursive: true }) await fs.writeFile(path.join('dist', urlPath, 'index.html'), result) } // await fs.cp('node_modules/highlight.js/styles/atom-one-dark.css', ''); await fs.cp('./public/', './dist/public/', { recursive: true }) await fs.cp('./favicon.ico', './dist/favicon.ico', { recursive: true }) } render()