[ADD] support for meta directive (#708)

e.g.

    .. meta::
        :description: blah blah blah
        :keywords lang=en: x y z

should yield

    <meta name="description" content="blah blah blah">
    <meta name="keywords" lang="en" content="x y z">

Also cleaned up `layout.html` a tad while at it:

* we're now properly setting the default metas via the translator so
  setting them in the template is unnecessary
* there's a flag to use an html5 doctype (also has a few other
  positive side-effects with respect to the metas sphinx generates in
  the template)
This commit is contained in:
xmo-odoo 2020-06-25 09:25:00 +02:00 committed by GitHub
parent 7d82513292
commit e43df474d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 13 deletions

View File

@ -1,4 +1,5 @@
{% extends "basic/layout.html" %}
{% set html5_doctype = True %}
{% set classes = [] %}
{% if pagename == master_doc %}
@ -13,15 +14,6 @@
{% set classes = classes + meta['classes'].split() %}
{% endif %}
{%- block doctype -%}
<!doctype html>
{%- endblock -%}
{%- block htmltitle -%}
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
{{ super() }}
{%- endblock -%}
{%- block linktags -%}
{% for code, url in language_codes %}
<link rel="alternate" hreflang="{{ code }}" href="{{ url }}" />

View File

@ -36,10 +36,6 @@ class BootstrapTranslator(nodes.NodeVisitor, object):
html_subtitle = 'html_subtitle'
# <meta> tags
meta = [
'<meta http-equiv="X-UA-Compatible" content="IE=edge">',
'<meta name="viewport" content="width=device-width, initial-scale=1">'
]
def __init__(self, document, builder):
# order of parameter swapped between Sphinx 1.x and 2.x, check if
@ -49,6 +45,11 @@ class BootstrapTranslator(nodes.NodeVisitor, object):
super(BootstrapTranslator, self).__init__(document)
self.builder = builder
self.meta = [
'', '',
'\n <meta http-equiv="X-UA-Compatible" content="IE=edge">',
'\n <meta name="viewport" content="width=device-width, initial-scale=1">'
]
self.body = []
self.fragment = self.body
self.html_body = self.body
@ -78,6 +79,9 @@ class BootstrapTranslator(nodes.NodeVisitor, object):
0xa0: u'&nbsp;'
})
def add_meta(self, meta):
self.meta.append('\n ' + meta)
def starttag(self, node, tagname, **attributes):
tagname = tagname.lower()
@ -134,6 +138,14 @@ class BootstrapTranslator(nodes.NodeVisitor, object):
def depart_document(self, node):
pass
def visit_meta(self, node):
if node.hasattr('lang'):
node['xml:lang'] = node['lang']
meta = self.starttag(node, 'meta', **node.non_default_attributes())
self.add_meta(meta)
def depart_meta(self, node):
pass
def visit_section(self, node):
# close "parent" or preceding section, unless this is the opening of
# the first section