forked from apjanco/borsht
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.py
45 lines (37 loc) · 1.44 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
import time
from fastapi import Request
from main import index, topics
import shutil
from pathlib import Path
def build_home():
page = index(Request)
(site_path / 'index.html').write_bytes(page.body)
def topic_pages():
if not (site_path / 'topic' ).exists():
(site_path / 'topic' ).mkdir(parents=True, exist_ok=True)
topics_path = Path.cwd() / 'data' / 'topics'
topic_files = [a.stem for a in topics_path.iterdir()]
for topic in topic_files:
page = topics(Request, topic)
(site_path / 'topic' / f'{topic}.html').write_bytes(page.body)
if __name__ == '__main__':
start_time = time.time()
# Create site directory
site_path = Path.cwd() / 'site'
if not site_path.exists():
site_path.mkdir(parents=True, exist_ok=True)
# Copy assets to site directory
if not (site_path / 'assets').exists():
shutil.copytree((Path.cwd() / 'assets'), (site_path / 'assets'))
else:
shutil.rmtree((site_path / 'assets'))
shutil.copytree((Path.cwd() / 'assets'), (site_path / 'assets'))
# Copy Netlify admin to site directory
if not (site_path / 'admin').exists():
shutil.copytree((Path.cwd() / 'admin'), (site_path / 'admin'))
else:
shutil.rmtree((site_path / 'admin'))
shutil.copytree((Path.cwd() / 'admin'), (site_path / 'admin'))
build_home()
topic_pages()
print(f"--- {time.time() - start_time} seconds ---")