diff --git a/build.py b/build.py old mode 100755 new mode 100644 index 7fffff5..f383ded --- a/build.py +++ b/build.py @@ -1,48 +1,66 @@ #!/usr/bin/env python3 import os from io import TextIOWrapper +import shutil import sys +import re NAVBAR_FMT = '''
''' +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() diff --git a/includes/footer.html b/includes/footer.html index 7ad85e7..7351d0b 100644 --- a/includes/footer.html +++ b/includes/footer.html @@ -1,5 +1,5 @@ -Hand written by Aaron Cook +
+ Website source, all hand written, available - - + here.
diff --git a/includes/header.html b/includes/header.html index f1ee96e..afd2533 100644 --- a/includes/header.html +++ b/includes/header.html @@ -1,2 +1 @@ - - \ No newline at end of file + diff --git a/includes/titlebar.html b/includes/titlebar.html index 51b6436..6db7355 100644 --- a/includes/titlebar.html +++ b/includes/titlebar.html @@ -1 +1 @@ -Site currently under construction.
++ I am an embedded firmware developer and hobbyist based out of + Minneapolis. I am actively engaged in the fighting game and furry + communities. +
++ Generally, each year I attend the + Furry Migration + and + Fursquared + furry conventions, as well as the annual MN fighting game tournament + Midwest Mixfest. + Feel free to say hi if you see me there! +
+ +Development profiles:
+Social media profiles:
+
+ Aaron - Red Wolf
+
+ Mim - Mouse
+