|
1 | 1 | import * as fs from 'node:fs';
|
2 | 2 | import * as path from 'node:path';
|
3 | 3 | import * as url from 'node:url';
|
| 4 | +import stripIndent from 'common-tags/lib/stripIndent/index.js'; |
4 | 5 |
|
5 | 6 | const __filename = url.fileURLToPath(import.meta.url);
|
6 | 7 | const __dirname = path.dirname(__filename);
|
7 | 8 |
|
8 | 9 | // Preview
|
9 | 10 | // =============================================================================
|
10 | 11 | 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'; |
11 | 19 | 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'; |
13 | 22 | const outPath = path.resolve(__dirname, '..', 'docs');
|
14 | 23 | 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') |
17 | 28 | // Replace CDN URLs with local paths
|
18 | 29 | .replace(/\/\/cdn.jsdelivr.net\/npm\/docsify@4\//g, '/');
|
19 | 30 |
|
20 |
| - fs.writeFileSync(path.resolve(outPath, 'preview.html'), outHTML); |
| 31 | + console.log(`\nBuilding ${outFile} in ${outPath}`); |
| 32 | + fs.writeFileSync(path.resolve(outPath, outFile), outHTML); |
21 | 33 | }
|
22 | 34 |
|
23 | 35 | generatePreview();
|
0 commit comments