1+ import toml
2+ import mkdocs_gen_files
3+
4+ from urllib .parse import urlparse
5+
6+
7+ def parse_github_url (url ):
8+ parsed_url = urlparse (url )
9+
10+ if parsed_url .netloc != "github.com" :
11+ raise ValueError ("The provided URL is not a valid GitHub URL" )
12+
13+ path_parts = parsed_url .path .strip ("/" ).split ("/" )
14+
15+ if len (path_parts ) < 2 :
16+ raise ValueError ("Invalid URL format. Unable to extract organization and repository names" )
17+
18+ organization = path_parts [0 ]
19+ repository = path_parts [1 ]
20+
21+ return organization , repository
22+
23+ with mkdocs_gen_files .open ("Adapter/Third-Party.md" , "w" ) as f :
24+ def fp (str ):
25+ print (str , file = f )
26+
27+ def el ():
28+ print ("" , file = f )
29+
30+ fp ("---" )
31+ fp ("comments: true" )
32+ fp ("hide:" )
33+ fp (" - navigation" )
34+ fp (" - toc" )
35+ fp ("---" )
36+ el ()
37+
38+ fp ("# 第三方适配器" )
39+ el ()
40+ fp ("本页包含一些HuHoBot的第三方适配器" )
41+ el ()
42+
43+ fp ("## 添加适配器" )
44+ el ()
45+ fp ("您可以在网站上添加自己的插件,只需打开一个[新Pull Request](https://github.com/HuHoBot/HuHoBot.github.io/pulls)即可。" )
46+ el ()
47+
48+ fp ("## 可用适配器列表" )
49+ el ()
50+ fp ("<div class=\" grid cards\" markdown>" )
51+ el ()
52+
53+ config = toml .load ("docs/adapter.toml" )
54+ for name , info in config .items ():
55+ description = info ["description" ]
56+ authors = info ["authors" ]
57+ github = info ["github" ]
58+ user , repo = parse_github_url (github )
59+
60+
61+ fp (f"- **{ name } ** <small>by { ", " .join (authors )} </small>" )
62+ el ()
63+ fp (f" " )
64+ fp (f" " )
65+ fp (f" " )
66+ fp (f" " )
67+ el ()
68+ fp (" ---" )
69+ el ()
70+ fp (f" { description } " )
71+ el ()
72+ fp (f" [**:octicons-arrow-right-24: GitHub**]({ github } )" )
73+ el ()
74+
75+ el ()
76+ fp ("</div>" )
0 commit comments