MCPcopy
hub / github.com/ChinaGodMan/UserScripts / generate_html_table

Function generate_html_table

utils/update_scripts_list.py:30–111  ·  view source on GitHub ↗
(scripts)

Source from the content-addressed store, hash-verified

28
29# 生成 HTML 表格
30def generate_html_table(scripts):
31 html_table = ''''''
32 template_path = "utils/templates/ScriptCard.html"
33 with open(template_path, 'r', encoding='utf-8') as file:
34 html_template = file.read()
35 html_template = format_str(html_template)
36 for script in scripts:
37
38 script_id = script.get("greasyfork_id")
39 script_fold = script.get("directory")
40 adult = script.get("adult")
41 js_name = script.get("js_name")
42
43 # 判断是否为成人脚本
44 domain = "sleazyfork.org" if adult else "greasyfork.org"
45
46 # ? 直接从尼玛的脚本中读取脚本名称和介绍,废弃掉从json内读取,让README.md显示完整的信息
47 script_absolute_path = script.get("directory") + "/" + js_name
48
49 # 含有更新日志的脚本,显示更新日志链接
50 change_log = script.get("directory") + "/CHANGELOG.md"
51 changelog_block = ""
52 if os.path.exists(change_log):
53 changelog_block = (
54 f' /\n<a href="https://github.com/{get_repo_name()}/tree/main/{script_fold}/CHANGELOG.md">\n'
55 f' <img hight=16 width=15 src="https://img.icons8.com/parakeet/48/renew-subscription.png">'
56 f'更新日志</a>')
57
58 # 含有引用的脚本,显示链接
59 author = script.get("directory") + "/AUTHORS.md"
60 author_block = ""
61 if os.path.exists(author):
62 author_block = (
63 f' /\n<a href="https://github.com/{get_repo_name()}/tree/main/{script_fold}/AUTHORS.md">\n'
64 f' <img hight=18 width=18 src="https://raw.githubusercontent.com/{get_repo_name()}History/main/images/authors.svg">'
65 f'修改自</a>')
66
67 sreach_result = search_in_file(script_absolute_path, LANG_CODE)
68 script_name = sreach_result.name_matches[0]
69 script_description = sreach_result.description_matches[0]
70
71 # 跳转到对应语言的readme
72 readme_file_name = f'README_{LANG_CODE}.md'
73 if not os.path.exists(f'{script.get("directory")}/{readme_file_name}'):
74 readme_file_name = "README_en.md"
75
76 # 直接跳转到目录
77 if LANG_CODE == "zh-CN":
78 readme_file_name = "#readme"
79
80 # 构建预览截图
81 previews = script.get("preview")
82 img_tag = ''
83 if previews:
84 if isinstance(previews, list):
85 img_tag = "\n ".join(f'<img width=511 src="{item}">' for item in previews)
86 else:
87 img_tag = f'<img width=511 src="{previews}">'

Callers 1

generate_grouped_htmlFunction · 0.85

Calls 4

format_strFunction · 0.90
get_repo_nameFunction · 0.90
search_in_fileFunction · 0.90
getMethod · 0.80

Tested by

no test coverage detected