From 71e722776384ee2b17e0a1419694e2b37d244120 Mon Sep 17 00:00:00 2001 From: Lea Verou Date: Fri, 21 Feb 2025 14:03:55 -0500 Subject: [PATCH] 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. --- docs/assets/scripts/tweak.js | 2 +- docs/assets/scripts/tweak/code.js | 17 +++++++++++------ docs/docs/themes/demo.njk | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/docs/assets/scripts/tweak.js b/docs/assets/scripts/tweak.js index ef2a4f849..764eafab7 100644 --- a/docs/assets/scripts/tweak.js +++ b/docs/assets/scripts/tweak.js @@ -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'; diff --git a/docs/assets/scripts/tweak/code.js b/docs/assets/scripts/tweak/code.js index d05328d7b..8f2ca3405 100644 --- a/docs/assets/scripts/tweak/code.js +++ b/docs/assets/scripts/tweak/code.js @@ -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'); } diff --git a/docs/docs/themes/demo.njk b/docs/docs/themes/demo.njk index cb8a4ef8e..018e4cb9a 100644 --- a/docs/docs/themes/demo.njk +++ b/docs/docs/themes/demo.njk @@ -37,7 +37,7 @@ eleventyComputed: