Merge pull request #25 from PR0M3TH3AN/codex/add-page-url-to-rendering-context

Add page URL to render context
This commit is contained in:
thePR0M3TH3AN
2025-07-10 14:00:02 -04:00
committed by GitHub

View File

@@ -179,7 +179,14 @@ async function generate({ contentDir = 'content', outputDir = '_site', configPat
const raw = await fs.promises.readFile(srcPath, 'utf8');
const { content, data } = matter(raw);
const body = require('marked').parse(content);
let html = env.render('layout.njk', { title: data.title || page.data.title, content: body });
const pageContext = {
title: data.title || page.data.title,
content: body,
page: { url: '/' + page.file.replace(/\.md$/, '.html') }
};
let html = env.render('layout.njk', pageContext);
const result = await runHook('onPageRendered', { file: page.file, html });
if (result && result.html) html = result.html;
await fs.promises.writeFile(outPath, html);