switching themes via loading only specific CSS

This commit is contained in:
zadam
2021-09-26 15:24:37 +02:00
parent 2fcb0c05c0
commit 113bebed3b
15 changed files with 219 additions and 232 deletions

View File

@@ -19,7 +19,7 @@ function index(req, res) {
res.render(view, {
csrfToken: csrfToken,
theme: options.theme,
themeCssUrl: getThemeCssUrl(options.theme),
headingStyle: options.headingStyle,
mainFontSize: parseInt(options.mainFontSize),
treeFontSize: parseInt(options.treeFontSize),
@@ -36,8 +36,28 @@ function index(req, res) {
});
}
function getThemeCssUrl(theme) {
if (theme === 'light') {
return false; // light theme is always loaded as baseline
}
if (theme === 'dark') {
return `stylesheets/theme-dark.css`;
}
else {
const themeNote = attributeService.getNoteWithLabel('appTheme', theme);
if (themeNote) {
return `api/notes/download/${themeNote.noteId}`;
}
else {
return false; // baseline light theme
}
}
}
function getAppCssNoteIds() {
return attributeService.getNoteIdsWithLabels(['appCss', 'appTheme']);
return attributeService.getNotesWithLabel('appCss').map(note => note.noteId);
}
module.exports = {