-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlink_css_js.py
More file actions
49 lines (37 loc) · 1.21 KB
/
link_css_js.py
File metadata and controls
49 lines (37 loc) · 1.21 KB
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
import os
import re
rd = "/sdcard/.workspace/web/knowlet/pyq"
total = 0
changed = 0
unchanged = 0
empty = 0
status = 'unknown'
for root, _, files in os.walk(rd):
for file in files:
#For Units
# if re.match(r"unit_(\d+)\.html", file):
fp = os.path.join(root, file)
total += 1
with open(fp, 'r', encoding='utf-8') as f:
c = f.read()
nc = c
#link Styles
if not '<link rel="stylesheet"' in c:
nc = c.replace('<style>','''<link rel="stylesheet" href="../../../../assets/styles/units.css">
<style>''')
#link scripts
if not '<div id="app"></div>' in c:
nc = nc.replace('</body>',''' <div id="app"></div>
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>
<script src="../../../../assets/scripts/units.js"></script>
</body>''')
if c != nc:
with open(fp, 'w', encoding='utf-8') as f:
f.write(nc)
changed += 1
status = '✔️'
else:
unchanged += 1
status = '🟰'
print(f"{status} {fp.removeprefix(rd)}")
print(f"\nTotal: {total}\nEmpty: {empty}\nChanged: {changed}\nUnchanged: {unchanged}")