Skip to content

Commit ac87a1f

Browse files
committed
add typescript twoslash
1 parent a230c65 commit ac87a1f

File tree

10 files changed

+5256
-1706
lines changed

10 files changed

+5256
-1706
lines changed

app/global.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@import 'tailwindcss';
22
@import 'fumadocs-ui/css/neutral.css';
33
@import 'fumadocs-ui/css/preset.css';
4+
@import 'fumadocs-twoslash/twoslash.css';
45

56
@source '../node_modules/fumadocs-ui/dist/**/*.js';

content/docs/Hydro/dev/typescript.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ title: 使用 TypeScript 编写插件
1010
- 修改代码后,尝试更新系统时,自己的修改被新版本覆盖,需要手动合并(或是直接丢失了更改),极大幅度增加维护成本;
1111
- 第三方社区出现的大量修改分支无法直接按需求进行组合/拼装,或是功能间存在冲突;
1212

13-
基于以上痛点,Hydro 开创性的使用了插件系统,提供了一套完整的开发 API 供开发者使用,开发者基于提供的较稳定的 API 进行功能的编写,而无需过多关心内部实现,在多个版本间达到一致性,同时提供热重载功能,提升开发效率。
13+
基于以上痛点,Hydro 开创性的使用了插件系统,提供了一套完整的开发 API 供开发者使用,开发者基于提供的较稳定的 API 进行功能的编写,而无需过多关心内部实现,将功能拆分成多个最小的单元,允许用户根据需要进行自由组合,并在多个版本间达到一致性,同时提供热重载功能,提升开发效率。
1414

1515
此教程将以编写剪贴板插件为例进行插件开发的说明。
1616

@@ -85,12 +85,12 @@ args 为传入的参数集合(包括 QueryString, Body, Path)中的全部参
8585

8686
# Step3 index.ts
8787

88-
```ts
88+
```ts twoslash
8989
// @noErrors
9090
// @module: esnext
9191
// @filename: index.ts
9292
import {
93-
db, definePlugin, Handler, NotFoundError, param, PermissionError, PRIV, Types,
93+
db, definePlugin, Handler, NotFoundError, randomstring, param, PermissionError, PRIV, Types,
9494
} from 'hydrooj';
9595

9696
const coll = db.collection('paste');
@@ -112,7 +112,7 @@ declare module 'hydrooj' {
112112
}
113113

114114
async function add(userId: number, content: string, isPrivate: boolean): Promise<string> {
115-
const pasteId = String.random(16); // Hydro 提供了此方法,创建一个长度为16的随机字符串
115+
const pasteId = randomstring(16);
116116
// 使用 mongodb 为数据库驱动,相关操作参照其文档
117117
const result = await coll.insertOne({
118118
_id: pasteId,

content/docs/Hydro/install/compiler.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ title: 编译器
1313
以下是常用编译器的示例:
1414

1515
```sh
16-
nix-env -iA nixpkgs.busybox nixpkgs.bash nixpkgs.diffutils nixpkgs.unzip # 基础组件,已预装,不建议删除
16+
nix-env -iA nixpkgs.coreutils nixpkgs.bash nixpkgs.gawk nixpkgs.unzip # 基础组件,已预装,不建议删除
1717
nix-env -iA nixpkgs.gcc nixpkgs.fpc # C/C++ 和 Pascal,已预装,不建议删除
1818
nix-env -iA nixpkgs.ghc # Haskell
1919
nix-env -iA nixpkgs.rustc # Rust
20-
nix-env -iA nixpkgs.python2 # Python2
21-
nix-env -iA nixpkgs.pythonPackages.numpy # Python2 Numpy 库
2220
nix-env -iA nixpkgs.python3Minimal
2321
nix-env -iA nixpkgs.python3Packages.numpy
22+
nix-env -iA nixpkgs.pypy3
2423
nix-env -iA nixpkgs.php # PHP
2524
nix-env -iA nixpkgs.go # Golang
2625
nix-env -iA nixpkgs.nodejs # NodeJS

content/docs/Hydro/install/proxy.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Hydro 支持使用 Caddy, HaProxy 等工具进行反向代理,[此处](https:/
1919
Hydro 推荐您使用 [Caddy](https://caddyserver.com/)。以下为样例 Caddyfile。
2020
提示:如果您的服务器位于国内,则需要进行备案后才能使用 80 和 443 端口。
2121

22-
```Caddyfile
22+
```
2323
hydro.ac {
2424
log {
2525
output file /data/access.log {

content/docs/Hydro/install/riscv.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ bash get-sources.sh
3535

3636
给同目录的 `gen-config.sh` 添加 RISC-V 支持:
3737

38-
```patch
38+
```diff
3939
diff --git a/src/third_party/mozjs/gen-config.sh b/src/third_party/mozjs/gen-config.sh
4040
index 9144a461..141e089b 100755
4141
--- a/src/third_party/mozjs/gen-config.sh
@@ -58,7 +58,7 @@ index 9144a461..141e089b 100755
5858
bash gen-config.sh riscv64 linux
5959
```
6060

61-
```patch
61+
```diff
6262
diff --git a/src/third_party/mozjs/platform/riscv64/linux/build/Unified_cpp_js_src0.cpp b/src/third_party/mozjs/platform/riscv64/linux/build/Unified_cpp_js_src0.cpp
6363
new file mode 100644
6464
index 00000000..624b0d97
@@ -77,7 +77,7 @@ index 00000000..624b0d97
7777

7878
修改 MongoDB 的 `platform/pause.h` ,添加 RISC-V 支持:
7979

80-
```patch
80+
```diff
8181
diff --git a/src/mongo/platform/pause.h b/src/mongo/platform/pause.h
8282
index 67fe3d94..b3f50efb 100644
8383
--- a/src/mongo/platform/pause.h
@@ -95,7 +95,7 @@ index 67fe3d94..b3f50efb 100644
9595

9696
将上述 patch 传入 nixpkgs:
9797

98-
```patch
98+
```diff
9999
diff --git a/pkgs/servers/nosql/mongodb/7.0.nix b/pkgs/servers/nosql/mongodb/7.0.nix
100100
index cb4bbf53279f..0526976d4e8b 100644
101101
--- a/pkgs/servers/nosql/mongodb/7.0.nix

mdx-components.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as Twoslash from 'fumadocs-twoslash/ui';
2+
import defaultComponents from 'fumadocs-ui/mdx';
3+
import type { MDXComponents } from 'mdx/types';
4+
5+
export function getMDXComponents(components?: MDXComponents): MDXComponents {
6+
return {
7+
...defaultComponents,
8+
...Twoslash,
9+
...components,
10+
};
11+
}

next.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const withMDX = createMDX();
66
const config = {
77
output: 'export',
88
reactStrictMode: true,
9-
serverExternalPackages: ['twoslash'],
9+
serverExternalPackages: ['twoslash', 'typescript'],
1010
images: {
1111
unoptimized: true,
1212
dangerouslyAllowSVG: true,

package.json

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,33 @@
1111
"postinstall": "fumadocs-mdx"
1212
},
1313
"dependencies": {
14-
"@orama/stopwords": "^3.1.1",
15-
"@orama/tokenizers": "patch:@orama/tokenizers@npm%3A3.1.1#~/.yarn/patches/@orama-tokenizers-npm-3.1.1-d353c0f792.patch",
16-
"embla-carousel-react": "^8.5.2",
17-
"fumadocs-core": "15.0.15",
18-
"fumadocs-mdx": "11.5.6",
19-
"fumadocs-twoslash": "^3.1.0",
20-
"fumadocs-ui": "15.0.15",
21-
"katex": "^0.16.21",
22-
"lucide-react": "^0.477.0",
23-
"next": "15.2.0",
24-
"react": "^19.0.0",
25-
"react-dom": "^19.0.0",
14+
"@orama/stopwords": "^3.1.13",
15+
"@orama/tokenizers": "^3.1.13",
16+
"embla-carousel-react": "^8.6.0",
17+
"fumadocs-core": "15.7.11",
18+
"fumadocs-mdx": "11.9.1",
19+
"fumadocs-twoslash": "^3.1.7",
20+
"fumadocs-ui": "15.7.11",
21+
"katex": "^0.16.22",
22+
"lucide-react": "^0.544.0",
23+
"next": "15.5.3",
24+
"react": "^19.1.1",
25+
"react-dom": "^19.1.1",
2626
"rehype-katex": "^7.0.1",
27-
"remark-math": "^6.0.0"
27+
"remark-math": "^6.0.0",
28+
"twoslash": "^0.3.4"
2829
},
2930
"devDependencies": {
30-
"@tailwindcss/postcss": "^4.0.9",
31+
"@tailwindcss/postcss": "^4.1.13",
3132
"@types/mdx": "^2.0.13",
3233
"@types/node": "22.13.8",
33-
"@types/react": "^19.0.10",
34-
"@types/react-dom": "^19.0.4",
35-
"eslint": "^8",
36-
"eslint-config-next": "15.2.0",
37-
"postcss": "^8.5.3",
38-
"tailwindcss": "^4.0.9",
34+
"@types/react": "^19.1.13",
35+
"@types/react-dom": "^19.1.9",
36+
"eslint": "^8.57.1",
37+
"eslint-config-next": "15.5.3",
38+
"hydrooj": "^5.0.0-beta.9",
39+
"postcss": "^8.5.6",
40+
"tailwindcss": "^4.1.13",
3941
"typescript": "^5.8.2"
4042
},
4143
"packageManager": "[email protected]"

source.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import rehypeKatex from 'rehype-katex';
33
import remarkMath from 'remark-math';
44
import { transformerTwoslash } from 'fumadocs-twoslash';
55
import { rehypeCodeDefaultOptions } from 'fumadocs-core/mdx-plugins';
6+
import { createFileSystemTypesCache } from 'fumadocs-twoslash/cache-fs';
67

78
export const docs = defineDocs({
89
dir: 'content/docs',
@@ -19,7 +20,9 @@ export default defineConfig({
1920
},
2021
transformers: [
2122
...(rehypeCodeDefaultOptions.transformers ?? []),
22-
transformerTwoslash(),
23+
transformerTwoslash({
24+
typesCache: createFileSystemTypesCache(),
25+
}),
2326
],
2427
},
2528
},

0 commit comments

Comments
 (0)