From ecd825802cb898b67a3a8b8d326217e690452d24 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Thu, 10 Jul 2025 12:40:15 -0400 Subject: [PATCH] Fix Netlify build script and generator --- build-docs.js | 15 ++++++++++++ netlify.toml | 2 +- src/generator/index.js | 45 ++++++++++++++--------------------- templates/layout.njk | 4 ++-- templates/partials/footer.njk | 2 +- 5 files changed, 37 insertions(+), 31 deletions(-) create mode 100755 build-docs.js diff --git a/build-docs.js b/build-docs.js new file mode 100755 index 0000000..c41a2bb --- /dev/null +++ b/build-docs.js @@ -0,0 +1,15 @@ +#!/usr/bin/env node +const path = require('path'); +const { generate } = require('./src/generator'); + +(async () => { + try { + const contentDir = path.join(__dirname, 'docs', 'content'); + const configPath = path.join(__dirname, 'docs', 'config.yaml'); + const outputDir = path.join(__dirname, '_site'); + await generate({ contentDir, outputDir, configPath }); + } catch (err) { + console.error(err); + process.exit(1); + } +})(); diff --git a/netlify.toml b/netlify.toml index 310614a..8f544bb 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,3 +1,3 @@ [build] - command = "CI= npm run build" + command = "node build-docs.js" publish = "_site" diff --git a/src/generator/index.js b/src/generator/index.js index da3ca20..310f542 100644 --- a/src/generator/index.js +++ b/src/generator/index.js @@ -2,9 +2,9 @@ const fs = require('fs'); const path = require('path'); const matter = require('gray-matter'); -const Eleventy = require('@11ty/eleventy'); const lunr = require('lunr'); -const { lexer } = require('marked'); +const marked = require('marked'); +const { lexer } = marked; const loadConfig = require('../config/loadConfig'); const loadPlugins = require('../config/loadPlugins'); @@ -118,36 +118,27 @@ async function generate({ contentDir = 'content', outputDir = '_site', configPat JSON.stringify({ index: searchIndex.toJSON(), docs: searchDocs }, null, 2) ); - const elev = new Eleventy(contentDir, outputDir); - elev.setConfig({ - dir: { - input: contentDir, - output: outputDir, - includes: path.relative(contentDir, 'templates') - }, - templateFormats: ['md', 'njk'], - markdownTemplateEngine: 'njk', - htmlTemplateEngine: 'njk', - dataTemplateEngine: 'njk' - }); - elev.configFunction = function(eleventyConfig) { - eleventyConfig.addGlobalData('navigation', nav); - eleventyConfig.addGlobalData('config', config); - eleventyConfig.addGlobalData('layout', 'layout.njk'); - eleventyConfig.addPassthroughCopy({ 'assets': 'assets' }); - }; - await elev.write(); + const nunjucks = require('nunjucks'); + const env = new nunjucks.Environment( + new nunjucks.FileSystemLoader('templates') + ); + env.addGlobal('navigation', nav); + env.addGlobal('config', config); for (const page of pages) { const outPath = path.join(outputDir, page.file.replace(/\.md$/, '.html')); - if (fs.existsSync(outPath)) { - let html = await fs.promises.readFile(outPath, 'utf8'); - const result = await runHook('onPageRendered', { file: page.file, html }); - if (result && result.html) html = result.html; - await fs.promises.writeFile(outPath, html); - } + await fs.promises.mkdir(path.dirname(outPath), { recursive: true }); + const srcPath = path.join(contentDir, page.file); + 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 result = await runHook('onPageRendered', { file: page.file, html }); + if (result && result.html) html = result.html; + await fs.promises.writeFile(outPath, html); } + for (const asset of assets) { const srcPath = path.join(contentDir, asset); const destPath = path.join(outputDir, asset); diff --git a/templates/layout.njk b/templates/layout.njk index 512d2b6..3d8a88a 100644 --- a/templates/layout.njk +++ b/templates/layout.njk @@ -1,9 +1,9 @@ - +
-