From 93077098a771147f756fb22760acb09f50ce4fe1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 12 Oct 2018 21:36:16 +0200 Subject: [PATCH] theme: ability to create pages with a passthrough template. I.e., without any header navbar or footer. --- doc/pelican/theme.rst | 46 +++++++++++++++++++ pelican-theme/templates/passthrough.html | 26 +++++++++++ .../test/page_passthrough/input/page.html | 22 +++++++++ pelican-theme/test/page_passthrough/page.html | 18 ++++++++ pelican-theme/test/test_page.py | 12 +++++ 5 files changed, 124 insertions(+) create mode 100644 pelican-theme/templates/passthrough.html create mode 100644 pelican-theme/test/page_passthrough/input/page.html create mode 100644 pelican-theme/test/page_passthrough/page.html diff --git a/doc/pelican/theme.rst b/doc/pelican/theme.rst index 478757b0..f9c2bf9d 100644 --- a/doc/pelican/theme.rst +++ b/doc/pelican/theme.rst @@ -811,6 +811,52 @@ Index, archive and all category/tag/author pages are paginated based on the to prev and next page, besides that there's :html:`` and :html:`` that provides the same as a hint to search engines. +`Pass-through pages`_ +===================== + +Besides `pages`_, `articles`_ and `pre-defined pages`_ explained above, where +the content is always wrapped with the navbar on top and the footer bottom, +it's possible to have pages with fully custom markup --- for example various +presentation slides, demos etc. To do that, set the :rst:`:template:` metadata +to ``passthrough``. While it works with :abbr:`reST ` +sources, this is best combined with raw HTML input. Pelican will copy the +contents of the :html:`` tag verbatim and use contents of the +:html:`` element for a page title, put again in the :html:`<title>` +(*not* as a :html:`<h1>` inside :html:`<body>`). Besides that, you can specify +additional metadata using the :html:`<meta name="key" content="value" />` tags: + +- :html:`<meta name="template" content="passthrough" />` needs to be always + present in order to make Pelican use the passthrough template. +- :html:`<meta name="css" />`, :html:`<meta name="js" />` and + :html:`<meta name="html_header" />` specify additional CSS files, + JavaScript files and arbitrary HTML, similarly as with normal pages. The + ``content`` can be multiple lines, empty lines are discarded for CSS and JS + references. Be sure to properly escape everything. +- :html:`<meta name="class" />` can be used to add a CSS class to the + top-level :html:`<html>` element +- All usual Pelican metadata like ``url``, ``slug`` etc. work here as well. + +Note that at the moment, the pass-through pages do not insert any of the +(social) meta tags. Example of an *input* file for a pass-through page: + +.. code:: html + + <!DOCTYPE html> + <html lang="en"> + <head> + <title>WebGL Demo Page + + + + + + + + + `Theme properties`_ =================== diff --git a/pelican-theme/templates/passthrough.html b/pelican-theme/templates/passthrough.html new file mode 100644 index 00000000..d06be23b --- /dev/null +++ b/pelican-theme/templates/passthrough.html @@ -0,0 +1,26 @@ + + + + + {{ page.title }} + + {% if page.css %} + {% set styles = page.css.strip().split('\n') %} + {% for style in styles %} + + {% endfor %} + {% endif %} + {% if page.js %} + {% set scripts = page.js.strip().split('\n') %} + {% for script in scripts %} + + {% endfor %} + {% endif %} + {% if page.html_header %} + {{ page.html_header.strip()|indent(2) }} + {% endif %} + + +{{- page.content -}} + + diff --git a/pelican-theme/test/page_passthrough/input/page.html b/pelican-theme/test/page_passthrough/input/page.html new file mode 100644 index 00000000..2f1dede6 --- /dev/null +++ b/pelican-theme/test/page_passthrough/input/page.html @@ -0,0 +1,22 @@ + + + + WebGL Demo Page + + + + + + + + + + diff --git a/pelican-theme/test/page_passthrough/page.html b/pelican-theme/test/page_passthrough/page.html new file mode 100644 index 00000000..7c97eb72 --- /dev/null +++ b/pelican-theme/test/page_passthrough/page.html @@ -0,0 +1,18 @@ + + + + + WebGL Demo Page + + + + + + + + + + + + diff --git a/pelican-theme/test/test_page.py b/pelican-theme/test/test_page.py index 3666cd63..ceb0d281 100644 --- a/pelican-theme/test/test_page.py +++ b/pelican-theme/test/test_page.py @@ -191,3 +191,15 @@ class GlobalSocialMeta(PageTestCase): # Verify that the social meta tags are present self.assertEqual(*self.actual_expected_contents('page.html')) + +class Passthrough(PageTestCase): + def __init__(self, *args, **kwargs): + super().__init__(__file__, 'passthrough', *args, **kwargs) + + def test(self): + self.run_pelican({ + 'READERS': {}, # re-enable the HTML reader + 'PAGE_PATHS': ['input'] + }) + + self.assertEqual(*self.actual_expected_contents('page.html')) -- 2.30.2