Skip to content

Commit

Permalink
Merge pull request #271 from render-engine:update-hookspecs-and-site-…
Browse files Browse the repository at this point in the history
…for-post_render_content

Updates post_render_content
  • Loading branch information
kjaymiller committed Oct 4, 2023
2 parents 5971164 + 461bee5 commit dcbfe47
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/render_engine/hookspecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def render_content(
def post_render_content(
self,
page : "page",
settings: dict[str: typing.Any]):
settings: dict[str: typing.Any],
site: "Site",
) -> None:
"""
Augments the content of the page before it is rendered as output.
"""
Expand Down
12 changes: 9 additions & 3 deletions src/render_engine/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import pathlib
import typing
from collections import defaultdict
from re import template

import pluggy
from jinja2 import Environment
from jinja2 import Environment, FileSystemLoader
from rich.progress import Progress

from .collection import Collection
Expand Down Expand Up @@ -45,6 +46,7 @@ class Site(ThemeManager):
"DATETIME_FORMAT": "%d %b %Y %H:%M %Z"
}
engine: Environment = engine
template_path: str = "templates"


def __init__(
Expand All @@ -54,6 +56,9 @@ def __init__(
self.subcollections = defaultdict(lambda: {"pages": []})
self.engine.globals.update(self.site_vars)

if self.template_path:
self.engine.loader.loaders.insert(0, FileSystemLoader(self.template_path))

# Manage Plugins
self._pm = pluggy.PluginManager(project_name=_PROJECT_NAME)
self._pm.add_hookspecs(SiteSpecs)
Expand Down Expand Up @@ -179,8 +184,9 @@ def _render_output(self, route: str, page: Page):
)
path.parent.mkdir(parents=True, exist_ok=True)
page.rendered_content = page._render_content(engine=self.engine)

self._pm.hook.post_render_content(page=page)
# pass the route to the plugin settings
settings = {**self.site_settings.get('plugins', {}), **{'route': route}}
self._pm.hook.post_render_content(page=page.__class__, settings=settings, site=self)

return path.write_text(page.rendered_content)

Expand Down

0 comments on commit dcbfe47

Please sign in to comment.