From 44e8d439aa57973437ea0f9d7ee60b8f55df9dd1 Mon Sep 17 00:00:00 2001 From: Nicolas Dechesne Date: Fri, 3 Jul 2020 17:46:31 +0200 Subject: sphinx: conf: add substitutions/global variables The Yocto Project documentation makes heavy use of 'global' variables. In Docbook these 'variables' are stored in the file poky.ent. This Docbook feature is not handled automatically with Pandoc. Sphinx has builtin support for substitutions however they are local to each reST file by default. They can be made global by using rst_prolog: rst_prolog A string of reStructuredText that will be included at the beginning of every source file that is read. However Sphinx substitution feature has several important limitations. For example, substitution does not work in code-block section. yocto-vars.py is an extension that processes .rst file to find and replace 'variables'. This plugin will do variables substitutions whenever a rst file is read, so it happens before sphinx parses the content. All variables are set in poky.yaml. It's a simple YAML file with pairs of variable/value, and the file is parsed once during setup. It's important to note that variables can reference other variables. poky.yaml was generated by converting poky.ent into a YAML format. To use a variable in the Yocto Project .rst files, make sure it is defined in poky.yaml, and then you can use : &DISTRO_NAME; For external links, Sphinx has a specific extension called extlinks, let's use it instead of variable substituions. Note that we intentionnally did not put the trailing '/' in the URL, this is to allow us to use :yocto_git:`/` trick to get the actual URL displayed in the HTML. (From yocto-docs rev: dc5f53fae8fdfdda04285869dd1419107b920bfe) Signed-off-by: Nicolas Dechesne Signed-off-by: Richard Purdie --- documentation/conf.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'documentation/conf.py') diff --git a/documentation/conf.py b/documentation/conf.py index dd20e44a1a..5519acb87a 100644 --- a/documentation/conf.py +++ b/documentation/conf.py @@ -26,10 +26,15 @@ author = 'The Linux Foundation' # -- General configuration --------------------------------------------------- +# to load local extension from the folder 'sphinx' +sys.path.insert(0, os.path.abspath('sphinx')) + # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ + 'sphinx.ext.extlinks', + 'yocto-vars' ] # Add any paths that contain templates here, relative to this directory. @@ -44,6 +49,26 @@ exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] # set it ourselves. master_doc = 'index' +# create substitution for project configuration variables +rst_prolog = """ +.. |project_name| replace:: %s +.. |copyright| replace:: %s +.. |author| replace:: %s +""" % (project, copyright, author) + +# external links and substitutions +extlinks = { + 'yocto_home': ('https://yoctoproject.org%s', None), + 'yocto_wiki': ('https://wiki.yoctoproject.org%s', None), + 'yocto_dl': ('https://downloads.yoctoproject.org%s', None), + 'yocto_lists': ('https://lists.yoctoproject.org%s', None), + 'yocto_bugs': ('https://bugzilla.yoctoproject.org%s', None), + 'yocto_ab': ('https://autobuilder.yoctoproject.org%s', None), + 'yocto_git': ('https://git.yoctoproject.org%s', None), + 'oe_home': ('https://www.openembedded.org%s', None), + 'oe_lists': ('https://lists.openembedded.org%s', None), +} + # -- Options for HTML output ------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for -- cgit v1.2.3-54-g00ecf