February 29, 2024 in antora, guide, doc as code, documentation by Wisdom Nwokocha8 minutes
Antora is a static site generator that transforms AsciiDoc content into documentation sites.
AsciiDoc is a lightweight markup language for creating notes, articles, books, and web pages. Its simplicity allows complex documents using plain text files.
This guide walks you through building a documentation site with Antora and AsciiDoc, including exporting to PDF, HTML, and other formats.
First, make sure you have Node.js installed on your system. Then, follow these steps:
Create a new directory for your documentation project.
Open a terminal and navigate to the project directory.
Run the following command to install Antora:
This command creates a package.json
file and installs the Antora CLI and site generator as development dependencies in your project.
To verify that Antora is installed, run the following command:
If you encounter any issues during the installation, refer to the official installation guide.
Create an Antora playbook file (e.g., antora-playbook.yml
) in your project directory. This file defines the structure of your documentation.
Specify the content sources (e.g., Git repositories, local directories) where your documentation files reside.
Define the UI bundle (e.g., a theme) that Antora will use to generate your site.
Playbook configuration
A playbook is a configuration file that tells Antora where to find the content and UI resources it needs to generate a documentation site.
To create a playbook, follow these steps:
Using your preferred text editor or IDE, create a new file.
Populate the file with the configuration information provided below.
This is the default playbook configuration from Antora.
This playbook file will create a site using the Antora demo repositories.
Save the file as antora-playbook.yml
in the root folder.
In the terminal, navigate to your project directory.
Run the following command to generate your site in the root folder:
This command tells Antora to generate the documentation site in this folder build/site
using your created playbook.
Site generation complete!
Open file:///Users/wisdomnwokocha/Desktop/Doctest/build/site/index.html in a browser to view your site.
Copy the URL and open the index.html
file in your browser to see the result.
To run Antora remotely, use the following command:
Add this flag --fetch
to fetch from a remote repo.
Antora will clone the content and UI repositories and generate your documentation site to the default output directory.
Congratulations!
You’ve successfully built your first site with Antora.
Now that you’ve created a documentation site, it’s time to learn how to create content using AsciiDoc.
To create content in AsciiDoc, you need to understand basic syntax.
Here’s a simple example:
This example demonstrates the basic structure of an AsciiDoc document.
=
character is used to define the document title.==
characters are used to define the section titles.===
characters are used to define the subsection titles.<>
character is used to define the author’s email address.To learn more about the syntax, refer to the AsciiDoctor Quick Syntax Reference.
You can export your AsciiDoc documents to PDF, HTML, and DocBook formats.
An easy way to export your documents is to use the AsciiDoc extension for Visual Studio Code.
AsciiDoc Extension for VSCode To use the AsciiDoc extension for Visual Studio Code, you need to install it from the Visual Studio Code Marketplace.
Make sure the extension you install is published by Asciidoctor.
The extension looks like this:
After installation, ensure the extension is enabled in your Visual Studio Code settings.
Export as PDF To export your AsciiDoc document as a PDF, follow these steps:
Open the command palette using the following command: ctrl+shift+p // On Windows. Alternatively, use F1. cmd+shift+p // On Mac
Select AsciiDoc: Export document as PDF
.
The AsciiDoc extension will prompt you to select the PDF’s desired file name and location.
Save as HTML To generate HTML from your Asciidoc file, follow the steps below:
Open the command palette.
Select AsciiDoc: Save HTML document
.
The file is generated in the same folder as the source document.
To quickly do this, use the shortcut keys below:
Save to DocBook Docbook is another type of markup language used in technical documentation.
To save your AsciiDoc file to Docbook, follow the steps below:
From the command palette.
Select AsciiDoc: Save to DocBook
.
The file is generated in the same folder as the source document.
Only DocBook 5 is supported.
Create a /docs
in the root folder of your project.
Copy the content from the GitHub repository’s docs
folder into your own.
Modify the content as needed.
Work Offline:
Update Your Playbook:
Edit your playbook (antora-playbook.yml
) with the following configurations:
Your URL is pointing to the root folder (.)
Ensure you have enabled your repository’s GitHub Pages by creating a gh-pages branch.
# Simple workflow for deploying static content to GitHub Pages
To Publish Your Changes:
Make Edits: Update your documentation files as needed.
Commit: Commit your changes to Git.
Push to GitHub: Always push your changes to GitHub.
Live Updates: Your updated content will be live once it’s pushed to the repository.
Follow the Same Process as GitHub:
Create an Azure Pages Workflow:
azure-pages.yml
) in your repository.