Implement simple build script

This commit is contained in:
Aaron Cook 2026-03-15 11:55:14 -05:00
commit 89738f9392
11 changed files with 178 additions and 74 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
public/

112
build.py Executable file
View file

@ -0,0 +1,112 @@
#!/usr/bin/env python3
import os
from io import TextIOWrapper
import sys
NAVBAR_FMT = '''
<ul>
<li><a href="index.html">
Home{}
</a></li>
<li><a href="projects.html">
Projects{}
</a></li>
<li><a href="about.html">
About & Contact{}
</a></li>
</ul>
'''
SELECT_FMT = ' &lt;'
current_source = ''
def token_to_str(token: str) -> str:
global current_source
if token == 'NAVBAR':
home_str = ''
projects_str = ''
about_str = ''
if current_source == 'index.html':
home_str = SELECT_FMT
elif current_source == 'projects.html':
projects_str = SELECT_FMT
elif current_source == 'about.html':
about_str = SELECT_FMT
return NAVBAR_FMT.format(home_str, projects_str, about_str)
elif token.endswith('.html'):
return open('includes/' + token).read()
else:
return '{{' + token + '}}'
def replace_line(line: str) -> (str, int):
ret = ''
count = 0
replacing = False
token = ''
i = 0
while i < (len(line) - 2):
if replacing:
if line[i:i+2] == r'}}':
replacing = False
ret += token_to_str(token)
i += 2
token = ''
count += 1
else:
token += line[i]
i += 1
else:
if line[i:i+2] == r'{{':
replacing = True
i += 2
else:
ret += line[i]
i += 1
if replacing:
ret += '{{' + token
ret += line[i:]
return (ret, count)
def stream_template(in_fd: TextIOWrapper, out_fd: TextIOWrapper) -> int:
replacements = 0
while True:
line = in_fd.readline()
if line == '':
break
new_line, count = replace_line(line)
out_fd.write(new_line)
replacements += count
return replacements
def main():
global current_source
includes = os.listdir('includes')
sources = os.listdir('src')
print(includes)
print(sources)
if not os.path.isdir('public'):
os.mkdir('public')
for source in sources:
current_source = source
in_fd = open('src/' + source, 'r')
out_fd = open('public/' + source, 'w')
stream_template(in_fd, out_fd)
if __name__ == '__main__':
main()

5
includes/footer.html Normal file
View file

@ -0,0 +1,5 @@
<p>Hand written by Aaron Cook
<a href="https://gitlab.com/CookenMonster/aarongc.com" target="_blank" rel="noopener noreferrer">
<i class="nf nf-dev-gitlab"></i>
</a>
</p>

2
includes/header.html Normal file
View file

@ -0,0 +1,2 @@
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="https://www.nerdfonts.com/assets/css/webfont.css">

1
includes/titlebar.html Normal file
View file

@ -0,0 +1 @@
<h1>Aaron G.C. Personal Website</h1>

View file

@ -1,33 +0,0 @@
<!DOCTYPE html>
<html>
<header>
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="https://www.nerdfonts.com/assets/css/webfont.css">
</header>
<body>
<div class="titlebar">
<h1>Aaron G.C. Personal Website</h1>
</div>
<div class="content">
<div class="navbar">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="projects.html">Projects</a></li>
<li><a href="about.html">About & Contact &lt;</a></li>
</ul>
</div>
<div class="page">
<p>Site currently under construction.</p>
</div>
</div>
<div class="footer">
<p>Hand written by Aaron Cook <a href="https://gitlab.com/CookenMonster/aarongc.com"><i
class="nf nf-dev-gitlab"></i></a></p>
</div>
</body>
</html>

View file

@ -1,31 +0,0 @@
<!DOCTYPE html>
<html>
<header>
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="https://www.nerdfonts.com/assets/css/webfont.css">
</header>
<body>
<div class="titlebar">
<h1>Aaron G.C. Personal Website</h1>
</div>
<div class="content">
<div class="navbar">
<ul>
<li><a href="index.html">Home &lt;</a></li>
<li><a href="projects.html">Projects</a></li>
<li><a href="about.html">About & Contact</a></li>
</ul>
</div>
<div class="page">
<p>Site currently under construction.</p>
</div>
</div>
<div class="footer">
<p>Hand written by Aaron Cook <a href="https://gitlab.com/CookenMonster/aarongc.com"><i class="nf nf-dev-gitlab"></i></a></p>
</div>
</body>
</html>

27
src/about.html Normal file
View file

@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<header>
{{header.html}}
</header>
<body>
<div class="titlebar">
{{titlebar.html}}
</div>
<div class="content">
<div class="navbar">
{{NAVBAR}}
</div>
<div class="page">
<p>Site currently under construction.</p>
</div>
</div>
<div class="footer">
{{footer.html}}
</div>
</body>
</html>

26
src/index.html Normal file
View file

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<header>
{{header.html}}
</header>
<body>
<div class="titlebar">
{{titlebar.html}}
</div>
<div class="content">
<div class="navbar">
{{NAVBAR}}
</div>
<div class="page">
<p>Site currently under construction.</p>
</div>
</div>
<div class="footer">
{{footer.html}}
</div>
</body>
</html>

View file

@ -1,22 +1,17 @@
<!DOCTYPE html>
<html>
<header>
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="https://www.nerdfonts.com/assets/css/webfont.css">
{{header.html}}
</header>
<body>
<div class="titlebar">
<h1>Aaron G.C. Personal Website</h1>
{{titlebar.html}}
</div>
<div class="content">
<div class="navbar">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="projects.html">Projects &lt;</a></li>
<li><a href="about.html">About & Contact</a></li>
</ul>
{{NAVBAR}}
</div>
<div class="page">
@ -46,8 +41,7 @@
</div>
<div class="footer">
<p>Hand written by Aaron Cook <a href="https://gitlab.com/CookenMonster/aarongc.com"><i
class="nf nf-dev-gitlab"></i></a></p>
{{footer.html}}
</div>
</body>