diff --git a/article.py b/article.py index 0e60945..c62b70f 100644 --- a/article.py +++ b/article.py @@ -11,8 +11,8 @@ class Article: def read_article_file(file: TextIOWrapper) -> Article: id = file.name.split(sep)[-1].split('.')[0] - title = file.readline() - summary = file.readline() + title = file.readline().strip() + summary = file.readline().strip() content = file.read().strip() return Article(id, title, summary, content) \ No newline at end of file diff --git a/compiler.py b/compiler.py index 1dc98ed..239094b 100644 --- a/compiler.py +++ b/compiler.py @@ -18,6 +18,7 @@ def compile(template_directory: str, work_directory: str, target_directory: str) file = open(join(root, fn), 'r+') article = read_article_file(file) + print(post_template) content = process_html(post_template, { 'title': article.title, 'summary': article.summary, @@ -30,9 +31,9 @@ def compile(template_directory: str, work_directory: str, target_directory: str) def process_html(content: str, variables: Dict[str, str]) -> str: for k, v in variables.items(): - content = replace_variable(k, v) + content = replace_variable(content, k, v) return content -def replace_variable(var: str, content: str) -> str: - return content.replace('{{ ' + var + ' }}', content) \ No newline at end of file +def replace_variable(content: str, var: str, val: str) -> str: + return content.replace('{{ ' + var + ' }}', val) \ No newline at end of file diff --git a/text.py b/text.py deleted file mode 100644 index 240b336..0000000 --- a/text.py +++ /dev/null @@ -1,2 +0,0 @@ -def replace_variable(var: str, content: str) -> str: - return content.replace('{{ ' + var + ' }}', content) \ No newline at end of file