|
7 | 7 | from dataclasses import dataclass, field
|
8 | 8 | from datetime import date, datetime, time
|
9 | 9 | from pathlib import Path
|
10 |
| -from types import MappingProxyType |
11 | 10 |
|
12 | 11 | import jinja2
|
13 | 12 | import rfeed
|
|
28 | 27 | )
|
29 | 28 | RSS_FILE_NAME = 'index.xml'
|
30 | 29 | v = sys.version_info
|
31 |
| -CONTEXT = MappingProxyType(dict( |
32 |
| - python_version=f'{v.major}.{v.minor}.{v.micro}', |
33 |
| - now=datetime.now(), |
34 |
| - commit_sha=os.environ.get('CF_PAGES_COMMIT_SHA'), |
35 |
| -)) |
36 | 30 |
|
37 | 31 |
|
38 | 32 | @dataclass(frozen=True)
|
@@ -95,6 +89,11 @@ def run(self) -> int:
|
95 | 89 | 'index',
|
96 | 90 | pages=PAGES,
|
97 | 91 | years=sorted(years.items(), reverse=True),
|
| 92 | + |
| 93 | + # for rendering footer |
| 94 | + python_version=f'{v.major}.{v.minor}.{v.micro}', |
| 95 | + now=datetime.now(), |
| 96 | + commit_sha=os.environ.get('CF_PAGES_COMMIT_SHA'), |
98 | 97 | )
|
99 | 98 | render_html(
|
100 | 99 | 'typing',
|
@@ -156,15 +155,15 @@ def _prepare_dirs(self) -> None:
|
156 | 155 |
|
157 | 156 | def render_html(slug: str, title: str | None = None, **kwargs) -> None:
|
158 | 157 | template = jinja_env.get_template(f'{slug}.html.j2')
|
159 |
| - content = template.render(len=len, title=title, **CONTEXT, **kwargs) |
| 158 | + content = template.render(len=len, title=title, **kwargs) |
160 | 159 | html_path = ROOT / 'public' / f'{slug}.html'
|
161 | 160 | html_path.write_text(content, encoding='utf8')
|
162 | 161 |
|
163 | 162 |
|
164 | 163 | def render_post(posts: list[PostToRender]) -> None:
|
165 | 164 | main_post = posts[0]
|
166 | 165 | template = jinja_env.get_template('post.html.j2')
|
167 |
| - content = template.render(title=main_post.title, posts=posts, **CONTEXT) |
| 166 | + content = template.render(title=main_post.title, posts=posts) |
168 | 167 | html_path = ROOT / 'public' / 'posts' / f'{main_post.slug}.html'
|
169 | 168 | html_path.write_text(content, encoding='utf8')
|
170 | 169 |
|
|
0 commit comments