From 54d2deea153992f367a0b2cd610e941e2a85885b Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Mon, 28 Aug 2023 15:52:39 +0200 Subject: [PATCH] Support multiple customStyles pages --- web/client.ts | 35 ++++++++++++++++++++++------------- web/types.ts | 2 +- website/SETTINGS.md | 2 +- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/web/client.ts b/web/client.ts index 7185aaf5..14a57a6f 100644 --- a/web/client.ts +++ b/web/client.ts @@ -794,20 +794,29 @@ export class Client { async loadCustomStyles() { if (this.settings.customStyles) { - try { - const { text: stylesText } = await this.space.readPage( - cleanPageRef(this.settings.customStyles), - ); - const cssBlockRegex = /```css([^`]+)```/; - const match = cssBlockRegex.exec(stylesText); - if (!match) { - return; - } - const css = match[1]; - document.getElementById("custom-styles")!.innerHTML = css; - } catch (e: any) { - console.error("Failed to load custom styles", e); + const accumulatedCSS: string[] = []; + let customStylePages = this.settings.customStyles; + if (!Array.isArray(customStylePages)) { + customStylePages = [customStylePages]; } + for (const customStylesPage of customStylePages) { + try { + const { text: stylesText } = await this.space.readPage( + cleanPageRef(customStylesPage), + ); + const cssBlockRegex = /```css([^`]+)```/; + const match = cssBlockRegex.exec(stylesText); + if (!match) { + return; + } + accumulatedCSS.push(match[1]); + } catch (e: any) { + console.error("Failed to load custom styles", e); + } + } + document.getElementById("custom-styles")!.innerHTML = accumulatedCSS.join( + "\n\n", + ); } } diff --git a/web/types.ts b/web/types.ts index 10bfa349..04ffc5d7 100644 --- a/web/types.ts +++ b/web/types.ts @@ -34,7 +34,7 @@ export type PanelMode = number; export type BuiltinSettings = { indexPage: string; - customStyles?: string; + customStyles?: string | string[]; plugOverrides?: Record>; // Format: compatible with docker ignore spaceIgnore?: string; diff --git a/website/SETTINGS.md b/website/SETTINGS.md index 30c74d54..2946167c 100644 --- a/website/SETTINGS.md +++ b/website/SETTINGS.md @@ -4,7 +4,7 @@ This page contains settings for configuring SilverBullet and its Plugs. Changing # Initial page to load when launching SB indexPage: "[[SilverBullet]]" -# Load custom CSS styles from the following page +# Load custom CSS styles from the following page, can also be an array customStyles: "[[STYLES]]" # Template related settings