23 lines
1016 B
JavaScript
23 lines
1016 B
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
// Same four compile-time substitutions as src/admin/public.rs.
|
|
export function renderAdminIndex(root) {
|
|
const web = path.join(root, 'src/admin/web');
|
|
let html = fs.readFileSync(path.join(web, 'index.html'), 'utf8');
|
|
const metrics = fs.readFileSync(path.join(web, 'partials/overview-metrics.html'), 'utf8')
|
|
.split('<!-- RP_METRICS_SPLIT -->');
|
|
const charts = fs.readFileSync(path.join(web, 'partials/overview-charts.html'), 'utf8')
|
|
.split('<!-- RP_CHARTS_SPLIT -->');
|
|
if (metrics.length !== 2 || charts.length !== 2) throw new Error('Invalid Overview partials');
|
|
for (const [marker, text] of [
|
|
['METRICS_MAIN', metrics[0]], ['CHARTS_MAIN', charts[0]],
|
|
['METRICS_WEB', metrics[1]], ['CHARTS_WEB', charts[1]],
|
|
]) {
|
|
const token = `<!-- RP_${marker} -->`;
|
|
if (!html.includes(token)) throw new Error(`Missing ${token}`);
|
|
html = html.replace(token, text);
|
|
}
|
|
return html;
|
|
}
|