-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforked.py
158 lines (121 loc) · 3.88 KB
/
forked.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
# -----------------------
# release.py use for generate a empty karaty project
# execute this script before push new change to repository
# currently using for github-action
# -----------------------
import shutil
from pathlib import Path
import tomllib
DIR = "forked"
def main():
dir_path = Path(".") / DIR
if dir_path.exists():
shutil.rmtree(dir_path)
shutil.copytree("./karaty", dir_path)
# re-genenate Cargo.toml file
cargo_toml = dir_path / "Cargo.toml"
if cargo_toml.exists():
current_content = cargo_toml.read_text()
new_content = clean_template_deps(current_content)
cargo_toml.write_text(new_content)
# clean all data
data_dir = dir_path / "data"
shutil.rmtree(data_dir)
# re-create data dir
data_dir.mkdir()
# write default page
home_md = data_dir / "home.md"
home_md.write_text(home_md_content())
# rewrite config
config_dir = dir_path / "config"
template_toml = config_dir / "template.toml"
template_toml.write_text(template_toml_content())
routing_toml = config_dir / "routing.toml"
routing_toml.write_text(routing_toml_content())
# rewrite karaty.toml
karaty_toml = dir_path / "karaty.toml"
karaty_toml.write_text(karaty_toml_content())
# write README.md
readme_md = dir_path / "README.md"
readme_md.write_text(readme_md_content())
def clean_template_deps(config: str) -> str:
new = ""
for line in config.splitlines():
data = tomllib.loads(line)
ls = list(data.items())
if len(ls) > 0:
k = ls[0][0]
v = ls[0][1]
if isinstance(v, dict):
if 'template' in v and v.get('template') == True:
if k != "karaty-template":
continue
# print(k)
if k == "name":
line = line.replace("karaty", "karaty-website")
new += line + "\n"
return new
def home_md_content() -> str:
return '''<div align="center">
<img src="/assets/karaty.png" width="150">
</div>
***"A static website & blog generator made by Dioxus"***
Use single config file `karaty.toml` to configure your website
Use different file-type for different render template
Dynamic routing segments & queries support
Deploy website without CLI, render pages from markdown
Independent data-source, split content and code in different git repository
Single page application, powered by single `.wasm` file
Support custom **Dioxus** component & template development'''
def template_toml_content() -> str:
return '''[default.file-type]
md = "center"
json = "card::projects"'''
def routing_toml_content() -> str:
return '''[[routing]]
path = "/"
file = "pages/home.md"'''
def karaty_toml_content() -> str:
return '''[site]
name = "Karaty Offical"
title-suffix = " | Karaty Site"
dark-mode = true
[repository]
service = "GitHub"
name = "<github_user>/<github_repo>"
[data-source]
# get more information from document: https://karaty.mrxzx.info/docs/data-source
mode = "<data-source-mode>"
data = "<data-source-config>"
[data-source.local]
# get more information from document: https://karaty.mrxzx.info/docs/data-source
mode = "custom-url"
data = { url = "/data", index-file = "_index.json" }
[navigation]
content = [
{ text = "Home", page = "/" },
{ text = "Docs", link = "https://karaty.mrxzx.info/docs/" },
{ feature = "mode-switch" },
]
[footer]
# enable = false
content = [
[
{ icon = "brand.github", link = "https://github.com/mrxiaozhuox/karaty" },
{ icon = "solid.table", link = "https://karaty.mrxzx.info/blog/roadmap" },
],
[{ text = "Powered by Karaty" }],
]
[build.static-generator]
source = "data"
target = "data"
'''
def readme_md_content() -> str:
return '''## New Karaty project
> you can use dioxus cli to start a local server
``shell
dx serve
``
'''
if __name__ == "__main__":
main()