MCPcopy Index your code
hub / github.com/ChinaGodMan/UserScripts / main

Function main

utils/navigation.py:41–76  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

39
40
41def main():
42 json_path = 'docs/ScriptsPath.json'
43 data = read_json(json_path)
44 scripts = data.get('scripts', [])
45 # 定义开始和结束标签
46 start_tag = "<!--NAVIGATION-->"
47 end_tag = "<!--NAVIGATION-END-->"
48 for script in scripts:
49 script_directory = script.get('directory', '')
50 cnfile_path = os.path.join(script_directory, "README.md")
51
52 # Linux和Windows统一排序方式,防止ci在github运行时排序不一致
53 # ! fix: 排序应从滤过后中获取,不是从目录中获取
54 md_files = sorted(get_md_files(script_directory))
55
56 # 生成html和获取文件中的html
57 descriptions = build_html(md_files, script_directory)
58 olddescriptions = get_file_description(cnfile_path, start_tag, end_tag)
59 olddescriptions = olddescriptions if olddescriptions is not None else "1"
60
61 # 从md文件中获取所有readme文件名
62 md_old = re.findall(r'README[^"]*\.md', olddescriptions) # 从readme文件中获取
63 md_new = get_md_files(script_directory) # 获取当前脚本目录下的所有过滤后的md文件
64 all_in_old = all(md in set(md_old) for md in md_new) # 如果当前过滤后的readme文件名都md_old 不进行替换
65 if all_in_old: # 哪怕导航栏模版发生变动,只要导航栏指向github的链接没变动就不进行替换
66 print("链接在内容中存在")
67 # continue
68
69 # 相等跳过
70 if olddescriptions + "\n" == descriptions: # 换行符添加上,就这样了能用就行
71 continue
72 else:
73 print(f"----\033[94m[{script.get('name', '')}]\033[0m\033[92m 内容变化,执行替换\033[0m")
74 for md_file in md_new:
75 file_path = os.path.join(script_directory, md_file)
76 process_file(file_path, descriptions, start_tag, end_tag, "head")
77
78
79if __name__ == "__main__":

Callers 1

navigation.pyFile · 0.70

Calls 6

read_jsonFunction · 0.90
get_md_filesFunction · 0.90
get_file_descriptionFunction · 0.90
process_fileFunction · 0.90
build_htmlFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected