mirror of
https://github.com/PR0M3TH3AN/Archivox.git
synced 2025-09-07 14:48:40 +00:00
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:
15
build-docs.js
Executable file
15
build-docs.js
Executable 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);
|
||||
}
|
||||
})();
|
@@ -1,3 +1,3 @@
|
||||
[build]
|
||||
command = "CI= npm run build"
|
||||
command = "node build-docs.js"
|
||||
publish = "_site"
|
||||
|
@@ -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);
|
||||
|
@@ -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>
|
||||
|
@@ -1,3 +1,3 @@
|
||||
<footer class="footer">
|
||||
<p>© {{ config.site.title }} {{ new Date().getFullYear() }}</p>
|
||||
<p>© {{ config.site.title }}</p>
|
||||
</footer>
|
||||
|
Reference in New Issue
Block a user