This repository has been archived on 2025-01-08. You can view files and clone it, but cannot push or open issues or pull requests.
blog-software/template.py

30 lines
1 KiB
Python
Raw Normal View History

2024-05-23 16:16:02 +02:00
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
)