feat(docs): 新增脚本以自动生成 CommunityShare 索引页#110
Closed
LynPtl wants to merge 1 commit intoInvolutionHell:mainfrom
Closed
feat(docs): 新增脚本以自动生成 CommunityShare 索引页#110LynPtl wants to merge 1 commit intoInvolutionHell:mainfrom
LynPtl wants to merge 1 commit intoInvolutionHell:mainfrom
Conversation
|
@LynPtl is attempting to deploy a commit to the Yoyo's projects Team on Vercel. A member of the Team first needs to authorize it. |
Member
|
@TSK-Glofy TSK看看 |
TSK-Glofy
suggested changes
Sep 27, 2025
Contributor
TSK-Glofy
left a comment
There was a problem hiding this comment.
本地测试无误,但需要添加glob和gray-matter依赖
同时workflow需要在.github/workflows/deploy.yml中添加run: node scripts/generate-community-index.js
Member
|
fumadocs自带的api, source.getPage是不是就可以满足需求 |
Member
|
@LynPtl 我顺手修了吧, 确实老问题了 |
longsizhuo
added a commit
that referenced
this pull request
Apr 16, 2026
现状:/docs/CommunityShare/index.mdx 里的分类列表长期人工维护,已经过期: - 缺列了 Amazing-AI-Tools / Language / Leetcode / Life / Personal-Study-Notes 五个分类 - 还留着"身体健康"这种没对应目录、只有标题没有文章的占位分类 - 新增文章后还得记得回来改 index,实际做不到 改法:新增 server component `CommunityShareIndex`,直接读 fumadocs `source.getPages()` 按第一级子目录分组渲染,分类标题优先读子目录 index.mdx 的 frontmatter.title, 没 index 时降级用目录名。翻译版(lang === "en" / 文件名 .en)统一不进列表。 条目数超过 12 的分类折叠成"查看全部 N 篇 →"单行链接,避免 Leetcode 顶爆页面。 替代 #110:#110 是脚本生成静态 MDX 的路线,需要引入 glob / gray-matter 两个新依赖 + 一个 CI 步骤 + 一套目录名硬编码映射表。用 fumadocs source 之后这些 全部不需要——fumadocs 已经在跑目录扫描和 slug 规范化(包括 lib/source.ts 里 Leetcode 的拼音 slug transform,硬拼 URL 会漏掉),直接复用更干净。 感谢 @LynPtl 最早指出了手维护索引会过期的问题(#110 的痛点诊断)。
4 tasks
Member
|
Hi @LynPtl 🙏 感谢最早指出 CommunityShare 索引手维护会过期这个核心问题——验证了你的痛点诊断是对的(main 上 经过讨论,我们决定换一条实现路线:不走脚本+静态 MDX,改成直接从 fumadocs
因此要 close 这个 PR 了。你最早的问题诊断我已经写进 #288 的 commit 描述里,方案也受你启发。下次有想改的地方欢迎继续提 PR! |
Member
|
替代方案见 #288。原 PR 的痛点诊断有效,实现路线改为 fumadocs server component。 |
longsizhuo
added a commit
that referenced
this pull request
Apr 16, 2026
现状:/docs/CommunityShare/index.mdx 里的分类列表长期人工维护,已经过期: - 缺列了 Amazing-AI-Tools / Language / Leetcode / Life / Personal-Study-Notes 五个分类 - 还留着"身体健康"这种没对应目录、只有标题没有文章的占位分类 - 新增文章后还得记得回来改 index,实际做不到 改法:新增 server component `CommunityShareIndex`,直接读 fumadocs `source.getPages()` 按第一级子目录分组渲染,分类标题优先读子目录 index.mdx 的 frontmatter.title, 没 index 时降级用目录名。翻译版(lang === "en" / 文件名 .en)统一不进列表。 条目数超过 12 的分类折叠成"查看全部 N 篇 →"单行链接,避免 Leetcode 顶爆页面。 替代 #110:#110 是脚本生成静态 MDX 的路线,需要引入 glob / gray-matter 两个新依赖 + 一个 CI 步骤 + 一套目录名硬编码映射表。用 fumadocs source 之后这些 全部不需要——fumadocs 已经在跑目录扫描和 slug 规范化(包括 lib/source.ts 里 Leetcode 的拼音 slug transform,硬拼 URL 会漏掉),直接复用更干净。 感谢 @LynPtl 最早指出了手维护索引会过期的问题(#110 的痛点诊断)。 Co-authored-by: LynPtl <194795025+LynPtl@users.noreply.github.com>
longsizhuo
added a commit
that referenced
this pull request
Apr 16, 2026
合并 #288 + #290 + app/docs/CommunityShare/Leetcode/index.mdx 里原先三份 各自实现的"列目录子节点"逻辑,改成一个 server component。 ## 为什么要合并 原本三处各自实现: - /docs 根路由(PR #290 draft)—— 读 pageTree.children - CommunityShare/index.mdx(PR #288 draft)—— 读 getPages() 过滤 path - CommunityShare/Leetcode/index.mdx —— 内联 MDX 里 source.getPages().filter().map() drift 问题:排序、英文过滤、fallback URL 三份逻辑各走各的;更严重的是 PR #288 里对"没 index.mdx 的子目录"硬拼 /docs/CommunityShare/<dir> 会 404 (Copilot CR 指出),和 PR #290 修 /docs 404 是同一个根因:Next [...slug] 不匹配空 slug,folder 没 index 就意味着 /docs/X 没 route。 ## <SectionIndex root?> - 走 source.pageTree(不是 getPages),fumadocs 已经把 folder+index 关系建好了,不用自己从扁平 page 列表反推 - root 接 "CommunityShare" / "CommunityShare/Leetcode" 这种相对路径, 不传就是从 pageTree 根开始(给 /docs landing 用) - URL 永不硬拼:folder 有 index 走 index.url;没 index 递归找子树第一个 page 的 url 作为 fallback(直接修掉 CR 那个 404 bug) - 英文翻译版(URL 末段 .en)过滤不进列表;语言切换仍由 [...slug] 的 cookie fallback 负责 - 统一 fumadocs <Cards>/<Card> 视觉 ## 本地验证 - /docs → 5 张卡片,全部 200 - /docs/CommunityShare → 8 张卡片,全部 200(包括原先会 404 的 Language/ Life/Personal-Study-Notes/RAG 四个没 index 的分类,现在点进去是子目录里 第一篇 page,不再死链) - /docs/CommunityShare/Leetcode → 49 张卡片,0 个 .en 泄漏 ## 取代关系 - 关闭 PR #288(CommunityShareIndex 专用实现,有 404 bug) - 关闭 PR #290(/docs landing 单独实现) - 本 PR 一并覆盖,继续承担解决 #110 的责任 Co-authored-by: LynPtl <194795025+LynPtl@users.noreply.github.com>
5 tasks
longsizhuo
added a commit
that referenced
this pull request
Apr 16, 2026
…(取代 #288 #290) (#292) * refactor(docs): 统一 /docs、CommunityShare、Leetcode 三处索引为 <SectionIndex> 合并 #288 + #290 + app/docs/CommunityShare/Leetcode/index.mdx 里原先三份 各自实现的"列目录子节点"逻辑,改成一个 server component。 ## 为什么要合并 原本三处各自实现: - /docs 根路由(PR #290 draft)—— 读 pageTree.children - CommunityShare/index.mdx(PR #288 draft)—— 读 getPages() 过滤 path - CommunityShare/Leetcode/index.mdx —— 内联 MDX 里 source.getPages().filter().map() drift 问题:排序、英文过滤、fallback URL 三份逻辑各走各的;更严重的是 PR #288 里对"没 index.mdx 的子目录"硬拼 /docs/CommunityShare/<dir> 会 404 (Copilot CR 指出),和 PR #290 修 /docs 404 是同一个根因:Next [...slug] 不匹配空 slug,folder 没 index 就意味着 /docs/X 没 route。 ## <SectionIndex root?> - 走 source.pageTree(不是 getPages),fumadocs 已经把 folder+index 关系建好了,不用自己从扁平 page 列表反推 - root 接 "CommunityShare" / "CommunityShare/Leetcode" 这种相对路径, 不传就是从 pageTree 根开始(给 /docs landing 用) - URL 永不硬拼:folder 有 index 走 index.url;没 index 递归找子树第一个 page 的 url 作为 fallback(直接修掉 CR 那个 404 bug) - 英文翻译版(URL 末段 .en)过滤不进列表;语言切换仍由 [...slug] 的 cookie fallback 负责 - 统一 fumadocs <Cards>/<Card> 视觉 ## 本地验证 - /docs → 5 张卡片,全部 200 - /docs/CommunityShare → 8 张卡片,全部 200(包括原先会 404 的 Language/ Life/Personal-Study-Notes/RAG 四个没 index 的分类,现在点进去是子目录里 第一篇 page,不再死链) - /docs/CommunityShare/Leetcode → 49 张卡片,0 个 .en 泄漏 ## 取代关系 - 关闭 PR #288(CommunityShareIndex 专用实现,有 404 bug) - 关闭 PR #290(/docs landing 单独实现) - 本 PR 一并覆盖,继续承担解决 #110 的责任 Co-authored-by: LynPtl <194795025+LynPtl@users.noreply.github.com> * docs(SectionIndex): 加大量中文注释说明 pageTree 心智模型 + 每步做什么 * fix(SectionIndex): 按 CR 补齐 locale 变体过滤 + 去掉注释里的 markdown Copilot 在 #292 提了 3 条要修的: 1) isEnglishVariant 只过滤 .en,没管 .zh —— 站点实际有 .zh.md(原文是 en 时的中文翻译), 重复链接会在索引里暴露。改成 isHideableLocaleVariant(url, canonicals):只有对应 canonical 存在时才隐藏,孤儿(只有 .en 或 .zh 单一形态的文档,共 35 + 7 篇)保留。 2) folder.index 如果本身是翻译版(理论上会有 index.en.mdx / index.zh.mdx),不能直接 当卡片 href,会暴露非 canonical URL。nodeToCard 里给 idxUrl 加同样的过滤,不合规时 退回 findFirstPageUrl。 3) folderSegmentName 注释写的"倒数第二段"但代码取的是最后一段,改掉注释。 另外按用户反馈清掉注释里的 markdown(**bold**、反引号等),代码注释又不会被渲染。 --------- Co-authored-by: LynPtl <194795025+LynPtl@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose:
为了解决 CommunityShare 索引页 (index.mdx) 需要手动维护的问题,本次提交引入了一个自动化的 Node.js 脚本。该脚本能够根据实际文件目录结构,动态生成一个结构清晰、链接准确、始终保持最新的索引页。
Key Changes:
新增索引生成脚本:
在 scripts/ 目录下添加了 generate-community-index.js 文件。
更新索引页:
使用新脚本生成了最新的 app/docs/CommunityShare/index.mdx 文件,以展示脚本的运行效果。
脚本核心功能 (Script Features)
自动扫描: 脚本会自动扫描 CommunityShare 下的所有分类目录(如 Geek, computer-science 等)。
支持多级嵌套: 能够正确处理任意深度的目录结构(例如 .../data-structures/array/),并生成对应的层级缩进。
智能排序: 在每个目录层级中,index.mdx (作为该层级的概述页) 会被优先排列,其余文件则按字母顺序排序。
读取元数据: 脚本会自动读取每个 .mdx 文件头部的 Frontmatter,使用其中定义的 title作为链接的显示文本。
How to Use:
在项目根目录下运行以下命令即可更新索引:
node scripts/generate-community-index.js
Next Steps:
依赖库glob和gray-matter由于我配置原因未写入package.json,在此之后才能做GitHub Actions。
没玩明白GitHub Actions workflows工作流,需要集成才能实现自动化。