From 48a1bd47b3cf45916b5f3a52a468e982b6b38bad Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sat, 24 Nov 2018 00:41:36 -0800 Subject: [PATCH] refactor(themes): use CSS specificity order for themes (#684) The point of this PR is to make it easier to implement scrollbars (#683). With this PR, the themes move from a body tag-based system (e.g. `body.theme-scarlet`) to a system where they simply declare global CSS and we use CSS specificity order to give us the right theme. --- bin/build-sass.js | 21 ++++--- inline-script.js | 4 +- package-lock.json | 71 ++++++++++------------ package.json | 1 - routes/_store/observers/onlineObservers.js | 5 +- routes/_utils/themeEngine.js | 42 ++++++++++--- scss/themes/_base.scss | 3 +- scss/themes/_dark.scss | 2 +- scss/themes/_default.scss | 6 +- scss/themes/_offline.scss | 4 -- scss/themes/cobalt.scss | 5 +- scss/themes/gecko.scss | 4 -- scss/themes/hacker.scss | 5 +- scss/themes/hotpants.scss | 4 -- scss/themes/majesty.scss | 4 -- scss/themes/oaken.scss | 4 -- scss/themes/ozark.scss | 7 +-- scss/themes/punk.scss | 5 +- scss/themes/riot.scss | 5 +- scss/themes/scarlet.scss | 4 -- scss/themes/seafoam.scss | 4 -- scss/themes/sorcery.scss | 5 +- templates/2xx.html | 18 +++--- tests/spec/010-focus.js | 6 +- tests/spec/020-themes.js | 8 +-- tests/utils.js | 14 ++++- 26 files changed, 120 insertions(+), 141 deletions(-) diff --git a/bin/build-sass.js b/bin/build-sass.js index 5c804249..9c62c006 100755 --- a/bin/build-sass.js +++ b/bin/build-sass.js @@ -34,18 +34,21 @@ function doWatch () { chokidar.watch() } -async function compileGlobalSass () { - let results = await Promise.all([ - render({ file: defaultThemeScss, outputStyle: 'compressed' }), - render({ file: globalScss, outputStyle: 'compressed' }), - render({ file: offlineThemeScss, outputStyle: 'compressed' }) - ]) +async function renderCss (file) { + return (await render({ file, outputStyle: 'compressed' })).css +} - let css = results.map(_ => _.css).join('') +async function compileGlobalSass () { + let mainStyle = (await Promise.all([defaultThemeScss, globalScss].map(renderCss))).join('') + let offlineStyle = (await renderCss(offlineThemeScss)) let html = await readFile(html2xxFile, 'utf8') - html = html.replace(/`) + html = html.replace(/[\s\S]+/, + `\n` + + `\n` + + `\n` + + `` + ) await writeFile(html2xxFile, html, 'utf8') } diff --git a/inline-script.js b/inline-script.js index 6af6cd7e..3d76f451 100644 --- a/inline-script.js +++ b/inline-script.js @@ -7,11 +7,11 @@ if (localStorage.store_currentInstance && localStorage.store_instanceThemes) { let safeParse = (str) => str === 'undefined' ? undefined : JSON.parse(str) let theme = safeParse(localStorage.store_instanceThemes)[safeParse(localStorage.store_currentInstance)] if (theme && theme !== 'default') { - document.body.classList.add(`theme-${theme}`) let link = document.createElement('link') link.rel = 'stylesheet' link.href = `/theme-${theme}.css` - document.head.appendChild(link) + // inserting before the offline + +