Skip to content

Commit 12ceade

Browse files
committed
docs: website panels use embedded HTML
1 parent 5bc9f53 commit 12ceade

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

docs/website/render.js

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
const Handlebars = require('handlebars');
22
const hljs = require('highlight.js/lib/core');
3-
const asciidoc = require('asciidoctor')()
4-
const cheerio = require('cheerio');
53
hljs.registerLanguage('cpp', require('highlight.js/lib/languages/cpp'));
64
hljs.registerLanguage('xml', require('highlight.js/lib/languages/xml'));
75
const fs = require('fs');
@@ -28,7 +26,6 @@ if (helpersDirExists) {
2826
});
2927
}
3028

31-
3229
// Read the JSON data file
3330
const dataFile = 'data.json';
3431
const dataContents = fs.readFileSync(dataFile, 'utf8')
@@ -47,52 +44,57 @@ if (!fs.existsSync(mrdocsExecutable)) {
4744
}
4845

4946
// Read panel snippet files and create documentation
47+
const absSnippetsDir = path.join(__dirname, 'snippets')
5048
for (let panel of data.panels) {
5149
// Find source file
52-
const absSnippetsDir = path.join(__dirname, 'snippets')
5350
const sourcePath = path.join(absSnippetsDir, panel.source)
5451
assert(sourcePath.endsWith('.cpp'))
5552
assert(fs.existsSync(sourcePath))
5653
const sourceBasename = path.basename(sourcePath, path.extname(sourcePath))
5754

5855
// Create a CMakeLists.txt file for the snippet
5956
const cmakeListsPath = path.join(absSnippetsDir, 'CMakeLists.txt')
60-
const cmakeListsContent = `cmake_minimum_required(VERSION 3.13)\nproject(${sourceBasename})\nadd_executable(${sourceBasename} ${panel.source})\ntarget_compile_features(${sourceBasename} PRIVATE cxx_std_23)\n`
57+
const cmakeListsContent = `
58+
cmake_minimum_required(VERSION 3.13)
59+
project(${sourceBasename})
60+
add_executable(${sourceBasename} ${panel.source})
61+
target_compile_features(${sourceBasename} PRIVATE cxx_std_23)
62+
`;
6163
fs.writeFileSync(cmakeListsPath, cmakeListsContent)
6264

6365
// Run mrdocs to generate documentation
6466
const mrdocsConfig = path.join(absSnippetsDir, 'mrdocs.yml')
6567
const mrdocsInput = cmakeListsPath
6668
const mrdocsOutput = path.join(absSnippetsDir, 'output')
67-
const command = `${mrdocsExecutable} --config=${mrdocsConfig} ${mrdocsInput} --output=${mrdocsOutput} --multipage=true --generate=adoc`
69+
const args = [
70+
mrdocsExecutable,
71+
`--config=${mrdocsConfig}`,
72+
mrdocsInput,
73+
`--output=${mrdocsOutput}`,
74+
'--multipage=true',
75+
'--generate=html',
76+
'--embedded=true',
77+
];
78+
const command = args.join(' ');
6879
console.log(`Running command: ${command}`)
69-
execSync(command, {encoding: 'utf8'});
80+
try {
81+
execSync(command, {stdio: 'inherit'});
82+
} catch (error) {
83+
console.error(`Command failed with exit code ${error.status}`);
84+
process.exit(error.status);
85+
}
7086

71-
// Look for documentation file somewhere in the output directory
72-
const documentationFilename = `${sourceBasename}.adoc`
87+
// Look load symbol page in the output directory
88+
const documentationFilename = `${sourceBasename}.html`
7389
const documentationPath = path.join(mrdocsOutput, documentationFilename)
7490
if (!fs.existsSync(documentationPath)) {
7591
console.log(`Documentation file ${documentationFilename} not found in ${mrdocsOutput}`)
76-
console.log('mrdocs failed to generate documentation')
92+
console.log('Failed to generate website panel documentation')
7793
process.exit(1)
7894
}
79-
const documentationContent = fs.readFileSync(documentationPath, 'utf8')
80-
const htmlDocumentation = asciidoc.convert(documentationContent, {
81-
doctype: 'book',
82-
safe: 'safe',
83-
standalone: true
84-
})
85-
const $ = cheerio.load(htmlDocumentation)
86-
// Iterate 5, 4, 3, 2, 1
87-
for (let i = 5; i >= 1; i--) {
88-
$(`h${i}`).replaceWith(function () {
89-
return $(`<h${i + 1}>`).html($(this).html());
90-
});
91-
}
92-
$('#footer').remove();
93-
panel.documentation = $('body').html();
95+
panel.documentation = fs.readFileSync(documentationPath, 'utf8');
9496

95-
// Also inject the contents of the source file
97+
// Also inject the contents of the source file as highlighted C++
9698
const snippetContents = fs.readFileSync(sourcePath, 'utf8');
9799
const highlightedSnippet = hljs.highlight(snippetContents, {language: 'cpp'}).value;
98100
panel.snippet = highlightedSnippet;
@@ -102,10 +104,10 @@ for (let panel of data.panels) {
102104
fs.unlinkSync(cmakeListsPath);
103105
}
104106

105-
// Render the template with the data
107+
// Render the template with the data containing the snippet data
106108
const result = template(data);
107109

108-
// Write the output to an HTML file
110+
// Write the rendered website template to an HTML file
109111
assert(templateFile.endsWith('.hbs'));
110112
const outputFile = templateFile.slice(0, -4);
111113
fs.writeFileSync(outputFile, result);

0 commit comments

Comments
 (0)