I've Been Using The AsciiDoc Intellij Plugin For a Month. Here's My Review.
I’ve been reviewing the AsciiDoc plugin for IntelliJ over the last four weeks. In this post, I share everything that I learned.
Whenever you create online documentation, eventually, the structure needs to change; such as a name change, content restructure, or old content is removed. When these times come, it’s important to create redirects to avoid breaking user expectations. In this post, I’m going to step you through how to do so with Antora.
Speaking from experience, creating redirects in Antora is quite trivial, as it only involves two steps:
--redirect-facility
option when building your documentation.Antora supports creating redirects for all content available in a generated site.
It does so by using the page-aliases
page-level attribute.
This AsciiDoc attribute contains a comma-separated list of page references that redirect to the current page.
Page references follow Antora’s Xref format.
They can link to pages:
Let’s say that you have a page in the current module, named upgrade/service/apache.adoc
, and it was moved to a new directory, upgrade/server
, for whatever reason.
To redirect requests from the original location to the new location, at the top of upgrade/server/apache.adoc
, add a page-aliases
attribute with a link to the original location, as in the following example:
= Page Title
:page-aliases: upgrade/service/apache.adoc
Now let’s say that you want to redirect upgrade/service/apache.adoc
in the current module to the same location in a new module, called webservers
.
To do that, you prefix the path with the module name, separated by a colon, as in the following example:
= Page Title
:page-aliases: webservers:upgrade/service/apache.adoc
Finally, let’s say that you want to redirect upgrade/service/apache.adoc
in the current module to the same location in the webservers
module, but in a different component, called sysadmin
.
To do that, you prefix the path with the module name, separated by a colon, and prefix the module with the component, separated by a colon, as in the following example:
= Page Title
:page-aliases: sysadmin:webservers:upgrade/service/apache.adoc
For a more in-depth discussion on Antora’s Xref syntax, please refer to the relevant Antora documentation.
--redirect-facility
Option When Building Your DocumentationNow that at least one of the pages of source content uses the page-aliases
attribute, you need to tell Antora to generate redirects when it builds your documentation.
To do this, you need to use the --redirect-facility
option, as in the example below.
antora --redirect-facility nginx playbook.yml
This option supports four options; these are: static, netlify, nginx, and disabled.
static
is the default.
When used, Antora generates static bounce pages for each page that is to redirected from.
Each page will contain:
Here is an example of the generated static configuration.
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="canonical" href="http://localhost:5000/upgrade/server/apache.html">
<script>location="marketplace_apps.html"</script>
<meta http-equiv="refresh" content="0; url=../server/apache.html">
<meta name="robots" content="noindex">
<title>Redirect Notice</title>
<h1>Redirect Notice</h1>
<p>
The page you requested has been relocated to
<a href="../server/.html">http://localhost:5000/server/apache.html</a>.
</p>
When netlify
is used, Antora generates a Netlify _redirects file, called _redirects
, in the Playbook’s output directory, which contains the generated rewrite configuration.
Here is an example of the generated Netlify configuration.
/upgrade/service/apache.html /upgrade/server/apache.html 301
The first item is the path to match. The second item is path to redirect to, when a match is encountered. The third value is the HTTP code to redirect with.
Once the _redirects
file is generated, no further changes are required in your build server.
When present, Netlify will make use of the file and start handling the required redirects.
Honestly, I couldn’t imagine a simpler setup.
When nginx
is used, Antora generates an NGINX rewrite configuration in a file called rewrite.conf
, in a new directory called .etc/nginx
, which is itself created inside the Playbook’s output directory.
Here is an example of the generated NGINX configuration.
location = /upgrade/service/apache.html {
return 301 /upgrade/server/apache.html;
}
The top line specifies the path to match The line inside the curly braces tells NGINX the HTTP status code to send and where to redirect to, if the path is matched in a request.
Note: After Antora generates the file, don’t forget to update your build server configuration to ensure that NGINX makes use of the generated rewrite.conf
.
When disabled
is used, no redirects are generated.
Be careful not to create circular redirects when using this attribute. I encountered this recently, and it resulted in Antora failing to build.
Secondly, you cannot create redirects to pages that already exist (naturally). If you attempt to do so, you will see the following error when you run antora:
Error: Page alias cannot reference an existing page
And that’s how to create redirects in Antora, when the structure of your technical documentation changes. Like almost everything in Antora, it only requires a text change and a re-run of Antora. I’d go into greater depth, but I don’t see anything else worth saying.
If you’ve been wondering how to create redirects in Antora, this short tutorial will set you on the right path. If you’re not yet using Antora, I’d love to hear how your technical documentation platform implements redirects. Please share your input in the comments.
If you’re keen to learn more about Antora, check out the Antora docs. And if you’re just getting started using Antora, make sure to get involved in the online community.
I’ve been reviewing the AsciiDoc plugin for IntelliJ over the last four weeks. In this post, I share everything that I learned.
The Asciidoctor.js Live Preview extension allows custom AsciiDoc attributes to be set using file query strings. In this post, I show you how to do so, along with how to use it in tandem with the extension’s configuration UI.
In this post, I step through how to set custom AsciiDoc attributes in the Asciidoctor.js Live Preview Extension for Firefox (and Chromium/Chrome). By doing so, you can preview your content properly and avoid setting attributes directly in your AsciiDoc content and other hacks.
If you need to create and maintain technical writing, there are a large number of solutions that will give you a lot of what you want. However, which one is the best? Today, I’ll show you which one I believe is the best choice.
Please consider buying me a coffee. It really helps me to keep producing new tutorials.
Join the discussion
comments powered by Disqus