Skip to content

Commit 2b43332

Browse files
feat: enhance documentation and configuration options for EC-Twoslash (#78)
* feat: enhance documentation and configuration options for EC-Twoslash * chore: update VSCode settings and remove obsolete configuration files * fix: correct formatting in astro.config.mts for analytics script inclusion * feat: enhance style override documentation for EC-Twoslash * feat: enhance documentation and add Vue integration examples * feat: update Vue integration documentation order and add TypeScript integration guide * feat: update TypeScript label to include TSX in documentation
1 parent ec6299c commit 2b43332

17 files changed

Lines changed: 729 additions & 38 deletions

File tree

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
"twocustom",
5252
"twoerror",
5353
"twoslash",
54+
"Twoslash",
5455
"Twoslasher",
56+
"Twoslashers",
5557
"UIDOM",
5658
"withstudiocms"
5759
]

biome.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,22 @@
3434
"organizeImports": "on"
3535
}
3636
}
37-
}
37+
},
38+
"overrides": [
39+
{
40+
"includes": ["**/*.astro"],
41+
"linter": {
42+
"rules": {
43+
"correctness": {
44+
"noUnusedImports": "off",
45+
"noUnusedVariables": "off"
46+
},
47+
"style": {
48+
"useConst": "off",
49+
"useImportType": "off"
50+
}
51+
}
52+
}
53+
}
54+
]
3855
}

docs/.vscode/extensions.json

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

docs/.vscode/launch.json

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

docs/astro.config.mts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ export default defineConfig({
2323
alt: "EC Twoslash Logo",
2424
},
2525
credits: true,
26+
components: {
27+
PageTitle: "./src/components/starlight/PageTitle.astro",
28+
},
2629
social: [
2730
{
2831
label: "GitHub",
@@ -161,6 +164,10 @@ export default defineConfig({
161164
label: "Getting Started",
162165
autogenerate: { directory: "getting-started" },
163166
},
167+
{
168+
label: "Available Twoslashers",
169+
autogenerate: { directory: "twoslashers" },
170+
},
164171
{
165172
label: "Usage",
166173
items: [
@@ -190,6 +197,10 @@ export default defineConfig({
190197
},
191198
],
192199
},
200+
{
201+
label: "Reference",
202+
autogenerate: { directory: "reference" },
203+
},
193204
],
194205
}),
195206
],
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
const body = (await Astro.slots.render("default")).trim();
3+
const signature = body.match(/^<ul>\s*<li>\s*([\s\S]*?)\s*<\/li>\s*<\/ul>/)?.[1] ?? "";
4+
const signatureParts = signature.split(/<\/li>\s*<li>/);
5+
const extractSignaturePart = (name: string) => {
6+
name = `${name}: `;
7+
const idx = signatureParts.findIndex((part) => part.startsWith(name));
8+
if (idx === -1) return;
9+
const part = (signatureParts[idx] ?? "").replace(name, "").trim();
10+
signatureParts.splice(idx, 1);
11+
return part;
12+
};
13+
const propertyType = extractSignaturePart("Type");
14+
const defaultValue = extractSignaturePart("Default");
15+
const availability = extractSignaturePart("Availability");
16+
---
17+
18+
<div class="property-signature not-content">
19+
{propertyType && (
20+
<span class="name">Type:</span>
21+
<span class="value" set:html={propertyType} />
22+
)}
23+
{defaultValue && (
24+
<span class="name">Default:</span>
25+
<span class="value" set:html={defaultValue} />
26+
)}
27+
{availability && (
28+
<span class="name">Availability:</span>
29+
<span set:html={availability} />
30+
)}
31+
</div>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
import { Badge } from "@astrojs/starlight/components";
3+
import Default from "@astrojs/starlight/components/PageTitle.astro";
4+
5+
const {
6+
entry: { data },
7+
} = Astro.locals.starlightRoute;
8+
---
9+
{
10+
(data.template === 'splash' && data.title === "404")
11+
? <slot/>
12+
: data.addedIn
13+
? <Default><slot/></Default><Badge text={`Added in ${data.addedIn}`} variant="success" />
14+
: <Default><slot/></Default>
15+
}

docs/src/content.config.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
import { defineCollection } from "astro:content";
22
import { docsLoader } from "@astrojs/starlight/loaders";
33
import { docsSchema } from "@astrojs/starlight/schema";
4+
import { z } from "astro/zod";
5+
6+
const extendedDocsSchema = z.object({
7+
addedIn: z.string().optional(),
8+
});
49

510
export const collections = {
6-
docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }),
11+
docs: defineCollection({
12+
loader: docsLoader(),
13+
schema: docsSchema({
14+
extend: extendedDocsSchema,
15+
}),
16+
}),
717
};

docs/src/content/docs/getting-started/basic.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Using the homepage as an example, here is a simple code sample:
2121
```ts twoslash
2222
// @errors: 2540
2323

24-
console.log((1 + 2 + 3 + 4).toFixed(2))
24+
console.log((1 + 2 + 3 + 4).toFixed(2));
2525
// ^|
2626

2727
/** A Basic Todo interface*/
@@ -34,7 +34,7 @@ const todo: Readonly<Todo> = {
3434
// ^?
3535
}
3636

37-
todo.title = 'Hello'
37+
todo.title = 'Hello';
3838
```
3939

4040
``````
@@ -46,7 +46,7 @@ todo.title = 'Hello'
4646
```ts twoslash
4747
// @errors: 2540
4848

49-
console.log((1 + 2 + 3 + 4).toFixed(2))
49+
console.log((1 + 2 + 3 + 4).toFixed(2));
5050
// ^|
5151

5252
/** A Basic Todo interface*/
@@ -59,7 +59,7 @@ const todo: Readonly<Todo> = {
5959
// ^?
6060
}
6161

62-
todo.title = 'Hello'
62+
todo.title = 'Hello';
6363
```
6464

6565
</TabItem>

docs/src/content/docs/getting-started/installation.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default defineConfig({
6060
<TabItem label='ec.config.mjs'>
6161

6262
```ts twoslash ins={2, 5}
63-
import { defineEcConfig } from 'astro-expressive-code'
63+
import { defineEcConfig } from 'astro-expressive-code';
6464
import ecTwoSlash from "expressive-code-twoslash";
6565

6666
export default defineEcConfig({
@@ -121,7 +121,7 @@ export default defineEcConfig({
121121
<TabItem label='Next.js'>
122122

123123
```ts twoslash title="next.config.mjs" ins={2, 6}
124-
import rehypeExpressiveCode from 'rehype-expressive-code'
124+
import rehypeExpressiveCode from 'rehype-expressive-code';
125125
import ecTwoSlash from "expressive-code-twoslash";
126126

127127
/** @type {import('rehype-expressive-code').RehypeExpressiveCodeOptions} */
@@ -143,7 +143,7 @@ For more information on how to add to your Next.js config, see the [Expressive C
143143
Default config options shown.
144144

145145
```ts twoslash
146-
import { defineEcConfig } from 'astro-expressive-code'
146+
import { defineEcConfig } from 'astro-expressive-code';
147147
import ecTwoSlash from "expressive-code-twoslash";
148148
import ts from "typescript";
149149

0 commit comments

Comments
 (0)