forked from mirrors/thatmattlove-hyperglass
Properly handle empty/missing custom JS/HTML
This commit is contained in:
parent
bd0eb65ffc
commit
5f4d5049e0
1 changed files with 8 additions and 2 deletions
|
|
@ -13,8 +13,14 @@ interface DocumentExtra extends DocumentInitialProps {
|
|||
class MyDocument extends Document<DocumentExtra> {
|
||||
static async getInitialProps(ctx: DocumentContext): Promise<DocumentExtra> {
|
||||
const initialProps = await Document.getInitialProps(ctx);
|
||||
const customJs = fs.readFileSync('custom.js').toString();
|
||||
const customHtml = fs.readFileSync('custom.html').toString();
|
||||
let customJs = '',
|
||||
customHtml = '';
|
||||
if (fs.existsSync('custom.js')) {
|
||||
customJs = fs.readFileSync('custom.js').toString();
|
||||
}
|
||||
if (fs.existsSync('custom.html')) {
|
||||
customHtml = fs.readFileSync('custom.html').toString();
|
||||
}
|
||||
return { customJs, customHtml, ...initialProps };
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue