-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
67 lines (57 loc) · 2.02 KB
/
build.py
File metadata and controls
67 lines (57 loc) · 2.02 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
import os
import shutil
from flask import Flask, render_template
import docutils.core
from datetime import datetime
app = Flask(__name__)
# Configure Flask for URL generation
app.config.update(
SERVER_NAME='localhost',
APPLICATION_ROOT='/',
PREFERRED_URL_SCHEME='http'
)
def rst_to_html(rst_content):
"""Convert RST content to HTML."""
overrides = {
'input_encoding': 'unicode',
'output_encoding': 'unicode',
'report_level': 5, # Suppress all messages
'halt_level': 5, # Don't halt on any level
}
return docutils.core.publish_string(
source=rst_content,
writer_name='html',
settings_overrides=overrides
)
def get_content(filename):
"""Read and convert RST content from file."""
with open(os.path.join('content', filename), 'r', encoding='utf-8') as f:
return rst_to_html(f.read())
def build_page(template, content_file, output_file):
"""Build a single page."""
with app.app_context():
content = get_content(content_file)
html = render_template(template,
content=content,
current_year=datetime.now().year)
# Ensure the directory exists
os.makedirs(os.path.dirname(output_file), exist_ok=True)
with open(output_file, 'w', encoding='utf-8') as f:
f.write(html)
def main():
# Create output directory
if os.path.exists('_site'):
shutil.rmtree('_site')
os.makedirs('_site')
# Build pages
build_page('index.html', 'index.rst', '_site/index.html')
build_page('publications.html', 'publications.rst', '_site/publications/index.html')
build_page('experience.html', 'experience.rst', '_site/experience/index.html')
# Copy static files
if os.path.exists('static'):
shutil.copytree('static', '_site/static', dirs_exist_ok=True)
print("Static files copied successfully")
else:
print("Warning: static directory not found")
if __name__ == '__main__':
main()