diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/article.py | 9 | ||||
| -rw-r--r-- | src/blog_node5_net.py | 27 |
2 files changed, 23 insertions, 13 deletions
diff --git a/src/article.py b/src/article.py index 0b437bc..a35b431 100644 --- a/src/article.py +++ b/src/article.py @@ -87,10 +87,9 @@ class ArticleGenerator: self.articles_path = articles_path def get_web_dir(self, path, name) -> tuple[str, ...]: - dir_structure = path.split(name)[0] - # Split into tuple, remove first part, assemble to path again, all to remove the first source dir agnostically - dir_structure_prefix_striped = pathlib.Path(dir_structure).parts[2:] - return dir_structure_prefix_striped + dir = path.split(name)[0] # Get dir for one file articles and folder articles + web_path = pathlib.Path(dir).relative_to(pathlib.Path(self.articles_path)) + return web_path.parts def parse_article_meta_data(self, source: str) -> typing.Tuple[str, MetaData]: if source.startswith('---'): @@ -189,6 +188,6 @@ class ArticleGenerator: for article_path in articles_paths: article = self.get_article(article_path) logger.debug(article.pretty_print) - self.discover_folder_structure(articles=articles, article=article) + self.discover_folder_structure(article=article, articles=articles) self.sort_articles(articles) return articles diff --git a/src/blog_node5_net.py b/src/blog_node5_net.py index a8961d8..7da959c 100644 --- a/src/blog_node5_net.py +++ b/src/blog_node5_net.py @@ -5,6 +5,7 @@ import signal import sys import typing import urllib +import pathlib import flask import markdown @@ -50,10 +51,11 @@ stream_handler.setFormatter(CustomFormatter()) logger.root.addHandler(stream_handler) logger.info(f"Debug: {'en' if debug else 'dis'}abled") -with open(os.path.join('configs', 'config.yml'), 'r') as file: - config = yaml.safe_load(file.read()) +content_root_path = os.environ.get("CONTENT_ROOT_PATH") +if not content_root_path: + sys.exit("ERROR: required environment variable CONTENT_ROOT_PATH is not set") -article_generator = article.ArticleGenerator(os.path.join(config['site_root_folder_path'], 'articles')) +article_generator = article.ArticleGenerator(os.path.join(content_root_path, 'articles')) def get_articles() -> article.Folder: @@ -70,10 +72,11 @@ if len(sys.argv) > 1 and sys.argv[1] == 'validate': logger.info('OK') exit(0) -app = flask.Flask(__name__, template_folder=os.path.join('..', config['site_root_folder_path'], 'templates'), - static_folder=os.path.join('..', config['site_root_folder_path'], 'static'), static_url_path='') - -with open(os.path.join(config['site_root_folder_path'], 'motd.md'), 'r') as file: +template_path = os.path.join('..', content_root_path, 'templates') +logger.debug(f"template path: {template_path}") +app = flask.Flask(__name__, template_folder=template_path, + static_folder=os.path.join('..', content_root_path, 'static'), static_url_path='') +with open(os.path.join(content_root_path, 'motd.md'), 'r') as file: motd_list = [markupsafe.Markup(markdown.markdown(line)) for line in file.readlines()] folders_by_url: typing.Dict[str, article.Folder] = {} @@ -107,7 +110,7 @@ def inject_common(): 'insert_sql_pretty': insert_sql_pretty, 'comments_sql': markupsafe.Markup(markdown.markdown(sql_pretty)), 'comments': comments_formatted, - 'title': config['site_root_folder_path'], + 'title': pathlib.Path(content_root_path).name, 'motd': random.choice(motd_list) } @@ -203,3 +206,11 @@ def signal_handler(signum, frame): signal.signal(signal.SIGHUP, signal_handler) + + +def main(): + global app + app.run() + +if __name__ == '__main__': + main() |
