render-engine 2025.10.1a1__py3-none-any.whl → 2025.10.1a2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
render_engine/page.py CHANGED
@@ -1,3 +1,4 @@
1
+ import logging
1
2
  import re
2
3
  from pathlib import Path
3
4
  from typing import Any
@@ -10,6 +11,8 @@ from render_engine.themes import ThemeManager
10
11
  from ._base_object import BaseObject
11
12
  from .plugins import PluginManager
12
13
 
14
+ logger = logging.getLogger("Page")
15
+
13
16
 
14
17
  class BasePage(BaseObject):
15
18
  """
@@ -28,6 +31,8 @@ class BasePage(BaseObject):
28
31
  extension (str): The file extension for the page. Defaults to ".html".
29
32
  routes (list[str] | Path): The list of routes for the page. Defaults to ["./"].
30
33
  template (str | Template | None): The template to use for rendering the page.
34
+ site: The Site object that owns the page.
35
+ no_prerender: Flag to not prerender the content
31
36
  """
32
37
 
33
38
  extension: str = ".html"
@@ -36,7 +41,8 @@ class BasePage(BaseObject):
36
41
  rendered_content: str | None
37
42
  _reference: str = "_slug"
38
43
  plugin_manager: PluginManager | None
39
- site = None
44
+ site = None # This is a Site but circular imports so we can't actually type hint it.
45
+ no_prerender: bool = False
40
46
 
41
47
  @property
42
48
  def _content(self) -> any:
@@ -69,20 +75,35 @@ class BasePage(BaseObject):
69
75
  return f"/{route}/{self.path_name}"
70
76
 
71
77
  def _render_from_template(self, template: Template, **kwargs) -> str:
72
- """Renders the page from a template."""
78
+ """
79
+ Renders the page from a template.
80
+
81
+ If the content looks like a template that
82
+
83
+ :param template: Template to render
84
+ :param **kwargs: Data to pass into the template for rendering.
85
+ :return: The rendered page
86
+ """
73
87
  template_data = {"data": self._data, "content": self._content}
74
88
  if site := getattr(self, "site", None):
75
89
  template_data["site_map"] = site.site_map
76
- if isinstance(self._content, str) and re.search(r"{{.*}}", self._content):
90
+ if not self.no_prerender and isinstance(self._content, str) and re.search(r"{{.*?site_map.*?}}", self._content):
77
91
  # If the content looks like a template, try to render it.
78
- content_template = Template(self._content)
79
- template_data["content"] = content_template.render(
80
- **{
81
- **self.to_dict(),
82
- **template_data,
83
- **kwargs,
84
- }
85
- )
92
+ try:
93
+ content_template = Template(self._content)
94
+ except Exception:
95
+ logger.info(f"Failed to parse {repr(self.path_name)} as a template.", exc_info=True)
96
+ else:
97
+ try:
98
+ template_data["content"] = content_template.render(
99
+ **{
100
+ **self.to_dict(),
101
+ **template_data,
102
+ **kwargs,
103
+ }
104
+ )
105
+ except Exception:
106
+ logger.info(f"Failed to pre-render {repr(self.path_name)}.", exc_info=True)
86
107
 
87
108
  return template.render(
88
109
  **{
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: render_engine
3
- Version: 2025.10.1a1
3
+ Version: 2025.10.1a2
4
4
  Summary: A Flexible Static Site Generator for Python
5
5
  Project-URL: homepage, https://github.com/render-engine/render-engine/
6
6
  Project-URL: repository, https://github.com/render-engine/render-engine/
@@ -9,7 +9,7 @@ render_engine/engine.py,sha256=GOtUiq4ny5GHaLSCeH5u1Zk1JnWJVh63vK7etJiwS20,2843
9
9
  render_engine/feeds.py,sha256=i-VHsb6pRplMzaenBn6oeqh9yI_N4WVUAExPox6iJgw,921
10
10
  render_engine/hookspecs.py,sha256=GhOpw0zTQjfwWOFYYbJ4P7Cvq-oy1MmTPHmd90dr0kg,2292
11
11
  render_engine/links.py,sha256=pKmQMTz8-yGX8IecHcrlF3Dkejk7cptaO3qCkQiHB9I,2560
12
- render_engine/page.py,sha256=mIKdOmyQ1zRcaoZej9hMV2xajH_frXllaO-ZpZMzCtM,8091
12
+ render_engine/page.py,sha256=l6sKWNJ4gBtC_ONEc0u479q3znL-8Q7U_phNqXqmh6w,8988
13
13
  render_engine/plugins.py,sha256=NXM8QTbbRV-DwgpQRoIhILijJBN4SyYg2Rkk1LUAuZM,4703
14
14
  render_engine/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  render_engine/site.py,sha256=URvG7OQSgeFOcrZwrD8vHLUWa6UxDBxIP-UMeLLqhZM,12936
@@ -32,7 +32,7 @@ render_engine/render_engine_templates/base_templates/_page.html,sha256=jjrY2BAwl
32
32
  render_engine/render_engine_templates/components/footer.html,sha256=HkPGGhfN0HcYm7t8zgXWCQ3bsCbT8FxT4_n2-9e1zUE,74
33
33
  render_engine/render_engine_templates/components/page_title.html,sha256=l8aE1TY94UPHXHqAyy6jv4IoN2Hv9cbrTPh7ILkMyxg,137
34
34
  render_engine/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
35
- render_engine-2025.10.1a1.dist-info/METADATA,sha256=X7uol4Ld4scOzJSZ0jYobZmf_AyTwJ53DAwt1hM488s,11895
36
- render_engine-2025.10.1a1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
37
- render_engine-2025.10.1a1.dist-info/top_level.txt,sha256=aNGALDMsFyrusho04AvUjSivsgEE9tQp_LP_jGr312Q,14
38
- render_engine-2025.10.1a1.dist-info/RECORD,,
35
+ render_engine-2025.10.1a2.dist-info/METADATA,sha256=7zx7Hwwq03zUMWfBOP2FfsFVOdIF4AiJKjEqsazJvOk,11895
36
+ render_engine-2025.10.1a2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
37
+ render_engine-2025.10.1a2.dist-info/top_level.txt,sha256=aNGALDMsFyrusho04AvUjSivsgEE9tQp_LP_jGr312Q,14
38
+ render_engine-2025.10.1a2.dist-info/RECORD,,