Development of the govuk-tech-docs-sphinx-theme
¶
This theme was designed to complement govcookiecutter
to provide a
standardised GOV.UK Tech Docs-style theme that leverages the power
of Sphinx, a Python document generator. This enables users to build and
deploy documentation as a searchable website, whether that is locally on their machine
or elsewhere, such as on GitHub Pages.
The theme was developed by taking a build of the GOV.UK Tech Docs template, splitting it out into an acceptable Sphinx layout. Sphinx blocks were then applied to the appropriate areas of the HTML code. By default, the template CSS and JavaScript files supersede the inbuilt Sphinx ones, aside from a few cases (e.g. search).
If you discover any bugs, and/or discrepancies, please raise a GitHub issue on our repository (check out our contributing guidelines, and code of conduct first).
If you also want to contribute to the solution, please do raise a pull request too! The following sections will hopefully assist with fixing any bugs. Consider reading the Sphinx documentation on templating, and documentation on using Jinja templating. For new or existing GOV.UK Design System components, read the Sphinx extension development documentation.
Comparing with GOV.UK Tech Docs template¶
The theme was built by from a specific version of the GOV.UK Tech Docs template, and amending all HTML files to use relative paths for all assets (CSS, JavaScript, images, etc.).
This repository contains an automated way to get the latest version of the template, and amend the paths on a Unix-based machine:
Install the requirements for the GOV.UK Tech Docs template, but stop before creating a new project
Open your terminal at the root of this repository, and run the
build_alphagov_tech_docs_template.sh
shell scriptsh build_alphagov_tech_docs_template.sh
This builds the latest version of the template in the untracked folder
source/alphagov-tech-docs-template/build
.
Fixing missing attributes and classes with jQuery¶
If you notice missing attributes and/or classes in the HTML, use jQuery to inject these
attributes or classes at the correct location. Changes should be made in
src/govuk_tech_docs_sphinx_theme/static/javascripts/theme.js
.
For example, to prevent Sphinx autosummary from using a 10%:90% split for summary
tables, the style
attribute of all col
tags are set to have a 50% width by this
code:
$(function() {
$('table.longtable > colgroup').find('col').each(function() {
$(this).css('width', '50%');
});
});
The 'table.longtable > colgroup'
line ensures only table
tags with a longtable
class with a nested colgroup
tag are used to find nested col
tags.
Fixing missing styles with CSS¶
As Sphinx blocks were injected directly into the built GOV.UK Tech Docs template, Sphinx will sometimes inject more HTML tags and classes. This can then break any styles that a conditional, say on the order of tags and/or classes.
If you identify a situation where this occurs, find out what the affected style should
look like. Open
src/govuk_tech_docs_sphinx_theme/static/stylesheets/manifest.css
, and find the
incorrectly applied style. Identify the problem, then copy the relevant styles from
mainfest.css
to src/govuk_tech_docs_sphinx_theme/static/stylesheets/theme.css
,
making the relevant changes to apply the style to the theme.
For example, page titles have a specific format in the GOV.UK Tech Docs template.
However, they rely on a tag having a technical-documentation
class, with a nested
h1
tag (or a tag with a govuk-heading-xl
class) in manifest.css
.
.technical-documentation > h1, .govuk-heading-xl {
color: #0b0c0c;
font-family: "GDS Transport", Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-weight: 700;
font-size: 32px;
font-size: 2rem;
line-height: 1.09375;
display: block;
margin-top: 0;
margin-bottom: 30px; }
However, Sphinx injects a section
before the first heading (page title), so the above
CSS is amended in theme.css
to:
.technical-documentation > section > h1, .govuk-heading-xl {
color: #0b0c0c;
font-family: "GDS Transport", Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-weight: 700;
font-size: 32px;
font-size: 2rem;
line-height: 1.09375;
display: block;
margin-top: 0;
margin-bottom: 30px; }
Other relevant, and amended page title CSS also exist in theme.css
exist, but have
not been reproduced here for brevity.
GOV.UK Design System components¶
Some, but not all, GOV.UK Design System components have been included in this theme. To
add additional ones, read the Sphinx documentation on extensions,
and take a look at the existing ones in the
src/govuk_tech_docs_sphinx_theme/components
folder.
Note new components must be added as directives in the setup
function of
src/govuk_tech_docs_sphinx_theme/__init__.py
.