I legit forgot to commit today and then there was (still kinda is) a thunderstorm and power got rekt
it's back online but ssh is broken so kinda sad I'll probably have to fix this
This commit is contained in:
Minecon724 2024-05-20 18:16:13 +02:00
parent b3827b3d5e
commit 209a9e6adc
3 changed files with 6 additions and 7 deletions

View file

@ -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)

View file

@ -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)
def replace_variable(content: str, var: str, val: str) -> str:
return content.replace('{{ ' + var + ' }}', val)

View file

@ -1,2 +0,0 @@
def replace_variable(var: str, content: str) -> str:
return content.replace('{{ ' + var + ' }}', content)