chiark / gitweb /
theme: ability to create pages with a passthrough template.
authorVladimír Vondruš <mosra@centrum.cz>
Fri, 12 Oct 2018 19:36:16 +0000 (21:36 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Fri, 12 Oct 2018 19:36:16 +0000 (21:36 +0200)
I.e., without any header navbar or footer.

doc/pelican/theme.rst
pelican-theme/templates/passthrough.html [new file with mode: 0644]
pelican-theme/test/page_passthrough/input/page.html [new file with mode: 0644]
pelican-theme/test/page_passthrough/page.html [new file with mode: 0644]
pelican-theme/test/test_page.py

index 478757b0664f16ac1be40a5782c3f43acaadde1b..f9c2bf9d05e6a6305c74c34fcb7e5a1d954c7b94 100644 (file)
@@ -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:`<link rel="prev">` and
 :html:`<link rel="next">` 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 <reStructuredText>`
+sources, this is best combined with raw HTML input. Pelican will copy the
+contents of the :html:`<body>` tag verbatim and use contents of the
+:html:`<title>` 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</title>
+      <meta name="template" content="passthrough" />
+      <meta name="css" content="
+        m-dark.css
+        https://fonts.googleapis.com/css?family=Source+Code+Pro:400,400i,600%7CSource+Sans+Pro:400,400i,600,600i
+        " />
+      <meta name="js" content="webgl-demo.js" />
+    </head>
+    <body>
+    <!-- the actual page body -->
+    </body>
+    </html>
+
 `Theme properties`_
 ===================
 
diff --git a/pelican-theme/templates/passthrough.html b/pelican-theme/templates/passthrough.html
new file mode 100644 (file)
index 0000000..d06be23
--- /dev/null
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html lang="en"{% if page.class %} class="{{ page.class }}"{% endif %}>
+<head>
+  <meta charset="UTF-8" />
+  <title>{{ page.title }}</title>
+  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+  {% if page.css %}
+  {% set styles = page.css.strip().split('\n') %}
+  {% for style in styles %}
+  <link rel="stylesheet" href="{{ style.strip()|expand_link(page)|e }}" />
+  {% endfor %}
+  {% endif %}
+  {% if page.js %}
+  {% set scripts = page.js.strip().split('\n') %}
+  {% for script in scripts %}
+  <script src="{{ script.strip()|expand_link(page)|e }}"></script>
+  {% endfor %}
+  {% endif %}
+  {% if page.html_header %}
+  {{ page.html_header.strip()|indent(2) }}
+  {% endif %}
+</head>
+<body>
+{{- page.content -}}
+</body>
+</html>
diff --git a/pelican-theme/test/page_passthrough/input/page.html b/pelican-theme/test/page_passthrough/input/page.html
new file mode 100644 (file)
index 0000000..2f1dede
--- /dev/null
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <title>WebGL Demo Page</title>
+  <meta name="template" content="passthrough" />
+  <meta name="css" content="
+    a.css
+    b.css
+    " />
+  <meta name="js" content="webgl-demo.js
+    b.js" />
+  <meta name="class" content="a-html-class" />
+  <meta name="html_header" content="
+&lt;!-- extra HTML header content
+     another line --&gt;
+&lt;!-- escaping is annoying --&gt;
+" />
+</head>
+<body>
+<!-- the actual page body -->
+</body>
+</html>
diff --git a/pelican-theme/test/page_passthrough/page.html b/pelican-theme/test/page_passthrough/page.html
new file mode 100644 (file)
index 0000000..7c97eb7
--- /dev/null
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html lang="en" class="a-html-class">
+<head>
+  <meta charset="UTF-8" />
+  <title>WebGL Demo Page</title>
+  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+  <link rel="stylesheet" href="a.css" />
+  <link rel="stylesheet" href="b.css" />
+  <script src="webgl-demo.js"></script>
+  <script src="b.js"></script>
+  <!-- extra HTML header content
+       another line -->
+  <!-- escaping is annoying -->
+</head>
+<body>
+<!-- the actual page body -->
+</body>
+</html>
index 3666cd63e5854c7f7d8cf703e971ad90892a627d..ceb0d281e9ffc39375d828eb6d4114b8286d5bd6 100644 (file)
@@ -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'))