by specifying the corresponding menu item slug in the :rst:`:highlight:` field.
If the field is not present, page's own slug is used instead.
-`Extra CSS`_
-------------
+`Extending HTML \<head\>`_
+--------------------------
The :rst:`:css:` field can be used to link additional CSS files in page header.
-Put one URL per line, internal link targets are expanded. Example:
+Put one URL per line, internal link targets are expanded. Similarly :rst:`:js:`
+can be used to link JavaScript files. Besides that, the :rst:`:html_header:`
+field can be used to put arbitrary HTML at the end of the :html:`<head>`
+element. Indenting the lines is possible by putting an escaped space in front
+(the backslash and the escaped space itself won't get inserted). Example:
.. code:: rst
:css:
{filename}/static/webgl.css
{filename}/static/canvas-controls.css
+ :js:
+ {filename}/static/showcase.js
+ :html_header:
+ <script>
+ \ function handleDrop(event) {
+ \ event.preventDefault();
+ \ ...
+ \ }
+ </script>
`Breadcrumb navigation`_
------------------------
{% block social %}
{% endblock social %}
{% endif %}
+ {% block extra %}
+ {% endblock extra %}
</head>
<body>
<header><nav id="navigation"{% if page and page.landing and page.cover %} class="m-navbar-landing"{% elif (page and page.cover) or (article and article.cover) %} class="m-navbar-cover"{% endif %}>
<meta property="og:type" content="page" />
{% endblock %}
+{% block extra %}
+ {% if page.js %}
+ {% set scripts = page.js.strip().split('\n') %}
+ {% for script in scripts %}
+ <script src="{{ script|expand_link(page)|e }}"></script>
+ {% endfor %}
+ {% endif %}
+ {% if page.html_header %}
+ {{ page.html_header|indent(2) }}
+ {% endif %}
+{% endblock %}
+
{% block main %}
{% if not page.landing %}
{% if page.cover %}
+++ /dev/null
-A page
-######
-
-:css: static/m-debug.css
- static/m-grid.css
<link rel="stylesheet" href="static/m-grid.css" />
<link rel="canonical" href="page.html" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <script src="a.js"></script>
+ <script src="b.js"></script>
+ <!-- this goes into the HTML head
+ another line -->
+ <!-- have to indent them with a backslash -->
</head>
<body>
<header><nav id="navigation">
--- /dev/null
+A page
+######
+
+:css:
+ static/m-debug.css
+ static/m-grid.css
+:js:
+ a.js
+ b.js
+:html_header:
+ <!-- this goes into the HTML head
+ \ another line -->
+ <!-- have to indent them with a backslash -->
self.assertEqual(*self.actual_expected_contents('page.html'))
self.assertEqual(*self.actual_expected_contents('subpage.html'))
-class ExtraCss(PageTestCase):
+class ExtraHtmlHead(PageTestCase):
def __init__(self, *args, **kwargs):
- super().__init__(__file__, 'extra_css', *args, **kwargs)
+ super().__init__(__file__, 'extra_html_head', *args, **kwargs)
def test(self):
self.run_pelican({})
- # The page should contain two extra CSS links
+ # The page should contain two extra CSS links, two JS references and a
+ # multi-line HTML comment
self.assertEqual(*self.actual_expected_contents('page.html'))
class HeaderFooter(PageTestCase):