Skip to content

Commit eb28203

Browse files
authored
🩹 Merge colors, fonts, and font sizes from base theme.json even when disabled (#10)
1 parent 8a134e9 commit eb28203

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

‎src/index.ts‎

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -961,33 +961,56 @@ export function wordpressThemeJson(config: ThemeJsonConfig = {}): VitePlugin {
961961
settings: {
962962
...baseThemeJson.settings,
963963
color: disableTailwindColors
964-
? undefined
964+
? baseThemeJson.settings?.color
965965
: {
966966
...baseThemeJson.settings?.color,
967967
palette: [
968968
...(baseThemeJson.settings?.color
969969
?.palette || []),
970970
...(colorEntries || []),
971-
],
971+
].filter(
972+
(entry, index, self) =>
973+
index ===
974+
self.findIndex(
975+
(e) => e.slug === entry.slug
976+
)
977+
),
972978
},
973979
typography: {
974980
...baseThemeJson.settings?.typography,
975-
defaultFontSizes: false,
976-
customFontSize: false,
981+
defaultFontSizes:
982+
baseThemeJson.settings?.typography
983+
?.defaultFontSizes ?? false,
984+
customFontSize:
985+
baseThemeJson.settings?.typography
986+
?.customFontSize ?? false,
977987
fontFamilies: disableTailwindFonts
978-
? undefined
988+
? baseThemeJson.settings?.typography
989+
?.fontFamilies
979990
: [
980991
...(baseThemeJson.settings?.typography
981992
?.fontFamilies || []),
982993
...(fontFamilyEntries || []),
983-
],
994+
].filter(
995+
(entry, index, self) =>
996+
index ===
997+
self.findIndex(
998+
(e) => e.slug === entry.slug
999+
)
1000+
),
9841001
fontSizes: disableTailwindFontSizes
985-
? undefined
1002+
? baseThemeJson.settings?.typography?.fontSizes
9861003
: [
9871004
...(baseThemeJson.settings?.typography
9881005
?.fontSizes || []),
9891006
...(fontSizeEntries || []),
990-
],
1007+
].filter(
1008+
(entry, index, self) =>
1009+
index ===
1010+
self.findIndex(
1011+
(e) => e.slug === entry.slug
1012+
)
1013+
),
9911014
},
9921015
},
9931016
};

‎tests/index.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,9 @@ describe('wordpressThemeJson', () => {
399399

400400
const themeJson = JSON.parse(emitFile.mock.calls[0][0].source);
401401

402-
expect(themeJson.settings.color?.palette).toBeUndefined();
403-
expect(themeJson.settings.typography.fontFamilies).toBeUndefined();
404-
expect(themeJson.settings.typography.fontSizes).toBeUndefined();
402+
expect(themeJson.settings.color?.palette).toEqual([]);
403+
expect(themeJson.settings.typography.fontFamilies).toEqual([]);
404+
expect(themeJson.settings.typography.fontSizes).toEqual([]);
405405
});
406406

407407
it('should handle invalid font properties', () => {

0 commit comments

Comments
 (0)