-
- Site currently under construction.
-diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d298be1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +public/ \ No newline at end of file diff --git a/build.py b/build.py new file mode 100755 index 0000000..7fffff5 --- /dev/null +++ b/build.py @@ -0,0 +1,112 @@ +#!/usr/bin/env python3 +import os +from io import TextIOWrapper +import sys + +NAVBAR_FMT = ''' +
+''' +SELECT_FMT = ' <' +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() diff --git a/includes/footer.html b/includes/footer.html new file mode 100644 index 0000000..efcd2ab --- /dev/null +++ b/includes/footer.html @@ -0,0 +1,5 @@ +Hand written by Aaron Cook + + + +
\ No newline at end of file diff --git a/includes/header.html b/includes/header.html new file mode 100644 index 0000000..f1ee96e --- /dev/null +++ b/includes/header.html @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/includes/titlebar.html b/includes/titlebar.html new file mode 100644 index 0000000..51b6436 --- /dev/null +++ b/includes/titlebar.html @@ -0,0 +1 @@ +Site currently under construction.
-Site currently under construction.
-Site currently under construction.
+Site currently under construction.
+