diff options
| author | user <user@node5.net> | 2024-02-26 22:30:39 +0100 |
|---|---|---|
| committer | user <user@node5.net> | 2024-02-26 22:30:39 +0100 |
| commit | a855ebc794f40045a97cd9f2b5ad75e0302c7564 (patch) | |
| tree | e59c5dab13c6d77c4abca5d7b415a55a36d081cf /src/blog_node5_net.py | |
| parent | ac71b7ca1de2462e3101c5360842de80079449d2 (diff) | |
render articles
Diffstat (limited to 'src/blog_node5_net.py')
| -rw-r--r-- | src/blog_node5_net.py | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/blog_node5_net.py b/src/blog_node5_net.py index fcaf750..af26c76 100644 --- a/src/blog_node5_net.py +++ b/src/blog_node5_net.py @@ -6,42 +6,45 @@ import os import article_handler logging.basicConfig(format='%(asctime)s,%(msecs)03d %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s', - datefmt='%Y-%m-%d:%H:%M:%S', - level=logging.DEBUG) + datefmt='%Y-%m-%d:%H:%M:%S', level=logging.DEBUG) logger = logging.getLogger(__name__) -app = flask.Flask(__name__) - site_root_folder_path = 'blog.node5.net' +app = flask.Flask(__name__, template_folder=os.path.join('..', site_root_folder_path, 'templates'), + static_folder=os.path.join('..', site_root_folder_path, 'static'), static_url_path='') folders_by_url: typing.Dict[str, article_handler.Folder] = {} articles_by_url: typing.Dict[str, article_handler.Article] = {} +@app.context_processor # Always inject title to all render_templates +def inject_title(): + return {'title': site_root_folder_path} + + def strip_trailing_slash(path): - ''' - Strip trailing slashes from path - ''' stripped_path = path if not path[len(path) - 1] == '/' else path[:-1] return stripped_path + def view_folder(): path = flask.request.path if path is not '/': - path = strip_trailing_slash(flask.request.path) + path = strip_trailing_slash(flask.request.path) a = folders_by_url[path] return 'Folder' def view_article(): path = strip_trailing_slash(flask.request.path) - return articles_by_url[path].pretty_print + article = articles_by_url[path] + return flask.render_template('article.html', article=article) def register_urls(folder: article_handler.Folder): # Use recursion to traverse folder tree structure app.add_url_rule(folder.url, view_func=view_folder) - folders_by_url[strip_trailing_slash(folder.url)] = folder + folders_by_url[strip_trailing_slash(folder.url) if folder.url != '/' else folder.url] = folder for article in folder.articles: logger.debug(f"Registering url: {article.url}, static path: {article.folder_path}") blueprint_args = {} |
