feat(docs): 新增脚本以自动生成 CommunityShare 索引页 #110
Open
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工作流,需要集成才能实现自动化。