Commit | Line | Data |
---|---|---|
acd291ea AT |
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 | |
bc9c2a94 | 7 | import sys, os, urllib.parse |
acd291ea AT |
8 | |
9 | # CMless imports | |
d955cfad | 10 | import config, misc, template |
acd291ea AT |
11 | |
12 | def main(): | |
13 | print("Content-Type: text/html;charset=utf-8\n") | |
14 | ||
78e2ec48 AT |
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. | |
765a8ad0 AT |
18 | if os.environ['REQUEST_URI'][-1] == "/": |
19 | os.environ['REQUEST_URI'] = os.environ['REQUEST_URI'] + config.default_page | |
78e2ec48 AT |
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). | |
bc9c2a94 | 23 | os.environ['REQUEST_URI'] = urllib.parse.unquote(os.environ['REQUEST_URI']) |
765a8ad0 | 24 | |
78e2ec48 AT |
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. | |
d955cfad | 29 | content = misc.load_file(config.site_template_prefix + "/" + config.template_file) |
0a58f7f1 AT |
30 | content = template.page_title(content) |
31 | content = template.site_title(content) | |
990c6f79 | 32 | content = template.current_year(content) |
1debf034 AT |
33 | content = template.head_meta_description(content) |
34 | content = template.head_meta_keywords(content) | |
73c5dba9 AT |
35 | content = template.menu_top_level(content) |
36 | content = template.menu_current_dir(content) | |
0a58f7f1 | 37 | content = template.body(content) |
d955cfad | 38 | print(content) |
acd291ea AT |
39 | |
40 | if __name__ == "__main__": | |
41 | sys.exit(main()) |