30 lines
No EOL
1 KiB
Python
30 lines
No EOL
1 KiB
Python
from article import Article, Site
|
|
from jinja2 import Environment, Template, FileSystemLoader, select_autoescape
|
|
|
|
class TemplateEnvironment:
|
|
environment: Environment
|
|
site: Site
|
|
post_template: Template
|
|
index_template: Template
|
|
|
|
def __init__(self, template_directory: str, site: Site):
|
|
self.environment = Environment(
|
|
loader = FileSystemLoader(template_directory, followlinks=True),
|
|
autoescape = select_autoescape()
|
|
)
|
|
|
|
self.site = site
|
|
self.post_template = self.environment.get_template('post_template.html')
|
|
self.index_template = self.environment.get_template('index.html')
|
|
|
|
def process_article(self, article: Article) -> str:
|
|
return self.post_template.render(
|
|
site = self.site,
|
|
article = article
|
|
)
|
|
|
|
def process_index(self, *articles: Article) -> str:
|
|
return self.index_template.render(
|
|
site = self.site,
|
|
articles = articles
|
|
) |