99repo_full = os .environ .get ("GITHUB_REPOSITORY" , "defaultOwner/defaultRepo" )
1010branch = os .environ .get ("GITHUB_REF_NAME" , "main" )
1111
12- # 文本文件走 blob 链接(在线查看),二进制文件走 cdn 链接(便于直接下载)
12+ # 文本文件走 blob 链接(在线查看),其他文件走 cdn 链接(便于直接下载),大文件反代加速
1313BLOB_URL_PREFIX = f"https://github.com/{ repo_full } /blob/{ branch } /"
1414BIN_URL_PREFIX = f"https://cdn.jsdmirror.com/gh/{ repo_full } /"
15+ LARGE_URL_PREFIX = f"https://raw.github.site/{ repo_full } /refs/heads/{ branch } /"
16+
17+ # 大文件阈值 15MB
18+ LARGE_THRESHOLD = 15 * 1024 * 1024
1519
1620# 顶层排除目录
1721EXCLUDE_TOP_DIRS = {'.git' , 'docs' , '.vscode' , '.circleci' , 'site' , 'image' }
2226# 生成 blob 链接
2327BLOB_EXTS = {'md' , 'txt' , 'c' , 'cpp' , 'py' }
2428
29+
2530def process_directory (base_dir : str , rel_path : str ):
2631 """
2732 将 base_dir(绝对路径) 对应的目录内容,递归生成到 docs/rel_path 目录下的 index.md 中。
@@ -56,11 +61,18 @@ def process_directory(base_dir: str, rel_path: str):
5661 # 若是 README,则已处理过;否则纳入链接
5762 if item not in README_CANDIDATES :
5863 ext = item .split ("." )[- 1 ].lower () if "." in item else ""
59- # 判断用 blob 还是 cdn 加速
64+ file_size = os .path .getsize (full_item_path )
65+
66+ # blob 类文件链接
6067 if ext in BLOB_EXTS :
6168 file_url = BLOB_URL_PREFIX + quote (f"{ rel_path } /{ item } " )
6269 else :
63- file_url = BIN_URL_PREFIX + quote (f"{ rel_path } /{ item } " )
70+ # 大文件链接
71+ if file_size > LARGE_THRESHOLD :
72+ file_url = LARGE_URL_PREFIX + quote (f"{ rel_path } /{ item } " )
73+ else :
74+ file_url = BIN_URL_PREFIX + quote (f"{ rel_path } /{ item } " )
75+
6476 file_links .append ((item , file_url ))
6577 else :
6678 # 是子目录
@@ -80,9 +92,8 @@ def process_directory(base_dir: str, rel_path: str):
8092 # 3) 列出当前目录内的文件链接
8193 for fname , url in file_links :
8294 wf .write (f"- [{ fname } ]({ url } )\n " )
83- wf .write ("\n " )
8495
85- # 4) 递归处理子目录
96+ # 递归处理子目录
8697 for subdir in subdirs :
8798 sub_rel_path = os .path .join (rel_path , subdir )
8899 full_subdir_path = os .path .join (base_dir , subdir )
0 commit comments