Skip to content

Commit 964b4aa

Browse files
committed
chore: migrate to Astro 7 and Sätteri
1 parent f2713ed commit 964b4aa

9 files changed

Lines changed: 843 additions & 877 deletions

File tree

packages/docs/astro.config.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { satteri } from '@astrojs/markdown-satteri';
12
import starlight from '@astrojs/starlight';
23
import type { ExpressiveCodeTheme } from '@astrojs/starlight/expressive-code';
34
import { defineConfig } from 'astro/config';
4-
import remarkDirective from 'remark-directive';
5-
import { fixInternalLinks } from './remark/fixInternalLinks.ts';
6-
import { transformDirectives } from './remark/transformDirectives.ts';
5+
import { fixInternalLinks } from './plugins/fixInternalLinks.ts';
6+
import { transformDirectives } from './plugins/transformDirectives.ts';
77

88
const setForeground = (theme: ExpressiveCodeTheme, scope: string, value: string) => {
99
const settings = theme.settings.find(setting => setting.scope?.includes(scope));
@@ -21,7 +21,10 @@ export default defineConfig({
2121
'/guides/writing-a-plugin': '/writing-a-plugin',
2222
},
2323
markdown: {
24-
remarkPlugins: [fixInternalLinks, transformDirectives, remarkDirective],
24+
processor: satteri({
25+
features: { directive: true },
26+
mdastPlugins: [fixInternalLinks, transformDirectives],
27+
}),
2528
},
2629
integrations: [
2730
starlight({

packages/docs/package.json

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,16 @@
1919
},
2020
"dependencies": {
2121
"@astro-community/astro-embed-youtube": "0.5.10",
22-
"@astrojs/starlight": "0.40.0",
22+
"@astrojs/markdown-satteri": "0.3.3",
23+
"@astrojs/starlight": "0.41.3",
24+
"satteri": "0.9.4",
2325
"sharp": "0.35.1"
2426
},
2527
"devDependencies": {
2628
"@astrojs/check": "0.9.9",
2729
"@octokit/graphql": "^9.0.3",
28-
"@types/mdast": "4.0.4",
29-
"@types/unist": "3.0.3",
30-
"astro": "6.4.8",
31-
"hastscript": "9.0.1",
32-
"picocolors": "^1.1.1",
33-
"remark-directive": "4.0.0",
34-
"remark-frontmatter": "5.0.0",
35-
"remark-gfm": "4.0.1",
36-
"remark-parse": "11.0.0",
37-
"remark-stringify": "11.0.0",
38-
"unified": "11.0.5",
39-
"unist-builder": "4.0.0",
40-
"unist-util-visit": "5.1.0"
30+
"astro": "7.0.6",
31+
"picocolors": "^1.1.1"
4132
},
4233
"engines": {
4334
"node": ">=22.0.0"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import pc from 'picocolors';
2+
import { defineMdastPlugin } from 'satteri';
3+
4+
const dateTimeFormat = new Intl.DateTimeFormat([], {
5+
hour: '2-digit',
6+
minute: '2-digit',
7+
second: '2-digit',
8+
hour12: false,
9+
});
10+
11+
const rewrite = (url: string) => url.replace(/(?:\/index)?\.mdx?(#.+)?$/, '$1');
12+
13+
const log = (from: string, to: string) => {
14+
console.log(`${pc.dim(dateTimeFormat.format(new Date()))} ${pc.cyan('[fix-link]')} Modify ${from}${to}`);
15+
};
16+
17+
export const fixInternalLinks = defineMdastPlugin({
18+
name: 'fix-internal-links',
19+
link(node, ctx) {
20+
if (node.url.startsWith('.')) {
21+
const next = rewrite(node.url);
22+
ctx.setProperty(node, 'url', next);
23+
log(node.url, next);
24+
}
25+
},
26+
definition(node, ctx) {
27+
if (node.url.startsWith('.')) {
28+
const next = rewrite(node.url);
29+
ctx.setProperty(node, 'url', next);
30+
log(node.url, next);
31+
}
32+
},
33+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { defineMdastPlugin } from 'satteri';
2+
3+
export const transformDirectives = defineMdastPlugin({
4+
name: 'transform-directives',
5+
containerDirective(node, ctx) {
6+
ctx.setProperty(node, 'data', {
7+
hName: node.name,
8+
hProperties: node.attributes ?? {},
9+
});
10+
},
11+
leafDirective(node, ctx) {
12+
ctx.setProperty(node, 'data', {
13+
hName: node.name,
14+
hProperties: node.attributes ?? {},
15+
});
16+
},
17+
textDirective(node, ctx) {
18+
ctx.setProperty(node, 'data', {
19+
hName: node.name,
20+
hProperties: node.attributes ?? {},
21+
});
22+
},
23+
});

packages/docs/remark/fixInternalLinks.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

packages/docs/remark/transformDirectives.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)