Skip to content

Commit 0b1f07c

Browse files
authored
Merge pull request #152 from ClaireggZ/feat/use-md-by-default
fix(contrib): change default submission file extension from .mdx to .md
2 parents e300642 + 4ce70de commit 0b1f07c

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

CONTRIBUTING.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pnpm dev
127127

128128
打开浏览器访问 [http://localhost:3000](http://localhost:3000)
129129

130-
修改 `docs/` 下的 `.md` `.mdx` 文件,会自动热更新。
130+
修改 `docs/` 下的 `.md` 文件,会自动热更新。
131131

132132
---
133133

@@ -155,7 +155,7 @@ pnpm postinstall # 同步必要的 Husky/Fumadocs 配置
155155
docxA 引用了 imgA 图片, 那么他们的文档结构应该是 `docxA.assets/imgA`:
156156

157157
```md
158-
docsA.mdx
158+
docsA.md
159159
docsA.assets/
160160
imgA
161161
```
@@ -199,35 +199,35 @@ tags:
199199
```
200200
📂 docs/
201201
├── 📂 computer-science/ # 计算机科学
202-
│ ├── 📄 index.mdx # 概述
202+
│ ├── 📄 index.md # 概述
203203
│ └── 📂 data-structures/ # 数据结构
204-
│ ├── 📄 index.mdx # 概述
204+
│ ├── 📄 index.md # 概述
205205
│ ├── 📂 array/ # 数组
206-
│ │ ├── 📄 index.mdx # 概述
207-
│ │ ├── 📄 01-static-array.mdx # 静态数组
208-
│ │ └── 📄 02-dynamic-array.mdx # 动态数组
206+
│ │ ├── 📄 index.md # 概述
207+
│ │ ├── 📄 01-static-array.md # 静态数组
208+
│ │ └── 📄 02-dynamic-array.md # 动态数组
209209
│ └── 📂 linked-list/ # 链表
210-
│ ├── 📄 index.mdx # 概述
211-
│ └── 📄 01-singly-linked-list.mdx # 单向链表
210+
│ ├── 📄 index.md # 概述
211+
│ └── 📄 01-singly-linked-list.md # 单向链表
212212
```
213213

214214
### URL 生成
215215

216216
文件结构会自动生成简洁的 URL:
217217

218-
- `docs/computer-science/index.mdx``/computer-science`
219-
- `docs/computer-science/data-structures/array/01-static-array.mdx``/computer-science/data-structures/array/static-array`
218+
- `docs/computer-science/index.md``/computer-science`
219+
- `docs/computer-science/data-structures/array/01-static-array.md``/computer-science/data-structures/array/static-array`
220220

221221
### 命名约定
222222

223223
**文件夹:**
224224

225225
- 使用 `kebab-case` 命名: `computer-science`, `data-structures`
226-
- 每个主题文件夹应该有一个 `index.mdx` 文件作为概述
226+
- 每个主题文件夹应该有一个 `index.md` 文件作为概述
227227

228228
**文件:**
229229

230-
- 使用 `kebab-case` 命名: `static-array.mdx`
230+
- 使用 `kebab-case` 命名: `static-array.md`
231231
- 使用数字前缀排序: `01-`, `02-`
232232
- 前缀会自动从最终 URL 中移除
233233

app/components/Contribute.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const FILENAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]+$/;
2727

2828
// 统一调用工具函数生成 GitHub 新建链接,路径规则与 Edit 按钮一致
2929
function buildGithubNewUrl(dirPath: string, filename: string, title: string) {
30-
const file = filename.endsWith(".mdx") ? filename : `${filename}.mdx`;
30+
const file = filename.endsWith(".md") ? filename : `${filename}.md`;
3131
const frontMatter = `---
3232
title: '${title || "New Article"}'
3333
description: ""

scripts/check-images.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* MDX 图片路径校验脚本
44
*
55
* 功能
6-
* - 扫描 `app/docs/??/?.mdx`(含 .md
6+
* - 扫描 `app/docs/??/?.md`(含 .mdx
77
* - 识别 Markdown `![]()` 与内联 `<img src="…" />` 的图片引用
88
* - 强制使用“就近图片”:推荐相对路径(如 `./images/…`)
99
* - 仅对站点级共享资源允许绝对路径:`/images/site/*`、`/images/components/*`
@@ -38,7 +38,7 @@ const IMAGE_FILE_EXTS = new Set([
3838
".webp",
3939
".svg",
4040
]);
41-
const exts = new Set([".mdx", ".md"]);
41+
const exts = new Set([".md", ".mdx"]);
4242

4343
/** Recursively list files */
4444
function* walk(dir) {
@@ -60,7 +60,7 @@ function toRoutePath(file) {
6060
const rel = path.relative(DOCS_DIR, file).split(path.sep).join("/");
6161
const base = path.basename(rel);
6262
const dir = path.dirname(rel);
63-
if (base.toLowerCase() === "index.mdx") return dir === "." ? "" : dir;
63+
if (base.toLowerCase() === "index.md") return dir === "." ? "" : dir;
6464
const name = base.replace(/\.[^.]+$/, "");
6565
return dir === "." ? name : `${dir}/${name}`;
6666
}
@@ -207,7 +207,7 @@ function main() {
207207
console.log(`\nFound ${bad}/${total} files with image issues.`);
208208
process.exit(1);
209209
} else {
210-
console.log(`Checked ${total} MDX files: no issues.`);
210+
console.log(`Checked ${total} MD files: no issues.`);
211211
}
212212
}
213213

scripts/escape-angles.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import fg from "fast-glob";
1212
* 2) 仅在普通文本行内转义形如 <数字开头...> 或 <单词里含逗号/空格/数学符号...> 的片段
1313
* 3) 不动像 <Component> / <div> 这类“正常标签/组件名”的片段
1414
*/
15-
const files = await fg(["app/docs/**/*.mdx"], { dot: false });
15+
const files = await fg(["app/docs/**/*.md"], { dot: false });
1616

1717
for (const file of files) {
1818
let src = await fs.readFile(file, "utf8");

scripts/move-doc-images.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env node
22
/**
3-
* MDX 图片就近迁移脚本(中文注释)
3+
* MD 图片就近迁移脚本(中文注释)
44
*
55
* 目标
6-
* - 扫描 `app/docs/??/?.mdx`(含 .md)里的图片引用
7-
* - 对于以 `/images/...` 绝对路径引用且仅被“单一文档”使用的图片:移动到对应 MDX 同目录下的 `images/` 子目录
6+
* - 扫描 `app/docs/??/?.md`(含 .mdx)里的图片引用
7+
* - 对于以 `/images/...` 绝对路径引用且仅被“单一文档”使用的图片:移动到对应 MD 同目录下的 `images/` 子目录
88
* - 同时将文中的绝对路径替换为相对路径 `./images/<文件名>`(站点级资源除外)
99
*
1010
* 为什么需要
@@ -34,7 +34,7 @@ const PUBLIC_DIR = path.join(ROOT, "public");
3434
const EXCLUDE_PREFIXES = ["/images/site/", "/images/components/"];
3535

3636
// 需要处理的文档扩展名
37-
const exts = new Set([".mdx", ".md"]);
37+
const exts = new Set([".md", ".mdx"]);
3838

3939
/** 递归遍历目录,产出文件路径 */
4040
function* walk(dir) {
@@ -222,7 +222,7 @@ function moveForFile(file, refs) {
222222
return { moved, updated: content !== raw };
223223
}
224224

225-
/** 主流程:遍历所有 MDX,累计迁移数量并输出统计 */
225+
/** 主流程:遍历所有 MD,累计迁移数量并输出统计 */
226226
function main() {
227227
let totalFiles = 0;
228228
let totalMoved = 0;

0 commit comments

Comments
 (0)