Skip to content

Commit dcb4728

Browse files
committed
feat(astro): add 'themes' option to the tutorialkit astro integration
1 parent 05eb7ab commit dcb4728

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

packages/astro/src/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { fileURLToPath } from 'node:url';
22
import type { AstroConfig, AstroIntegration } from 'astro';
3-
import type { ExpressiveCodePlugin } from 'astro-expressive-code';
3+
import type { ExpressiveCodePlugin, ThemeObjectOrShikiThemeName } from 'astro-expressive-code';
44
import { extraIntegrations } from './integrations.js';
55
import { updateMarkdownConfig } from './remark/index.js';
66
import { tutorialkitCore } from './vite-plugins/core.js';
@@ -67,6 +67,15 @@ export interface Options {
6767
* @default []
6868
*/
6969
expressiveCodePlugins?: ExpressiveCodePlugin[];
70+
71+
/**
72+
* Themes for expressive code.
73+
* Make sure to provide a light and a dark theme if you want support for both light and dark modes.
74+
* Default values are ['light-plus', 'dark-plus']
75+
*
76+
* @default ['light-plus', 'dark-plus']
77+
*/
78+
themes?: [ThemeObjectOrShikiThemeName, ThemeObjectOrShikiThemeName];
7079
}
7180

7281
export default function createPlugin({
@@ -75,6 +84,7 @@ export default function createPlugin({
7584
isolation,
7685
enterprise,
7786
expressiveCodePlugins = [],
87+
themes,
7888
}: Options = {}): AstroIntegration {
7989
const webcontainerFiles = new WebContainerFiles();
8090

@@ -149,7 +159,7 @@ export default function createPlugin({
149159
config.integrations.splice(
150160
selfIndex + 1,
151161
0,
152-
...extraIntegrations({ root: fileURLToPath(config.root), expressiveCodePlugins }),
162+
...extraIntegrations({ root: fileURLToPath(config.root), expressiveCodePlugins, themes }),
153163
);
154164
},
155165
'astro:config:done'({ config }) {

packages/astro/src/integrations.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,28 @@ import react from '@astrojs/react';
44
import { pluginCollapsibleSections } from '@expressive-code/plugin-collapsible-sections';
55
import { pluginLineNumbers } from '@expressive-code/plugin-line-numbers';
66
import { getInlineContentForPackage } from '@tutorialkit/theme';
7-
import expressiveCode, { type ExpressiveCodePlugin } from 'astro-expressive-code';
7+
import expressiveCode, { type ExpressiveCodePlugin, type ThemeObjectOrShikiThemeName } from 'astro-expressive-code';
88
import UnoCSS from 'unocss/astro';
99

1010
export function extraIntegrations({
1111
root,
1212
expressiveCodePlugins = [],
13+
themes = ['light-plus', 'dark-plus'],
1314
}: {
1415
root: string;
1516
expressiveCodePlugins?: ExpressiveCodePlugin[];
17+
18+
/**
19+
* Themes for Expressive Code.
20+
* Takes a tuple of themes, e.g. `[lightTheme, darkTheme]`.
21+
*/
22+
themes?: [ThemeObjectOrShikiThemeName, ThemeObjectOrShikiThemeName];
1623
}) {
1724
return [
1825
react(),
1926
expressiveCode({
2027
plugins: [pluginCollapsibleSections(), pluginLineNumbers(), ...expressiveCodePlugins],
21-
themes: ['dark-plus', 'light-plus'],
28+
themes,
2229
customizeTheme: (theme) => {
2330
const isDark = theme.type === 'dark';
2431

@@ -35,13 +42,7 @@ export function extraIntegrations({
3542
};
3643
},
3744
themeCssSelector: (theme) => {
38-
let customThemeName = 'light';
39-
40-
if (theme.name === 'dark-plus') {
41-
customThemeName = 'dark';
42-
}
43-
44-
return `[data-theme='${customThemeName}']`;
45+
return `[data-theme='${theme.type}']`;
4546
},
4647
defaultProps: {
4748
showLineNumbers: false,

0 commit comments

Comments
 (0)