-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a6971c
commit 08cceab
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import os | ||
|
||
def generate_index(): | ||
"""遍历目录并生成新的index.md文件""" | ||
|
||
sections = { | ||
"example1": "示例类别1:", | ||
"example2": "示例类别2:", | ||
"""这里多加几行就是多几个类别,前面是文件夹名称,后面是显示名称""" | ||
} | ||
|
||
base_path = "/work/story/" # 设置文件夹路径 | ||
|
||
with open("new.md", "w", encoding="utf-8") as new_file: | ||
for section, title in sections.items(): | ||
folder_path = os.path.join(base_path, section) # 构造完整路径 | ||
files = [f[:-3] for f in os.listdir(folder_path) if f.endswith(".md")] | ||
links = [f"[{name}](/" + section + "/" + name + ")" for name in files] | ||
line = title + ", ".join(links) + "\n\n" | ||
new_file.write(line) | ||
|
||
if __name__ == "__main__": | ||
generate_index() |