Skip to content

Commit ae377a2

Browse files
committed
Parse theme names from .css file ([data-theme="..."]) instead of outdated themes.json
1 parent 19e507d commit ae377a2

File tree

3 files changed

+19
-1807
lines changed

3 files changed

+19
-1807
lines changed

packages/tailwind/src/lib/theme.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,29 @@ export function createThemeColors(colorSpace: SupportedColorSpace) {
4646
}
4747

4848
/**
49-
* Get themes names split into light and dark collections determined by `color-scheme` property
49+
* Get themes names (`[data-theme="..."]`) split into light and dark collections determined by `color-scheme` property
5050
*/
51-
export function getThemeNames(themes: Record<string, any>) {
52-
const light: string[] = [];
53-
const dark: string[] = [];
51+
export function getThemeNames(cssContent: string) {
52+
const themeBlocks = cssContent.split(/\[data-theme=/);
5453

55-
entries(themes).map(([themeName, props]) => {
56-
if (props['color-scheme'] === 'dark') {
54+
const light = [];
55+
const dark = [];
56+
57+
// Skip first element as it's content before first theme
58+
for (let i = 1; i < themeBlocks.length; i++) {
59+
const block = themeBlocks[i];
60+
61+
// Extract theme name
62+
const nameMatch = block.match(/^"([^"]+)"/);
63+
if (!nameMatch) continue;
64+
const themeName = nameMatch[1];
65+
66+
if (block.includes('color-scheme: dark')) {
5767
dark.push(themeName);
5868
} else {
5969
light.push(themeName);
6070
}
61-
});
71+
}
6272

6373
return { light, dark };
6474
}

sites/docs/src/routes/+layout.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { env } from '$env/dynamic/private';
22

3-
import themes from '../../themes.json' assert { type: 'json' };
43
import { getThemeNames } from '@layerstack/tailwind';
4+
import themeCss from '@layerstack/tailwind/themes/all.css?raw';
55

66
export async function load() {
77
return {
8-
themes: getThemeNames(themes),
8+
themes: getThemeNames(themeCss),
99
// themes: { light: ['light'], dark: ['dark'] },
1010
pr_id: env.VERCEL_GIT_PULL_REQUEST_ID,
1111
};

0 commit comments

Comments
 (0)