fix(aio): show aio-themed 404 page for unknown resources (#23188)
Fixes #23179 PR Close #23188
This commit is contained in:

committed by
Matias Niemelä

parent
668bfcec9d
commit
3d41739021
31
aio/scripts/build-404-page.js
Normal file
31
aio/scripts/build-404-page.js
Normal file
@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
// Imports
|
||||
const {readFileSync, writeFileSync} = require('fs');
|
||||
const {join, resolve} = require('path');
|
||||
|
||||
// Constants
|
||||
const SRC_DIR = resolve(__dirname, '../src');
|
||||
const DIST_DIR = resolve(__dirname, '../dist');
|
||||
|
||||
// Run
|
||||
_main(process.argv.slice(2));
|
||||
|
||||
// Functions - Definitions
|
||||
function _main() {
|
||||
const srcIndexPath = join(DIST_DIR, 'index.html');
|
||||
const src404BodyPath = join(SRC_DIR, '404-body.html');
|
||||
const dst404PagePath = join(DIST_DIR, '404.html');
|
||||
|
||||
const srcIndexContent = readFileSync(srcIndexPath, 'utf8');
|
||||
const src404BodyContent = readFileSync(src404BodyPath, 'utf8');
|
||||
const dst404PageContent = srcIndexContent.replace(/<body>[\s\S]+<\/body>/, src404BodyContent);
|
||||
|
||||
if (dst404PageContent === srcIndexContent) {
|
||||
throw new Error(
|
||||
'Failed to generate \'404.html\'. ' +
|
||||
'The content of \'index.html\' does not match the expected pattern.');
|
||||
}
|
||||
|
||||
writeFileSync(dst404PagePath, dst404PageContent);
|
||||
}
|
Reference in New Issue
Block a user