| 1 | #!/usr/bin/python3 |
| 2 | |
| 3 | # (c) 2017 Aaron Taylor <ataylor at subgeniuskitty dot com> |
| 4 | # See LICENSE file for copyright and license details. |
| 5 | |
| 6 | # Python imports |
| 7 | import sys, os, urllib.parse |
| 8 | |
| 9 | # CMless imports |
| 10 | import config, misc, template |
| 11 | |
| 12 | def main(): |
| 13 | print("Content-Type: text/html;charset=utf-8\n") |
| 14 | |
| 15 | # Since we can't use Apache's DirectoryIndex directive due to a RewriteCond |
| 16 | # passing all non-file objects to this script, we implement equivalent |
| 17 | # functionality here. |
| 18 | if os.environ['REQUEST_URI'][-1] == "/": |
| 19 | os.environ['REQUEST_URI'] = os.environ['REQUEST_URI'] + config.default_page |
| 20 | |
| 21 | # Since we use REQUEST_URI to navigate the filesystem we need to unquote it. |
| 22 | # In other words, replace things like '%20' with ' ' (a space character). |
| 23 | os.environ['REQUEST_URI'] = urllib.parse.unquote(os.environ['REQUEST_URI']) |
| 24 | |
| 25 | # The template engine operates like a micropass compiler with each pass |
| 26 | # handling one tag from the template. Extensions to the template engine |
| 27 | # should be executed from here and should not have or create |
| 28 | # inter-dependencies. |
| 29 | content = misc.load_file(config.site_template_prefix + "/" + config.template_file) |
| 30 | content = template.page_title(content) |
| 31 | content = template.site_title(content) |
| 32 | content = template.current_year(content) |
| 33 | content = template.head_meta_description(content) |
| 34 | content = template.head_meta_keywords(content) |
| 35 | content = template.menu_top_level(content) |
| 36 | content = template.menu_current_dir(content) |
| 37 | content = template.body(content) |
| 38 | print(content) |
| 39 | |
| 40 | if __name__ == "__main__": |
| 41 | sys.exit(main()) |