-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
68 lines (56 loc) · 2.4 KB
/
build.py
File metadata and controls
68 lines (56 loc) · 2.4 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
import shutil
from jinja2 import Environment, FileSystemLoader
def build():
# Directories from blatter.ini
static_dir = 'static'
template_dir = 'templates'
dynamic_dir = 'site'
output_dir = 'out'
# Ensure output directory exists and is empty
if os.path.exists(output_dir):
shutil.rmtree(output_dir)
os.makedirs(output_dir)
# Setup Jinja2 environment
env = Environment(loader=FileSystemLoader(template_dir))
# Render dynamic pages from 'site' directory
for root, dirs, files in os.walk(dynamic_dir):
for file in files:
if file.endswith('.html'):
# Get the relative path for the template
rel_dir = os.path.relpath(root, dynamic_dir)
if rel_dir == '.':
rel_dir = ''
# Jinja2 expects template names with forward slashes
template_path = os.path.join(dynamic_dir, rel_dir, file)
# Create output directory structure
out_page_dir = os.path.join(output_dir, rel_dir)
if not os.path.exists(out_page_dir):
os.makedirs(out_page_dir)
# Render the file
# Note: blatter treats files in 'site' as templates themselves
# but they usually extend a base template.
# We'll load the file content and render it.
with open(os.path.join(root, file), 'r') as f:
template_content = f.read()
template = env.from_string(template_content)
output = template.render()
with open(os.path.join(out_page_dir, file), 'w') as f:
f.write(output)
print(f"Rendered: {os.path.join(rel_dir, file)}")
# Copy static assets
if os.path.exists(static_dir):
for item in os.listdir(static_dir):
s = os.path.join(static_dir, item)
d = os.path.join(output_dir, item)
if os.path.isdir(s):
shutil.copytree(s, d)
else:
shutil.copy(s, d)
print(f"Copied static assets from {static_dir}")
# Create CNAME file for GitHub Pages
with open(os.path.join(output_dir, 'CNAME'), 'w') as f:
f.write('compecta.com')
print("Created CNAME file for compecta.com")
if __name__ == "__main__":
build()