Hugo API site

I’ve created about 10 different Hugo sites. So far it’s my favorite static site generator. The build speed is less than a minute for every site that I’ve deployed. However, the setup process for Hugo sites isn’t very clear for me. I wish I had clear instructions on how to add a theme and publish it online. Lots of Hugo themes are available at JAMstack Themes.

In this example, let’s build the API documentation site using the DocuAPI theme for Hugo static site generator. This Hugo theme is based on Slate. The end result will look similar to this site:

https://docuapi-test.netlify.app

Prerequisites

  1. Check that you have Hugo installed: hugo version.

    If you don’t have Hugo installed on your computer, read How to install Hugo on Windows.

  2. Check that you have Git client installed: git version.

    If you don’t have Git client installed on your computer, read how to install Git client.

  3. Check that you have:


Download the theme

To download the API documentation theme:

  1. Go to the theme GitHub repository.

    img

  2. Download the zipped project folder.

    img

  3. Unzip the project folder.


Create Hugo project

To set up a new Hugo project on your computer:

  1. In the Command Prompt, enter: hugo new site docuapi where docuapi is the name of the Hugo project you want to create.

    img

  2. Copy the downloaded theme folder to the theme folder of your Hugo project.

    In my case, I copy the docuapi-master folder to c:\Users\ivanc\docuapi\themes\.

    img

  3. Rename the copied folder from docuapi-master to docuapi. This is the theme name.

    img

  4. Open the exampleSite folder in c:\Users\ivanc\docuapi\themes\docuapi\exampleSite\.

  5. Copy everything in the exampleSite folder in c:\Users\ivanc\docuapi\themes\docuapi\exampleSite\ to the root of the project folder in c:\Users\ivanc\docuapi\. Replace the existing folders and files when asked.

    img


Build site locally

Before publishing the site online, let’s see how it looks locally.

To build your Hugo site locally:

  1. In the command prompt, change the folder path to your Hugo folder: cd docuapi. Press Enter.

  2. Enter hugo server. Press Enter.

    Your site is built and served on the local server.

  3. Copy the server address //localhost:1313/ and paste it in your browser.

    img

    You should see this site in your browser.

    img


Publish site online

You will use Netlify to deploy and host your Hugo API documentation site online. To publish your site online, you need to edit the configuration files and upload the project folder to GitHub first.

Edit the configuration file

To edit the Hugo site configuration file:

  1. Open the docuapi folder in VSCode.

  2. Select the config.toml file.

    img

  3. Edit the config.toml file.

    theme = "docuapi"
    # themesdir = "../.."
    languageCode = "en-us"
    baseurl = "/"
    title = "DocuAPI Example Site"
    

    The config should look like this.

    img


Edit the Netlify configuration file

You need to edit the Netlify configuration file for correct deploy to the Netlify service.

To edit the Netlify config:

  1. In VSCode, select the netlify.toml file. In my case, it’s located in c:\Users\ivanc\docuapi\themes\docuapi\.

    img

  2. Edit the file.

    [context.production.environment]
    HUGO_VERSION = "0.78.1"
    
  3. Change the value for HUGO_VERSION to your Hugo version.

    The edited netlify.toml file should look like this.

    img

  4. Move the netlify.toml file from the theme folder c:\Users\ivanc\docuapi\themes\docuapi\ to the project root folder c:\Users\ivanc\docuapi\.

Upload project folder to GitHub

To upload the project folder to GitHub:

  1. In VSCode, open the project folder.

  2. Select the Source Control icon.

    img

  3. Select Publish to GitHub.

  4. Select Publish to GitHub public repository.

    When the project folder has been uploaded to the GitHub repository, you will see the success message.

  5. Select Open in GitHub to view your project folder uploaded and synced to the GitHub repository.

    img


Publish with Netlify

To publish your site online:

  1. Log in to Netlify.

  2. Select New site from Git.

    img

  3. Select GitHub.

  4. Select your docuapi repository.

    img

  5. In the Build Command field, enter hugo.

  6. In the Publish directory field, enter public.

  7. Select Deploy site.

    img

    Wait until Netlify deploys your site with some funny name. You should see the green Published message.

  8. To change the site name, select Site settings.

    img

  9. Select Change site name and enter the available name. In my case, it’s docuapi-test.

    img

    Your site should be available now. You can view my test API documentation site here:

    https://docuapi-test.netlify.app/


Last modified March 9, 2023: first commit (98b8333)