Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export default defineConfig({
},
}),
expressiveCode({
themes: [expressiveCodeConfig.theme, expressiveCodeConfig.theme],
// themes: [expressiveCodeConfig.theme, expressiveCodeConfig.theme],
themes: expressiveCodeConfig.themes,
plugins: [
pluginCollapsibleSections(),
pluginLineNumbers(),
Expand Down
3 changes: 2 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@ export const licenseConfig: LicenseConfig = {
export const expressiveCodeConfig: ExpressiveCodeConfig = {
// Note: Some styles (such as background color) are being overridden, see the astro.config.mjs file.
// Please select a dark theme, as this blog theme currently only supports dark background color
theme: "github-dark",
// theme: "github-dark",
themes: ["github-dark", "github-dark-dimmed"],
};
3 changes: 2 additions & 1 deletion src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,6 @@ export type BlogPostData = {
};

export type ExpressiveCodeConfig = {
theme: string;
// theme: string;
themes: string[];
};
15 changes: 10 additions & 5 deletions src/utils/setting-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,16 @@ export function applyThemeToDocument(theme: LIGHT_DARK_MODE) {
break;
}

// Set the theme for Expressive Code
document.documentElement.setAttribute(
"data-theme",
expressiveCodeConfig.theme,
);
// Set the theme for Expressive Code (auto switch)
const themes = expressiveCodeConfig.themes || [];
const lightTheme = themes[0];
const darkTheme = themes.length > 1 ? themes[1] : themes[0];

const isDarkNow = document.documentElement.classList.contains("dark");
const autoTheme = isDarkNow ? darkTheme : lightTheme;
if (autoTheme) {
document.documentElement.setAttribute("data-theme", autoTheme);
}
}

export function setTheme(theme: LIGHT_DARK_MODE): void {
Expand Down
Loading