Skip to content

Commit a3e92b3

Browse files
committed
Append build comment to preview.html
1 parent 9373ab6 commit a3e92b3

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

build/html.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
11
import * as fs from 'node:fs';
22
import * as path from 'node:path';
33
import * as url from 'node:url';
4+
import stripIndent from 'common-tags/lib/stripIndent/index.js';
45

56
const __filename = url.fileURLToPath(import.meta.url);
67
const __dirname = path.dirname(__filename);
78

89
// Preview
910
// =============================================================================
1011
function generatePreview() {
12+
const comment = stripIndent`
13+
<!--
14+
This file is generated by the build/html.js script.
15+
Do not edit this file directly.
16+
-->
17+
`;
18+
const srcFile = 'index.html';
1119
const srcPath = path.resolve(__dirname, '..', 'docs');
12-
const srcHTML = fs.readFileSync(path.resolve(srcPath, 'index.html'), 'utf8');
20+
const srcHTML = fs.readFileSync(path.resolve(srcPath, srcFile), 'utf8');
21+
const outFile = 'preview.html';
1322
const outPath = path.resolve(__dirname, '..', 'docs');
1423
const outHTML = srcHTML
15-
// Append title
16-
.replace(/(<\/title>)/g, ' (Preview)$1')
24+
// Append comment
25+
.replace(/(<!DOCTYPE html>)/, `${comment}\n$1`)
26+
// Modify title
27+
.replace(/(<\/title>)/, ' (Preview)$1')
1728
// Replace CDN URLs with local paths
1829
.replace(/\/\/cdn.jsdelivr.net\/npm\/docsify@4\//g, '/');
1930

20-
fs.writeFileSync(path.resolve(outPath, 'preview.html'), outHTML);
31+
console.log(`\nBuilding ${outFile} in ${outPath}`);
32+
fs.writeFileSync(path.resolve(outPath, outFile), outHTML);
2133
}
2234

2335
generatePreview();

0 commit comments

Comments
 (0)