This project is used to develop and distribute the UI for the Red Hat documentation site. The UI bundle this project produces is intended to be used with Antora. The UI bundle contains the HTML templates (layouts, partials, and helpers), CSS, JavaScript, fonts, and (site-wide) images. As such, it provides both the visual theme and user interactions for the documentation site. The rest of the material for the documentation site comes from the content repositories.
You can view a preview of this UI online at cb-docs-ui.netlify.app.
The theme is based on github.com/redhat/docs-ui.
To use this UI with Antora, add the following configuration to your playbook file:
ui:
bundle:
url: https://github.com/aireilly/redhat-antora-ui/releases/download/prod-163/ui-bundle.zip
Read on to learn how to develop the UI.
This section offers a basic tutorial to learn how to set up the UI project, preview it locally, and bundle it for use with Antora.
To preview and bundle the UI, you need the following software on your computer:
First, make sure you have git installed.
$ git --version
If not, download and install the git package for your system.
Next, make sure that you have Node 10 installed.
$ node -v
If this command fails with an error, you don’t have Node installed. If the command doesn’t report a Node 10 version (e.g., v10.15.3), then you don’t have a suitable version of Node installed.
While you can install Node from the official packages, we strongly recommend that you use nvm (Node Version Manager) to install and manage Node. Follow the nvm installation instructions to set up nvm on your machine.
Once you’ve installed nvm, open a new terminal and install Node 10 using the following command:
$ nvm install 10
You can switch to this version of Node at any time using the following command:
$ nvm use 10
To make Node 10 the default in new terminals, type:
$ nvm alias default 10
Now that you have Node 10 installed, you can proceed with installing the Gulp CLI.
You’ll need the Gulp command-line interface (CLI) to run the build.
This package provides the gulp
command which, in turn, executes the version of Gulp declared by the project.
You should install the Gulp CLI globally (which resolves to a location in your user directory if you’re using nvm) using the following command:
$ npm install -g gulp-cli
If you prefer to install global packages using Yarn, run this command instead:
$ yarn global add gulp-cli
Verify the Gulp CLI is installed and on your PATH by running:
$ gulp -v
Now that you have the prerequisites installed, you can fetch and build the UI project.
Clone the UI project using git:
$ git clone https://github.com/aireilly/redhat-antora-ui && cd "`basename $_`"
The example above clones the Red Hat docs UI project and then switches to the project folder on your filesystem. Stay in this project folder when executing all subsequent commands.
Use npm to install the project’s dependencies inside the project. In your terminal, execute the following command:
$ npm install
This command installs the dependencies listed in package.json into the node_modules/ folder inside the project. This folder does not get included in the UI bundle and should not be committed to the source control repository.
In order for the pro Font Awesome icons to work, you must first add the following file to the root folder of the UI project:
@fortawesome:registry=https://npm.fontawesome.com/ //npm.fontawesome.com/:_authToken=${FONTAWESOME_NPM_AUTH_TOKEN}
Then pass the token to npm when running the npm install
command:
FONTAWESOME_NPM_AUTH_TOKEN=xxxx npm install
If you don’t supply this token when installing packages, the pro icons will not be installed, but the UI preview will still work. Any icon available in the free collection will still be found, but the pro icons will be missing. When an icon is missing, a missing icon is shown instead.
The UI project is configured to preview offline. The files in the preview-src/ folder provide the sample content that allow you to see the UI in action. In this folder, you’ll primarily find pages written in AsciiDoc. These pages provide a representative sample and kitchen sink of content from the real site.
To build the UI and preview it in a local web server, run the preview
command:
$ gulp preview
You’ll see a URL listed in the output of this command:
[17:32:55] Starting 'preview:serve'... [17:32:55] Starting server... [17:32:55] Server started http://localhost:5252 and http://192.168.1.3:5252 [17:32:55] Running server
Navigate to this URL to preview the site locally.
While this command is running, any changes you make to the source files will be instantly reflected in the browser.
This works by monitoring the project for changes, running the build
task if a change is detected, and sending the updates to the browser.
Press Ctrl+C to stop the preview server and end the continuous build.
You can share a preview of the UI online by submitting a pull request to GitHub. The repository is configured to create a deploy preview on Netlify for every pull request. Here’s how that process works:
-
Fork the repository on GitHub (only has to be done once).
-
Create a local branch.
-
Make changes to the UI.
-
Commit your changes to that branch.
-
Push that branch to your fork (on GitHub).
-
Submit a pull request from the branch you pushed to your fork.
-
Wait for deploy/netlify check to say “Deploy preview ready” on the pull request page.
-
Click on the “Details” link under “Show all checks” on the pull request page.
-
View your changes in the deploy preview or share the URL with others.
The deploy preview works because there is a webhook on the repository that pings https://api.netlify.com/hooks/github for the following events: push, pull_request, delete_branch. Netlify then runs the command specified in netlify.toml, deploys the site, and allocates a temporary URL for it.
If you need to package the UI so you can use it to generate the documentation site locally, run the following command:
$ gulp bundle
If any errors are reported by lint, you’ll need to fix them.
When the command completes successfully, the UI bundle will be available at build/ui-bundle.zip.
You can point Antora at this bundle using the --ui-bundle-url
command-line option (e.g., --ui-bundle-url=../docs-ui/build/ui-bundle.zip
).
To control the visual appearance of pages, the UI bundle provides a CSS stylesheet (for changing the CSS style rules) and any number of layouts in the form of Handlebars templates (for changing the HTML). Although most styles are used on all pages, it’s possible to configure styles to target certain pages either based on the layout or page role. This section will introduce these various options and explain how they work.
The most drastic way to change the appearance of the page is to change the HTML. The HTML is controlled by layouts, which are Handlebars templates located in src/layouts. A layout typically includes partials, located in src/partials, which are reusable template fragments. Partials may, in turn, include other partials.
This project currently has three layouts:
-
default.hbs
-
404.hbs
-
home.hbs
If a page doesn’t specify a layout, the default.hbs layout is used.
To specify a layout, the page file must declare the page-layout
document attribute in the AsciiDoc header.
The value of that attribute should match the stem of the layout file (the filename minus the file extension, e.g., home
).
For example, the home page declares the following document attribute in the AsciiDoc header:
= Welcome to the Red Hat Docs!
:page-layout: home
In this case, Antora will select the home.hbs layout for this page instead of default.hbs. Using a dedicated layout affords a lot of control over what gets displayed on this page. Every layout has access to the same UI model.
The home page likely requires additional styles that are only relevant for that page.
You can organize these styles inside a namespace by adding a dedicated class to the <body>
tag.
In fact, that’s what the home.hbs layout currently does.
<body class="home">
...
</body>
You can now define styles that are scoped to that page as follows:
.home h1,
.home h2,
.home h3 {
line-height: 1.2;
margin: 0;
}
To make these styles easier to find and manage, they should be organized in a dedicated file src/css/home.css and included into the master src/css/site.css file, which is how this project is currently configured.
When you run the preview, you can see the home page by visiting the URL http://localhost:5252/home.html.
The 404.hbs layout is similar to other layouts, except Antora selects it automatically to make the 404 page (404.html).
For this page, the page
variable in the UI model is reduced to page.layout
and page.title
.
None of the other data in the page
variable is applicable for this page.
When you run the preview, you can see the 404 page by visiting the URL http://localhost:5252/404.html.
Creating a new layout is powerful, but incurs a lot of maintenance overhead. If you’re only looking to tweak the visual appearance of the article region of the page, perhaps to support custom UI components, you can instead define a page role.
A page role is a special role that can be assigned per page that’s typically applied directly to the main article. It’s a way to activate CSS that is scoped to a given page or group of pages.
To apply a page role, the AsciiDoc file for the page must declare the page-role
attribute in the AsciiDoc document header.
For example, the Starter Kits page declares the tiles
role as follows:
= Starter Kits
:page-role: tiles
The value of this attribute is added by the src/css/body.hbs template to the class attribute of the .body
element.
<div class="body container{{#if page.attributes.role}} {{page.attributes.role}}{{/if}}">
...
</div>
Therefore, setting the page-role
attribute to tiles
activates any CSS under the .body.tiles
selector.
For example:
.body.tiles .doc {
display: flex;
flex-wrap: wrap;
margin-right: -1.25rem;
}
These and other styles organize the sections of the page into tiles. When you run the preview, you can see the tiles role in action by visiting the URL http://localhost:5252/tiles.html.
You can create as many of these roles as you like simply by adding CSS scoped to the name of a role.
The playbook for the Red Hat documentation includes a tabs block extension. The extension takes care of converting the AsciiDoc for the tabs to HTML. The UI provides the interaction (JavaScript) and styles (CSS) that power these tabs.
You can find the JavaScript for the tabs in the file src/js/05-tabset.js. You can find the styles for the tabs in the file src/css/doc.css. The preview site provides an example of these tabs in the file preview-src/index.adoc. Note that authors should never enter the HTML for tabs directly, but it is entered this way in the preview site to make it easier to work with.
You can create an arbitrary number of pages for the preview site.
To make a page, create a new AsciiDoc file inside the preview-src folder.
You can then access the page in the preview site using the URL pattern http://localhost:5252/<stem>.html, where <stem>
is the stem of the source file (the filename minus the file extension).
These preview pages serve the purpose of testing the page layout and content styling. Each page may declare a layout, role, or both.
The only caveat is that, at the moment, every page provides the same UI model (with a few exceptions). The model is defined in preview-src/ui-model.yml file. The exceptions include the layout, role, title, contents, and, in the case of home.adoc, the component, which get updated dynamically by the build.
For information about what goes in the UI model, refer the Handlebars templates page in the Antora documentation.
This UI provides integration with Algolia search. The Algolia client is configured in the file src/partials/footer-scripts.hbs. You can test the search directly from the preview site by setting the following environment variables in your shell:
-
ALGOLIA_APP_ID
- the application ID that hosts the search index (optional if you’re using docsearch) -
ALGOLIA_API_KEY
- your API key for Algolia -
ALGOLIA_INDEX_NAME
- the name of the index
You can point to any index that is publicly accessible.
This UI provides integration with JIRA feedback.
The JIRA feedback widget is configured in the file src/partials/footer-scripts.hbs.
You can test the feedback widget directly from the preview site by setting the FEEDBACK_BUTTON=true
environment variable in your shell.
The configuration for the widget is currently hardcoded into the partial template.
This section documents the logic used to compute the URL for the View Latest button and the canonical URL.
If the version of the current page does not match the latest version of the component (i.e., product), a banner is displayed to the visitor. If the version is a prerelease, the banner states that you’re viewing a prerelease version. If the version is an older stable release, the banner states that a newer version is available. The banner offers a button named "View Latest" that directs the visitor to the latest version.
The "View Latest" button tries to preserve the current page when switching versions. If the page is no longer available, then the button directs the user to the start page for the component.
The URL for the "View Latest" button is computed by the latest-page-url helper. Here’s the logic that the helper uses:
-
If the current page is found in the latest version, the latest page URL resolves to the URL of that page. For example, the latest page URL for docs.redhat.com/server/6.0/introduction/intro.html resolves to docs.redhat.com/server/6.5/introduction/intro.html (assuming 6.5 is the latest version)
-
If the SUPPORTS_CURRENT_URL=true environment variable is set, the version segment in the URL is replaced with the word "current". For example, the latest page URL for docs.redhat.com/server/6.0/introduction/intro.html resolves to docs.redhat.com/server/current/introduction/intro.html
-
-
If the current page is not found in the latest version, but the page is claimed by an alias, the latest page URL resolves to the URL of the page to which the alias points. For example, the latest page URL for docs.redhat.com/server/5.5/admin/ui-intro.html resolves to docs.redhat.com/server/6.5/manage/management-overview.html (assuming 6.5 is the latest version)
-
If the SUPPORTS_CURRENT_URL=true environment variable is set, the version segment in the URL is replaced with the word "current". For example, the latest page URL for docs.redhat.com/server/5.5/admin/ui-intro.html resolves to docs.redhat.com/server/current/manage/management-overview.html
-
-
If neither the current page or an alias is found in the latest version, the latest page URL resolves to the component start page.
-
If the SUPPORTS_CURRENT_URL=true environment variable is set, the version segment in the URL is replaced with the word "current".
-
If the current page is in the archive site and the latest version is in the production site, then the latest page URL will point to the production site. In this case, the version segment will only be replaced with "current" if the PRIMARY_SITE_SUPPORTS_CURRENT_URL=true environment variable is set.
The canonical URL differs slightly from the URL for the "View Latest" button in that if the page cannot be found in the latest version, it instead resolves to the newest version of the page. The canonical URL can resolve to the current URL (if the current URL is the canonical URL).
The canonical URL is computed by the canonical-url helper. Here’s the logic that the helper uses:
-
If the site.url is not set to an absolute path, no value is returned.
-
If the current page is found in the latest version, the canonical URL resolves to the URL of that page. For example, the canonical URL for docs.redhat.com/server/6.0/introduction/intro.html resolves to docs.redhat.com/server/6.5/introduction/intro.html (assuming 6.5 is the latest version)
-
If the SUPPORTS_CURRENT_URL=true environment variable is set, the version segment in the URL is replaced with the word "current". For example, the canonical URL for docs.redhat.com/server/6.0/introduction/intro.html resolves to docs.redhat.com/server/current/introduction/intro.html
-
-
If the current page is not found in the latest version, but the page is claimed by an alias, the canonical URL resolves to the URL of the page to which the alias points. For example, the canonical URL for docs.redhat.com/server/5.5/admin/ui-intro.html resolves to docs.redhat.com/server/6.5/manage/management-overview.html (assuming 6.5 is the latest version)
-
If the SUPPORTS_CURRENT_URL=true environment variable is set, the version segment in the URL is replaced with the word "current". For example, the canonical URL for docs.redhat.com/server/5.5/admin/ui-intro.html resolves to docs.redhat.com/server/current/manage/management-overview.html
-
-
If neither the current page or an alias is found in the latest version, the current URL resolves to the newest version of the page (which could be the current page). For example, the canonical URL for docs.redhat.com/server/4.0/architecture/cluster-ram-quotas.html resolves to docs.redhat.com/server/4.1/architecture/cluster-ram-quotas.html
-
If the SUPPORTS_CURRENT_URL=true environment variable is set, it has no affect on this case.
-
If the current page is in the archive site and the latest version is in the production site, then the canonical URL will point to the production site. In this case, the version segment will only be replaced with "current" if the PRIMARY_SITE_SUPPORTS_CURRENT_URL=true environment variable is set and the newest version of the page is the latest version of the component.
The software in this repository (build scripts, JavaScript files, Handlebars templates, foundation CSS, utility icons, etc) is part of the Antora project. As such, use of the software is granted under the terms of the Mozilla Public License Version 2.0 (MPL-2.0).
Copyright © Red Hat 2018-2021. All rights reserved.