1
0

Support multiple customStyles pages

This commit is contained in:
Zef Hemel 2023-08-28 15:52:39 +02:00
parent cc2448b91f
commit 54d2deea15
3 changed files with 24 additions and 15 deletions

View File

@ -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",
);
}
}

View File

@ -34,7 +34,7 @@ export type PanelMode = number;
export type BuiltinSettings = {
indexPage: string;
customStyles?: string;
customStyles?: string | string[];
plugOverrides?: Record<string, Partial<Manifest>>;
// Format: compatible with docker ignore
spaceIgnore?: string;

View File

@ -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