Merge pull request #17 from PR0M3TH3AN/5qfmm5-codex/fix-netlify-deployment-error

Fix netlify build by creating docs build script
This commit is contained in:
thePR0M3TH3AN
2025-07-10 12:40:59 -04:00
committed by GitHub
5 changed files with 37 additions and 31 deletions

15
build-docs.js Executable file
View File

@@ -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);
}
})();

View File

@@ -1,3 +1,3 @@
[build]
command = "CI= npm run build"
command = "node build-docs.js"
publish = "_site"

View File

@@ -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);

View File

@@ -1,9 +1,9 @@
<!DOCTYPE html>
<html lang="en" data-theme="{{ config.theme.darkMode ? 'dark' : 'light' }}">
<html lang="en" data-theme="{% if config.theme.darkMode %}dark{% else %}light{% endif %}">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>{{ title or config.site.title }}</title>
<title>{{ title | default(config.site.title) }}</title>
<link rel="stylesheet" href="/assets/theme.css" />
</head>
<body>

View File

@@ -1,3 +1,3 @@
<footer class="footer">
<p>&copy; {{ config.site.title }} {{ new Date().getFullYear() }}</p>
<p>&copy; {{ config.site.title }}</p>
</footer>