Theme remixing fix: Order of params should not matter (#772)

Also renamed the `theme` export to `getThemeCode` since it was being renamed everywhere it was imported.
This commit is contained in:
Lea Verou
2025-02-21 14:03:55 -05:00
committed by GitHub
parent dd671e15aa
commit 71e7227763
3 changed files with 13 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
/**
* Get import code for remixed themes and tweaked palettes.
*/
export { theme as getThemeCode } from './tweak/code.js';
export { getThemeCode } from './tweak/code.js';
export { cdnUrl, hueRanges, hues, selectors, tints, urls } from './tweak/data.js';
export { default as Permalink } from './tweak/permalink.js';

View File

@@ -25,18 +25,23 @@ export function cssLiteral(value, options = {}) {
}
}
export function theme(base, params, options) {
// Params in correct order
export const themeParams = ['colors', 'palette', 'brand', 'typography'];
export function getThemeCode(base, params, options) {
let ret = [];
if (base) {
ret.push(urls.theme(base));
}
ret.push(
...Object.entries(params)
.filter(([aspect, id]) => Boolean(id))
.map(([aspect, id]) => urls[aspect](id)),
);
for (let aspect of themeParams) {
let value = params[aspect];
if (value) {
ret.push(urls[aspect](value));
}
}
return ret.map(url => cssImport(url, options)).join('\n');
}

View File

@@ -37,7 +37,7 @@ eleventyComputed:
<script type="module">
import { urls as stylesheetURLs, docsURLs, icons } from "/assets/scripts/tweak/data.js";
import { theme as getThemeCode } from "/assets/scripts/tweak/code.js";
import { getThemeCode } from "/assets/scripts/tweak/code.js";
function updateTheme() {
let params = new URLSearchParams(window.location.search);