Template generator details¶
The portion of the content on docs.openstack.org that is not managed
as document sets built by Sphinx is handled via a custom template
rendering tool in tools/www-generator.py within the
openstack-manuals git repository.
The script reads YAML data files in www/project-data to determine
which projects exist in a given series and how they should be
displayed on the list of installation, configuration, and other
guides.
After the script loads the data about the external projects, it scans
www/ for HTML template files. It uses Jinja2
to convert the templates to complete HTML pages, which it writes to the
publish-docs output directory.
See also
The Jinja2 documentation includes a guide for template designers that covers the syntax of templates, inheritance between templates, and the various filters and other features available when writing templates.
The template files¶
The template files in the openstack-manuals repo are all under the
www directory. They are organized in the same structure used to
publish to the site, so the path to a published URL corresponds
directly to a path to the template file that produces it.
Here are a few representative files under www/:
austinindex.html– landing page for $series docs (one per series)
deindex.html– list of guides translated into $LANG
errorpage.htmlmitaka– newer series have more complex page organizations; each directory is uniqueadminindex.html
apiindex.html
deindex.html– landing page for $series docs translated into $LANG
index.htmllanguage-bindings.htmlprojects.htmluserindex.html
pikeadminindex.html
apiindex.html
configurationindex.html
deployindex.html
index.htmlinstallindex.html
language-bindings.htmlprojects.htmluserindex.html
project-data– YAML files with data about projects in each $serieslatest.yamlmitaka.yamlnewton.yamlocata.yamlpike.yamlREADME.rstschema.yaml
redirect-tests.txt– input file for whereto to test.htaccess. To see recent 404 errors check the “Goaccess report” artifact on builds of docs-openstack-goaccess-report in Zuul. To search for recent runs of this job visit the Zuul builds page.static– contains files that are not templates (CSS, JS, sitemap, etc.)templates– contains reused templates (base pages, partial pages, etc.)api_guides.tmplbase.tmplcontributor_guides.tmplcss.tmpldefault.tmpldropdown_languages.tmplfooter.tmplgoogle_analytics.tmplheader.tmplindexbase.tmplnavigation.tmplops_and_admin_guides.tmplproject_guides.tmplscript_footer.tmplscript_search.tmplseries_status.tmplos_search_install.tmplos_search_mobile.tmplos_search.tmpltraining_guides.tmpluser_guides.tmpl
Defining release series¶
The set of release series and their individual status and other
metadata is embedded in the template generator script in the
SERIES_INFO data structure. The structure is a dictionary mapping
the name of the release series to a SeriesInfo structure holding
the metadata.
For each release series, the generator needs to know:
dateThe date value should be a string containing the month name and 4 digit year.
statusThe ‘status’ field should be one of:
obsoletethe release existed, but we have no more artifacts for it
EOLthe release is closed but we have docs for it
maintainedthe release still has an open branch
developmentthe current release being developed
See also
Update www pages for end of release has some additional information about how the status values are updated at the end of a release cycle.
Project data file format¶
The projects associated with each release series are listed in a
separate YAML file in the www/project-data directory. Each file is
named for the series (austin.yaml, bexar.yaml, etc.) except
for the series currently under development which is always kept in
latest.yaml.
The schema for the project data files is defined in
www/project-data/schema.yaml.
Each file should contain an array or list of entries. Each entry must define the name, service, and type properties.
The name should be the base name of a git repository.
The deliverable-name should be the name of the deliverable as
defined in openstack/governance/reference/projects.yaml. This
value only needs to be set if the deliverable name does not match the
project name (such as glance_store and glance-store).
The service string should be taken from the governance repository
definition of the project.
The type must be one of the values listed below:
serviceA REST API service.
cloud-clientA library for talking to a cloud.
service-clientA library for talking to a service.
libraryAnother type of library.
toolA command line tool or other project that is used with, or used to build, OpenStack.
networkingA plugin for the networking service.
baremetalA subproject for the bare metal project, Ironic.
deploymentA tool for deploying OpenStack.
otherA project that does run in a cloud but does not provide a REST API.
An entry can also optionally define service_type, which must match
the value associated with the name in the service-types-authority
repository.
Entries with type set to client should include a description
field with a short description, such as “keystone client”.
Entries may optionally set flags to indicate that the repository includes particular types of documentation in an expected location, to include a link to that documentation on the templated landing pages.
has_install_guideproduces a link to
docs.o.o/{{name}}/latest/install/has_api_guideproduces a link to
developer.o.o/api-guide/{{service_type}}/has_api_refproduces a link to
developer.o.o/api-ref/{{service_type}}/has_config_refproduces a link to
docs.o.o/{{name}}/latest/configuration/has_in_tree_api_docsproduces a link to
docs.o.o/{{name}}/latest/api/has_admin_guideproduces a link to
docs.o.o/{{name}}/latest/admin/has_in_tree_htaccessenables full redirects to old paths, not just to the top of
/{{name}}/latest/has_deployment_guideproduces a link to
docs.o.o/project-deploy-guide/{{name}}/{{series}}/
Note
The documentation associated with the flags must exist before the flags are set.
Template variables¶
The template generator uses the input data to set several variables visible within the template. This allows us to reuse the same template to generate content for multiple pages of the same style, filling in different data.
By convention, all of the variables defined in the template generator use all uppercase names. This makes it easy to differentiate the generator variables from variables defined within templates (such as loop contexts).
TEMPLATE_FILEThe name of the template file being rendered, with the
wwwprefix removed. For example,pike/index.html.PROJECT_DATAAll of the project data loaded from the data files in a dictionary mapping the series name to the parsed data file. Most template pages will assign a local variable using
PROJECT_DATA[SERIES]to extract the correct subset of the data.TOPDIRThe path to the top of the build output (relative path by default and absolute URL with
--publishoption). This is useful for building paths between output pages in a way that allows those pages to move around later.SCRIPTDIRThe path to the location of the JavaScript directory in the build output (relative path by default and absolute URL with
--publishoption). This is useful for building links to JavaScript files.CSSDIRThe path to the location of the directory containing the CSS files in the build output (relative path by default and absolute URL with
--publishoption). This is useful for building links to CSS files.IMAGEDIRThe path to the location of the directory containing image files in the build output (relative path by default and absolute URL with
--publishoption). This is useful for building links to images.SERIESA string containing the name of the series usable in URLs. For the series under development, this is
"latest". For other series, it is the series name in lower case.This value is derived from the path to the template file. If the file is under a directory that matches one of the known series names, that value is used to set
SERIES.SERIES_TITLEA string containing the name of the series usable in text visible to the reader. It is always the actual name of the series in “title case” (the first letter of each word is uppercase). For example,
"Pike".This value is derived from the path to the template file. If the file is under a directory that matches one of the known series names, that value is used to set
SERIES.ALL_SERIESA list of all of the series names for all OpenStack releases, in order of release.
This list is derived from the keys of the
SERIES_INFOdictionary defined in the template generator.PAST_SERIESA list of the series names for OpenStack releases with a status other than
"development".This list is derived from the values in the
SERIES_INFOdictionary defined in the template generator.RELEASED_SERIESA string containing the lowercase name of the most recent series to be released. For example, during the Pike series this value was
"ocata".This value is derived from the values in the
SERIES_INFOdictionary defined in the template generator.SERIES_IN_DEVELOPMENTA string containing the lowercase name of the series under active development. For example, during the Pike series this value was
"pike".This value is derived from the values in the
SERIES_INFOdictionary defined in the template generator.SERIES_INFOThe
SeriesInfoobject associated with the current series. This provides access to thedateandstatusvalues for the series.This value is taken from the
SERIES_INFOdictionary defined in the template generator.REGULAR_REPOSA list of all of the names of regular repositories for official OpenStack projects. Here “regular” differentiates the repositories from infrastructure team repositories, which have their documentation published to a different location and therefore need some different URLs for redirects in the
.htaccesstemplate. SeeINFRA_REPOS.This value is derived from data published from the governance repository.
INFRA_REPOSA list of all of the names of repositories for the infrastructure team. See
REGULAR_REPOS.This value is derived from data published from the governance repository.
Common tasks¶
How would I change a page?¶
Look for the
TEMPLATE_FILEvalue in the page source to find which file produces the page.The source for https://docs.openstack.org/pike/ shows:
<!-- TEMPLATE_FILE: openstack-manuals/www/pike/index.html -->
Modify the file or one of the other templates from which it inherits.
www/pike/index.htmlhas a base template ofwww/templates/indexbase.tmplwhich contains:{% include "templates/series_status.tmpl" %}and that directive pulls in
www/templates/series_status.tmpl.
How would I add a new project?¶
Modify www/project-data/latest.yaml to add the new stanza.
Flags for having various types of docs default to off; only list the ones that should be turned on. Set the type for the project to ensure it shows up in the correct list(s).
How would I add a new flag to the project metadata?¶
Update the schema to allow the flag by changing
www/project-data/schema.yaml.Update the documentation team contributor guide to explain the flag’s use by modifying
doc/doc-contribu-guide/source/doc-tools/template-generator.rst.Update
www/project-data/latest.yamlto set the flag for some project(s).Update/create the template that will use the flag.
How would I add a new page?¶
Copy an existing template file to the new name under www/ and then
modify it.
How does the final release process work?¶
See Release task detail.
Testing the build¶
There are two commands useful for testing the build locally:
$ tox -e publishdocs
and
$ tools/test.sh
The test script supports a few options to make it more effective.
--skip-linksSkip link checks
--series SERIESseries to update/test
--check-all-linksCheck for links with flags set false.
To test template rendering without waiting for link checks:
$ ./tools/test.sh --skip-links
To test project links only for items listed in latest.yaml:
$ ./tools/test.sh --series latest
To produce a list of the unset flags for latest.yaml that could be set (the pages linked do exist):
$ ./tools/test.sh --check-all-links --series latest