generated from thevahidal/jake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
118 lines (109 loc) · 3.74 KB
/
script.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
import tomllib
from tinyhtml import html, h, frag, raw
with open("data.toml", "rb") as f:
data = tomllib.load(f)
sections = frag(
h("div", klass="section")(
h("hgroup")(
h("h3")(section.get("title")),
h("p")(section.get("description")),
),
h(
"div",
klass="items",
style=f"flex-direction: {section.get('direction', 'column')}",
)(
h(
"div",
klass="item",
style=f"width: {'100%' if section.get('direction', 'column') == 'column' else 'unset'}",
)(
h(
"a",
role="button",
klass=f"{'outline' if section.get('item_style', 'outline') == 'outline' else ''}",
href=item.get("url"),
target="_blank",
)(
h("hgroup")(
h("h4")(item.get("title")), h("h5")(item.get("description"))
),
),
)
for item in section["items"]
),
)
for section in data["sections"]
)
head = frag(
h("head")(
h("title")(data.get("name")),
h("meta", name="description", content=data.get("description")),
h("meta", name="keywords", content=data.get("keywords")),
h("meta", name="viewport", content="width=device-width, initial-scale=1"),
h("meta", charset="utf-8"),
h("link", rel="stylesheet", href="css/pico.min.css"),
h("link", rel="stylesheet", href="css/style.css"),
h("style", rel="stylesheet")(
f"""
[data-theme="dark"], [data-theme="light"] {{
--primary: {data.get("primary_color", "#546e7a")} !important;
}}
* {{
text-align: {data.get("text_align", "center")};
}}
"""
),
raw(
f"""
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id={data.get("gtag_id")}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){{dataLayer.push(arguments);}}
gtag('js', new Date());
gtag('config', '{data.get("gtag_id")}');
</script>
"""
)
if data.get("gtag_id")
else None,
),
)
header = frag(
h("header", klass="container")(
h("hgroup")(
h(
"img",
klass="avatar",
src=f"img/{data.get('image')}",
alt="avatar",
),
h("h1")(data.get("name")),
h("p")(data.get("description")) if data.get("description") else None,
),
)
)
footer = frag(
h("footer", klass="container")(
h("small")("Generated with "),
h(
"a",
klass="",
href="https://github.com/thevahidal/jake/",
target="_blank",
)("Jake"),
),
)
output = html(lang="en", data_theme=data.get("theme", "dark"))(
head,
h("body")(
header,
h("main", klass="container")(
sections,
),
footer,
),
).render()
with open("dist/index.html", "w") as f:
f.write(output)