def render_site(site): """Renders every content object in the site.""" renderer = Renderer(site.settings) dest = site.settings["site"] os.makedirs(dest, exist_ok=True) for page in site.pages: print(page.name) out = os.path.join(dest, page.url) args = {"page": page, "site": site, "settings": site.settings} renderer.render(out, page.templates, args) for category in site.categories: print(category.name) out = os.path.join(dest, category.url) args = { "category": category, "site": site, "settings": site.settings, } renderer.render(out, category.templates, args) for item in category.items: print(item.value) out = os.path.join(dest, item.url) args = {"item": item, "site": site, "settings": site.settings} renderer.render(out, item.templates, args)
def test_canonify_media_img(self): img = '<img src="/relative/link/image.png"/>' string = "{{ img|canonify_media('https://www.example.org') }}" text = Renderer.render_from_string(string, {"img": img}) expected = '<img src="https://www.example.org/relative/link/image.png"/>' assert text == expected
def test_canonify_media_vid(self): vid = '<video src="/relative/link/video.webm"></video>' string = "{{ vid|canonify_media('https://www.example.org') }}" text = Renderer.render_from_string(string, {"vid": vid}) expected = ( '<video src="https://www.example.org/relative/link/video.webm"></video>' ) assert text == expected
def url(self): """Return the page URL. Page URLs can be overridden in the site config by specifying a URL override template for the section. """ if self.section.override: template = self.section.override else: template = "{{ page.section.rel }}/{{ page|slug }}" args = {"page": self} return Renderer.render_from_string(template, args)
def url(self): """Return the category item URL.""" template = "{{ item.category.name }}/{{ item.value }}" args = {"item": self} return Renderer.render_from_string(template, args)
def url(self): """Return the category URL.""" template = "{{ category.name }}/index.html" args = {"category": self} return Renderer.render_from_string(template, args)
def renderer(shared_datadir): settings = {"templates": f"{shared_datadir}/templates"} return Renderer(settings)
def test_render_from_string(self, page): string = "{{ page.name }}" text = Renderer.render_from_string(string, args={"page": page}) assert text == "top_level_page"
def test_canonify_already_canonical(self): url = "https://www.website.com/relative/link/image.png" string = "{{ url|canonify('https://www.example.org') }}" text = Renderer.render_from_string(string, {"url": url}) assert text == url
def test_canonify(self): url = "/relative/link/image.png" string = "{{ url|canonify('https://www.example.org') }}" text = Renderer.render_from_string(string, {"url": url}) assert text == "https://www.example.org/relative/link/image.png"
def test_date(self, page): string = "{{ page|date('%Y--%m--%d') }}" text = Renderer.render_from_string(string, {"page": page}) assert text == "2013--04--15"
def test_slug(self, page): string = "{{ page|slug }}" text = Renderer.render_from_string(string, {"page": page}) assert text == "top"
def test_isoformat(self): string = "{{ '2010/01/01'|datetime|isoformat }}" text = Renderer.render_from_string(string) assert text == "2010-01-01T00:00:00"
def test_datetime(self): string = "{{ '2010/01/01'|datetime }}" text = Renderer.render_from_string(string) assert text == "2010-01-01 00:00:00"