forked from botcity-dev/bot-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
163 lines (128 loc) · 5.57 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
from genericpath import exists
import os
import sys
import json
import pathlib
import shutil
def generate_for_entry(deploy_path, uid, entry):
import string
html = []
# INTRO
intro = string.Template("""
<div id="botName">$name</div>
<div id="botAuthor">by <a href="$author_site">$author_name</a> on $upload_date</div>
<div id="botDescription">$description</div>
""").safe_substitute(**entry)
html.append(intro)
# TAGS
html.append(""" <div class="card_bot_tags_bot"><b>tags: </b>""")
tag = string.Template(""" <div class="card_bot_tag">$programming_language</div>""").safe_substitute(**entry)
html.append(tag)
for tag in entry.get('tags'):
tag = string.Template(""" <div class="card_bot_tag">$tag</div>""").safe_substitute(tag=tag)
html.append(tag)
html.append(""" </div>""")
# GH repo card
if entry.get("repository_url", ""):
org = entry.get("repository_url", "").split("/")[-2]
entry["org"] = org
gh = string.Template(
"""
<div class="div_git_repo">
<b>Repository:</b><br/>
<a href="$repository_url">
<img align="center" src="https://github-readme-stats.vercel.app/api/pin/?username=$org&repo=$repository_name"/>
</a><br/>
<font style='font-size:12px'>* Source code may be subject to copyright, check with author for redistribution.</font>
</div>
"""
).safe_substitute(**entry)
html.append(gh)
# YouTube Video
if entry.get("youtube_video"):
entry["hp"] = entry.get("youtube_height")/entry.get("youtube_width")*100
youtube = string.Template(
"""
<div class="video-container" style="padding-bottom:$hp%">
<iframe class="youtube_embeded" width="" height="" src="$youtube_video" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
"""
).safe_substitute(**entry)
html.append(youtube)
entry["url"] = f"https://repository.botcity.dev/bot-{uid}.html"
upload_date_iso = "/".join(entry.get("upload_date").split("/")[::-1])
entry["upload_date_iso"] = upload_date_iso
page = """
<html xmlns:og="http://opengraphprotocol.org/schema/" >
<head>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-N4HVP5D');</script>
<!-- End Google Tag Manager -->
<meta charset="UTF-8">
<link rel="stylesheet" href="./css/main.css">
<link rel="stylesheet" href="./css/bot.css">
<title>BotRepository - $name</title>
<!-- Essential META Tags -->
<meta property="og:type" content="article" />
<meta property="og:title" content="BotRepository - $name" />
<meta property="og:site_name" content="BotRepository" />
<meta property="og:url" content="$url" />
<meta property="og:image" content="$thumbnail_url" />
<meta property="og:description" content="$description" />
<meta property="article:author" content="$author_name" />
<meta property="article:published_time" content="$upload_date_iso" />
<meta property="og:locale" content="en_US"/>
<!-- Non-Essential, But Required for Analytics -->
<meta name="twitter:site" content="@BotcityDev" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:image:alt" content="$name" />
</head>
<body>
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-N4HVP5D"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
<!-- HEADER -->
<div data-include="header"></div>
<!-- Main Content -->
<div id="botPanel">$content</div>
<!-- FOOTER -->
<div data-include="footer"></div>
<script src="./js/jquery-3.6.0.min.js"></script>
<script src="./js/ui.js"></script>
<script>
$(function () {
UI.load();
});
</script>
</body>
</html>
"""
page_code = string.Template(page).safe_substitute(content="\n".join(html), **entry)
output_file = os.path.join(deploy_path, f"bot-{uid}.html")
with open(output_file, "w") as f:
f.write(page_code)
def build():
OUTPUT_FOLDER = "site-deploy"
base_path = os.path.dirname(os.path.realpath(__file__))
base_site = os.path.join(base_path, "site")
json_file = os.path.join(base_site, "data", "records.json")
deploy_path = os.path.join(base_path, OUTPUT_FOLDER)
if not os.path.exists(json_file) or not os.path.isfile(json_file):
sys.exit("Could not find site/data/records.json file.")
print("Base Path: ", base_path)
print("Base Site: ", base_site)
print("JSON File: ", json_file)
print("Deploy Path: ", deploy_path)
shutil.rmtree(deploy_path, ignore_errors=True)
shutil.copytree(base_site, deploy_path)
with open(json_file, "r") as f:
database = json.loads(f.read())
for uid, entry in enumerate(database):
generate_for_entry(deploy_path, uid, entry)
print(f"All set. Your new site is available at: {deploy_path}")
build()