summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/web
diff options
context:
space:
mode:
authorGianni Ceccarelli <gceccarelli@veritone.com>2023-12-14 13:58:07 +0000
committerGianni Ceccarelli <gceccarelli@veritone.com>2023-12-14 14:24:10 +0000
commit7f2a66f262e5b378909c15f5a2c51befeffbf82a (patch)
tree4dbfe37ce97d7e6f3f6c08441e0a0101352d97ea /packages/backend/src/server/web
parentchore: update contributers and add note to docker compose (diff)
downloadsharkey-7f2a66f262e5b378909c15f5a2c51befeffbf82a.tar.gz
sharkey-7f2a66f262e5b378909c15f5a2c51befeffbf82a.tar.bz2
sharkey-7f2a66f262e5b378909c15f5a2c51befeffbf82a.zip
allow a theme to specify a font - #225
Diffstat (limited to 'packages/backend/src/server/web')
-rw-r--r--packages/backend/src/server/web/boot.js23
1 files changed, 22 insertions, 1 deletions
diff --git a/packages/backend/src/server/web/boot.js b/packages/backend/src/server/web/boot.js
index e1864ae124..e1aaee1d49 100644
--- a/packages/backend/src/server/web/boot.js
+++ b/packages/backend/src/server/web/boot.js
@@ -106,8 +106,29 @@
//#region Theme
const theme = localStorage.getItem('theme');
+ const themeFontFaceName = 'sharkey-theme-font-face';
if (theme) {
- for (const [k, v] of Object.entries(JSON.parse(theme))) {
+ let existingFontFace;
+ document.fonts.forEach((v,k,s)=>{if (v.family === themeFontFaceName) existingFontFace=v;});
+ if (existingFontFace) document.fonts.delete(existingFontFace);
+
+ const themeProps = JSON.parse(theme);
+ const fontFaceSrc = themeProps.fontFaceSrc;
+ const fontFaceOpts = themeProps.fontFaceOpts || {};
+ if (fontFaceSrc) {
+ const fontFace = new FontFace(
+ themeFontFaceName,
+ fontFaceSrc, fontFaceOpts || {},
+ );
+ document.fonts.add(fontFace);
+ fontFace.load().catch(
+ (failure) => {
+ console.log(failure)
+ }
+ );
+ }
+ for (const [k, v] of Object.entries(themeProps)) {
+ if (k.startsWith('font')) continue;
document.documentElement.style.setProperty(`--${k}`, v.toString());
// HTMLの theme-color 適用