Add content for about and home page
Additionally added build script support for a blog page, and removed the external dependency on NerdFont CSS.
This commit is contained in:
parent
f177687947
commit
949dfa14bb
1 changed files with 202 additions and 50 deletions
94
build.py
Executable file → Normal file
94
build.py
Executable file → Normal file
|
|
@ -1,48 +1,66 @@
|
|||
#!/usr/bin/env python3
|
||||
import os
|
||||
from io import TextIOWrapper
|
||||
import shutil
|
||||
import sys
|
||||
import re
|
||||
|
||||
NAVBAR_FMT = '''
|
||||
<ul>
|
||||
<li><a href="index.html">
|
||||
<li><a href="/index.html">
|
||||
Home{}
|
||||
</a></li>
|
||||
<li><a href="projects.html">
|
||||
<li><a href="/projects.html">
|
||||
Projects{}
|
||||
</a></li>
|
||||
<li><a href="about.html">
|
||||
<details BLOG_OPEN>
|
||||
<summary>Ramblings</summary>
|
||||
<ul>
|
||||
<li><a href="/blog/2026-11-23.html">
|
||||
2026-11-22{}
|
||||
</a></li>
|
||||
</ul>
|
||||
</details>
|
||||
<li><a href="/about.html">
|
||||
About & Contact{}
|
||||
</a></li>
|
||||
</ul>
|
||||
'''
|
||||
NAVBAR_LINES = NAVBAR_FMT.split('\n')
|
||||
SELECT_FMT = ' <'
|
||||
current_source = ''
|
||||
|
||||
|
||||
def token_to_str(token: str) -> str:
|
||||
global current_source
|
||||
|
||||
def token_to_str(token: str, current_source: str) -> str:
|
||||
if token == 'NAVBAR':
|
||||
home_str = ''
|
||||
projects_str = ''
|
||||
about_str = ''
|
||||
fmt_strs = []
|
||||
href_re = re.compile('href\\="(.+)"')
|
||||
current_href = ''
|
||||
|
||||
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
|
||||
for line in NAVBAR_LINES:
|
||||
m = href_re.search(line)
|
||||
if m is not None:
|
||||
current_href = m.group(1)
|
||||
|
||||
return NAVBAR_FMT.format(home_str, projects_str, about_str)
|
||||
if '{}' in line:
|
||||
if (f'src{current_href}' == current_source):
|
||||
fmt_strs.append(SELECT_FMT)
|
||||
else:
|
||||
fmt_strs.append('')
|
||||
|
||||
if current_source.startswith('src/blog'):
|
||||
navbar_fmt = NAVBAR_FMT.replace('BLOG_OPEN', 'open')
|
||||
else:
|
||||
navbar_fmt = NAVBAR_FMT.replace('BLOG_OPEN', '')
|
||||
|
||||
print(fmt_strs)
|
||||
return navbar_fmt.format(*fmt_strs)
|
||||
elif token.endswith('.html'):
|
||||
return open('includes/' + token).read()
|
||||
else:
|
||||
return '{{' + token + '}}'
|
||||
|
||||
|
||||
def replace_line(line: str) -> (str, int):
|
||||
def replace_line(line: str, current_source: str) -> (str, int):
|
||||
ret = ''
|
||||
count = 0
|
||||
|
||||
|
|
@ -53,7 +71,7 @@ def replace_line(line: str) -> (str, int):
|
|||
if replacing:
|
||||
if line[i:i+2] == r'}}':
|
||||
replacing = False
|
||||
ret += token_to_str(token)
|
||||
ret += token_to_str(token, current_source)
|
||||
i += 2
|
||||
token = ''
|
||||
count += 1
|
||||
|
|
@ -74,7 +92,7 @@ def replace_line(line: str) -> (str, int):
|
|||
|
||||
return (ret, count)
|
||||
|
||||
def stream_template(in_fd: TextIOWrapper, out_fd: TextIOWrapper) -> int:
|
||||
def stream_template(in_fd: TextIOWrapper, out_fd: TextIOWrapper, current_source: str) -> int:
|
||||
replacements = 0
|
||||
|
||||
while True:
|
||||
|
|
@ -82,31 +100,43 @@ def stream_template(in_fd: TextIOWrapper, out_fd: TextIOWrapper) -> int:
|
|||
if line == '':
|
||||
break
|
||||
|
||||
new_line, count = replace_line(line)
|
||||
new_line, count = replace_line(line, current_source)
|
||||
out_fd.write(new_line)
|
||||
replacements += count
|
||||
|
||||
return replacements
|
||||
|
||||
|
||||
def main():
|
||||
global current_source
|
||||
def source_dir_to_output(source_dir: str, output_dir: str):
|
||||
sources = os.listdir(source_dir)
|
||||
|
||||
if not os.path.isdir(output_dir):
|
||||
os.mkdir(output_dir)
|
||||
|
||||
for source in sources:
|
||||
source_full = f'{source_dir}/{source}'
|
||||
output_full = f'{output_dir}/{source}'
|
||||
|
||||
if os.path.isdir(source_full):
|
||||
source_dir_to_output(source_full, output_full)
|
||||
continue
|
||||
|
||||
if source_full.endswith('.html'):
|
||||
in_fd = open(source_full, 'r')
|
||||
out_fd = open(output_full, 'w')
|
||||
stream_template(in_fd, out_fd, source_full)
|
||||
else:
|
||||
shutil.copy(source_full, output_full)
|
||||
|
||||
def main():
|
||||
print(NAVBAR_FMT)
|
||||
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)
|
||||
source_dir_to_output('src', 'public')
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
|||
Loading…
Reference in a new issue