(core) Add config to include custom CSS

Summary:
Adds a new environment variable that allows for custom
CSS to be included in all core static pages.

Test Plan: Tested manually in grist-core.

Reviewers: paulfitz

Reviewed By: paulfitz

Differential Revision: https://phab.getgrist.com/D3419
This commit is contained in:
George Gevoian
2022-05-11 23:08:06 -07:00
parent e6983e9209
commit 524dbf34e1
9 changed files with 61 additions and 2 deletions

View File

@@ -29,6 +29,9 @@ export interface ICreate {
sessionSecret(): string;
// Get configuration information to show at start-up.
configurationOptions(): {[key: string]: any};
// Return a string containing 1 or more HTML tags to insert into the head element of every
// static page.
getExtraHeadHtml?(): string;
}
export interface ICreateActiveDocOptions {
@@ -90,6 +93,13 @@ export function makeSimpleCreator(opts: {
if (config) { return config; }
}
return {};
}
},
getExtraHeadHtml() {
let customHeadHtmlSnippet = '';
if (process.env.APP_STATIC_INCLUDE_CUSTOM_CSS === 'true') {
customHeadHtmlSnippet += '<link rel="stylesheet" href="custom.css">';
}
return customHeadHtmlSnippet;
},
};
}

View File

@@ -90,10 +90,12 @@ export function makeSendAppPage(opts: {
const tagManagerSnippet = needTagManager ? getTagManagerSnippet(process.env.GOOGLE_TAG_MANAGER_ID) : '';
const staticOrigin = process.env.APP_STATIC_URL || "";
const staticBaseUrl = `${staticOrigin}/v/${options.tag || tag}/`;
const customHeadHtmlSnippet = server?.create.getExtraHeadHtml?.() ?? "";
const warning = testLogin ? "<div class=\"dev_warning\">Authentication is not enforced</div>" : "";
const content = fileContent
.replace("<!-- INSERT WARNING -->", warning)
.replace("<!-- INSERT BASE -->", `<base href="${staticBaseUrl}">` + tagManagerSnippet)
.replace("<!-- INSERT CUSTOM -->", customHeadHtmlSnippet)
.replace("<!-- INSERT CONFIG -->", `<script>window.gristConfig = ${JSON.stringify(config)};</script>`);
resp.status(options.status).type('html').send(content);
};