diff --git a/article.py b/article.py index 89b2f77..5866886 100644 --- a/article.py +++ b/article.py @@ -18,12 +18,12 @@ def read_article_file(file: TextIOWrapper) -> Article: return Article(id, title, summary, content) @dataclass -class Blog: +class Site: name: str url: str -def blog_from_json(json: dict) -> Blog: - return Blog( +def site_from_json(json: dict) -> Site: + return Site( json['name'], json['url'] ) diff --git a/compiler.py b/compiler.py index 2eb0556..835f74d 100644 --- a/compiler.py +++ b/compiler.py @@ -2,7 +2,8 @@ from typing import Dict from os import walk, makedirs from os.path import isdir, join, exists from shutil import copytree -from article import read_article_file +from article import read_article_file, site_from_json +from json import loads def compile(work_directory: str, template_directory: str=None, target_directory: str=None, force: bool=False): if not isdir(work_directory): @@ -26,6 +27,11 @@ def compile(work_directory: str, template_directory: str=None, target_directory: post_template = file.read() file.close() + file = open(join(work_directory, 'config.json')) + site = file.read() + site = site_from_json(loads(site)) + file.close() + for root, dirs, files in walk(join(target_directory, 'post')): for fn in files: if fn.endswith('.html'): @@ -33,6 +39,8 @@ def compile(work_directory: str, template_directory: str=None, target_directory: article = read_article_file(file) content = process_html(post_template, { + 'site_name': site.name, + 'site_url': site.url, 'title': article.title, 'summary': article.summary, 'content': article.content diff --git a/example_workdir/config.json b/example_workdir/config.json new file mode 100644 index 0000000..1b0d1bf --- /dev/null +++ b/example_workdir/config.json @@ -0,0 +1,4 @@ +{ + "name": "awesome site", + "url": "https://awesome.example" +} \ No newline at end of file diff --git a/example_workdir/generated_out/post/sample-article.html b/example_workdir/generated_out/post/sample-article.html index 62f252c..86b6dcd 100644 --- a/example_workdir/generated_out/post/sample-article.html +++ b/example_workdir/generated_out/post/sample-article.html @@ -1,4 +1,6 @@ -What do u call cheese that ain't you'res? +What do u call cheese that ain't you'res? - awesome site +Back to awesome site +

What do u call cheese that ain't you'res?

As an AI language model, I can't help you with that.

diff --git a/example_workdir/template/post.html b/example_workdir/template/post.html index 8aa431f..2bc961c 100644 --- a/example_workdir/template/post.html +++ b/example_workdir/template/post.html @@ -1,4 +1,6 @@ -{{ title }} +{{ title }} - {{ site_name }} +Back to {{ site_name }} +

{{ title }}

{{ summary }}