work
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:
parent
b3827b3d5e
commit
209a9e6adc
3 changed files with 6 additions and 7 deletions
|
@ -11,8 +11,8 @@ class Article:
|
||||||
|
|
||||||
def read_article_file(file: TextIOWrapper) -> Article:
|
def read_article_file(file: TextIOWrapper) -> Article:
|
||||||
id = file.name.split(sep)[-1].split('.')[0]
|
id = file.name.split(sep)[-1].split('.')[0]
|
||||||
title = file.readline()
|
title = file.readline().strip()
|
||||||
summary = file.readline()
|
summary = file.readline().strip()
|
||||||
content = file.read().strip()
|
content = file.read().strip()
|
||||||
|
|
||||||
return Article(id, title, summary, content)
|
return Article(id, title, summary, content)
|
|
@ -18,6 +18,7 @@ def compile(template_directory: str, work_directory: str, target_directory: str)
|
||||||
file = open(join(root, fn), 'r+')
|
file = open(join(root, fn), 'r+')
|
||||||
article = read_article_file(file)
|
article = read_article_file(file)
|
||||||
|
|
||||||
|
print(post_template)
|
||||||
content = process_html(post_template, {
|
content = process_html(post_template, {
|
||||||
'title': article.title,
|
'title': article.title,
|
||||||
'summary': article.summary,
|
'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:
|
def process_html(content: str, variables: Dict[str, str]) -> str:
|
||||||
for k, v in variables.items():
|
for k, v in variables.items():
|
||||||
content = replace_variable(k, v)
|
content = replace_variable(content, k, v)
|
||||||
|
|
||||||
return content
|
return content
|
||||||
|
|
||||||
def replace_variable(var: str, content: str) -> str:
|
def replace_variable(content: str, var: str, val: str) -> str:
|
||||||
return content.replace('{{ ' + var + ' }}', content)
|
return content.replace('{{ ' + var + ' }}', val)
|
2
text.py
2
text.py
|
@ -1,2 +0,0 @@
|
||||||
def replace_variable(var: str, content: str) -> str:
|
|
||||||
return content.replace('{{ ' + var + ' }}', content)
|
|
Reference in a new issue