Getting Started With AsciiDoc Using Antora
A popular Static Site Generator (SSG) that supports the use of AsciiDoc syntax is Antora. Static Site Generators are tools that generate a full static HTML website based on raw data and a set of templates and Antora is one that has been designed specifically around the needs of technical writers and their goal; which is to create technical documentation.
Antora is developed around the AsciiDoc syntax or format that is somewhat similar to the Markdown syntax. It also runs on Asciidoctor, a processor that parses and converts AsciiDoc source documents into various formats such as HTML5, PDF, DocBook etc. It provides technical writers with a structured and defined way of organizing technical content.
It is important to note that the developers of Asciidoctor are also the maintainers of Antora, this gives room for proper integration between the two technologies.
To use Antora to generate a document, you need to assemble your files into a standard project structure, and then store them in a git repository. Once that is done, Antora picks your file and transforms it into a website.
Now you will take a look at how to Install Antora.
Installation, Setup and Configuration
Before installing Antora locally on your computer, it is important to take a look at the Supported Platforms and System Requirements. This is to ensure your development device is supported by the system.
Installing Node.js and Chocolatey for Windows
After checking for system requirements, you need to ensure you have Node.js installed on your computer. To check if you do, open the PowerShell and type:
You should see something like the image below ;
Fig 1. An Image of the PowerShell showing the node version installed
Pin 1 shows the command used to check if Node.js is installed.
Pin 2 shows the version of Node.js installed.
If you are presented with an error in your PowerShell after running the command, that would mean you do not have Node.js installed.
The best way to install to install Node.js is by Chocolatey, a package manager for Windows. Open the PowerShell and run as an Administrator by right-clicking the PowerShell icon and selecting Run as Administrator.
Then run the following command;
Fig 2: A screenshot of the PowerShell showing the installation of Chocolatey
Once the command is complete, you can now install node.js
You can install Node.js with Chocolatey by running the following command in the PowerShell;
Fig 3: A screenshot of the PowerShell showing the installation of Node.js
Installing Antora
In this section, you will look at how to install Antora.
Prerequisite: You must have Node.js installed
To be able to use Antora to generate a documentation site, you are going to need the Antora command line interface (CLI) and the Antora site generator.
The first thing to do when trying to install Antora is to create a new directory for your documentation site, and then move into that directory. You can do this in your PowerShell. Let us call this directory test-site
The next step is to initialize the package.json file and install the necessary CLI package in the project so you can run Antora using Node Package Execute ( npx: a npm package runner that executes any package from the npm registry without having to install it ).
Warning: In case you run into an error running the Antora installation script in the PowerShell of your Windows machine, refer to this article on Execution Policies to fix the issue.
Verify Antora has been installed by running the command below;
If the installation is successful, the version of Antora CLI and the site generator specified will be printed onto the PowerShell.
Fig 4: A screenshot of the PowerShell that shows the various processes discussed above
From the Screenshot above, you can see the visual representation of the installation process of Antora in the PowerShell. The processes are pinned and explained below:
Pin 1: creation of the test-site directory
Pin 2: moving into the directory
Pin 3: Initializing the package.json file and other packages
Pin 4: Installing Antora
Pin 5: Verifying Antora, the version installed and the site generator
Creating a Playbook with IDE (Visual Studio Code)
To create a documentation site, Antora needs a playbook. you will look at how to do that in this section. Follow the following steps
Step 1: Using your preferred IDE, create a new file
Step 2: Add the following configuration information to the file and save it as antora-playbook.yml:
Fig 5: A screenshot of an IDE showing the antora-playbook.yml file
This configuration file will create a site using the Antora demo repositories.
Step 3: In the terminal, navigate to the test-site directory
Step 4: Run the following command :
This command lets Antora clone the content, UI repository and generate your documentation site to the default output directory.
Fig 6: A screenshot from the terminal showing that the generation of the documentation site is complete
Navigate to the test-site/build/site/index.html directory. Open the index.html file in your browser to view your generated documentation site.
Fig 7: A screenshot of the generated Antora documentation site.
Congratulations, you just created your first documentation site with Antora.
Testing your Documentation Site and Publishing with Antora
To be able to publish and test your documentation site, you should do the following:
- In your already created folder, clone the content of this Github repository into it.
- Once you have the repo cloned, now you can work locally on your pc.
- Change into the antora directory and then initialize the json package and install antora by running the following commands;
- Now generate your site by running the following command;
Now your site should be generated and ready to be viewed. Copy the displayed URL, and paste it into your browser to view your generated site.
To test for AsciiDoc syntax, navigate to the displayed folder below;
- antora/
- docs/
- modules/
- module_one/
- pages/
- gettingstarted.adoc
- installation.adoc
- overview.adoc
- pages/
- module_one/
- modules/
- docs/
- antora/
In the gettingstarted.adoc, installation.adoc and overview.adoc files, copy and paste your AsciiDoc syntax into any of the files, then generate the site again by running the “npx antora antora-playboook.yml” command again.
Go to your browser, and refresh to see your AsciiDoc syntax displayed.
NOTE: For any change you make with syntax in your vs code, always generate the site again by running the “npx antora antora-playbook.yml” command.
- Create a GitHub repository of your own, and push changes you have made to this repo you created.
- Once you have pushed to Github, configure the Github pages for your repo, and set Build and Deployment source to Github Actions.
- Use the Git Action workflow below to deploy your Antora page to GitHub pages.
Be sure to have enabled Github pages in your repo by creating a gh-pages branch
Simple workflow to deploy static content to Github Pages
- Make edits to your documentation file.
- Commit changes and push them to your repository.
- Your content will be live once changes have been to the repository.