[Docker] Build a site on Hugo and publish it on GitHub

Overview

I will summarize the procedure for building a Hugo site on Docker and publishing it on GitHub.

Premise

--Basic knowledge of Git --I have a GitHub account --Basic knowledge of Docker --Terminal is available

environment

The working folder name is "Docker Hugo". For docker-compose.yml for starting Hugo's virtual environment, see [Docker] Building an environment for using Hugo.

DockerHugo
├── docker-compose.yml

Overall picture

The figure below shows the flow performed locally with the container. スクリーンショット 2020-09-17 23.33.56.png

Create a new Hugo site

Enter the following command in the container

container


hugo new site hoge

A hoge folder is created in the root folder (here, the "Docker Hugo" folder). The contents of the hoge folder are as follows

hoge
├── archetypes
│   └── default.md
├── config.toml
├── content
├── data
├── layouts
├── static
└── themes

6 directories, 2 files

Download the theme you want to use

Many templates are provided by hugo. Find the template you want to use at themes.gohugo.io Reference: Hugo theme ranking site

Here, select Learn. Click [Demo] to see the sites that use the theme. スクリーンショット 2020-09-16 22.29.24.png

Click [Download] to display the github page. Copy the link provided in [Code] image.png

Start the terminal of the local PC and execute the following in the "DockerHugo" folder

Local PC


git init
git submodule add https://github.com/matcornic/hugo-theme-learn.git hoge/themes/learn

The contents of themes / learn folder are as follows

learn
├── CHANGELOG.md
├── LICENSE.md
├── README.md
├── archetypes
│   └── default.md
├── data
│   └── webpack_assets.json
├── exampleSite
│   ├── config.toml
│   ├── content
│   │   ├── _index.md
│   │   ├── about
│   │   │   └── _index.md
│   │   ├── contact.md
│   │   └── post
│   │       ├── _index.md
│   │       ├── chapter-1.md
・
・
・

26 directories, 101 files

You can confirm that the files necessary for configuring the site such as html and css have been downloaded.

Added to config.toml

Run the following in the hoge folder on your local PC's terminal

Local PC


echo 'theme = "learn"' >> config.toml

Added to the config.toml file

config.toml


baseURL = "http://example.org/"
languageCode = "en-us"
title = "My New Hugo Site"
theme = "learn"

Add content file

When you run the hugo new command, the content files are stored below content / specified folder name / file name

Run the following in the hoge folder of the container's terminal

container


hugo new posts/my-first-post.md

If you check the created file, the following items are added

my-first-post.md


---
title: "My First Post"
date: 2020-09-16T13:53:14Z
draft: true 
---

The default is "draft: true" and drafts are not built ("hugo" command). Be sure to set "draft: false" if you want to build

Since this file is a file that describes the contents of the Web file, add it as follows

#title
Try to create a hoge site

Start Hugo server

Start the Hugo server to check in your browser before building

Do the following in the hugo folder of the container's terminal

container


hugo server -D

If you add "-D", draft is also displayed.

Check the created website

Open http: // localhost: 1313 / in your browser スクリーンショット 2020-09-16 23.06.41.png

Page customization will be described in a separate article

Modify the config.toml file

The overall configuration of the site is done in the config.toml file. Changed as follows

config.toml


baseURL = "" #Not required if the relative path is set to true
languageCode = "ja" #Not necessary as it does not support multiple languages,"ja"Change to
title = "My New Hugo Site" 
theme = "learn"
publishDir = "../docs"  #File storage stored when the hugo command is executed
relativeURLs = true #Change to save as relative path (default is absolute path (relativeURLs)=false))

See Configure Hugo for parameter details.

Supplementary explanation about the reason for changing to publishDir =" docs "

This time, we will publish the website on GitHub Pages. In Github Pages, you can only specify the [(roots)] or [docs] folder as the folder that stores the files that build the web page. So I changed it to publishDir =" ../ docs " By default, the "public" folder is specified.

The following image is the setting screen of GitHub Pages スクリーンショット_2020-09-17_22_53_47.png

Supplementary explanation about the reason for setting relativeURLs =" true "

By changing from an absolute path to a relative path, it is now possible to handle folders even when moving.

Build static site

Execute the following in the "Docker Hugo" folder (root folder) of the container

container


hugo

Since I wrote "publishDir =" docs "" in config.toml, html and css files were generated in the docs folder.

docs $ tree
.
├── 404.html
├── categories
│   ├── index.html
│   └── index.xml
├── css
│   ├── atom-one-dark-reasonable.css
│   ├── auto-complete.css
│   ├── featherlight.min.css
・
・
・

8 directories, 82 files

Published on GitHub Pages

Publish to GitHub Pages using the git command or SourceTree See the article below for details ・ [Terminal] How to manage git / github -[SourceTree] Local / Remote Repository Management

reference

Hugo quick start page

Recommended Posts

[Docker] Build a site on Hugo and publish it on GitHub
Build Metabase with Docker on Lightsail and make it https with nginx
Create a Docker Image for redoc-cli and register it on Docker Hub
Enable Docker build cache on GitHub Action and deploy to Amazon ECS
Build a DHCP and NAT router on Ubuntu 16.04
I installed Docker on EC2 and started it
Easily build Redmine on Windows using WSL2 and Docker
Install Ubuntu 20.04 in virtual box on windows10 and build a development environment using docker
Until you build a Nuxt.js development environment with Docker and touch it with VS Code
Create a Java (Gradle) project with VS Code and develop it on a Docker container
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (5)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (6)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (3)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (2)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (1)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (4)
Create a Java (Maven) project with VS Code and develop it on a Docker container
Build a Node-RED environment with Docker to move and understand
Create a flyway jar with maven and docker build (migrate) with docker-maven-plugin
(Ruby on Rails6) Creating a database and displaying it in a view
Use Jenkins to build inside Docker and then create a Docker image.
Build a Node.js environment with Docker
Run React on a Docker container
Build a Minecraft server on AWS
Build Clang x VSCode on Docker (1)
Build a XAMPP environment on Ubuntu
Run PureScript on a Docker container
Build Unity development environment on docker
Let's install Docker on Windows 10 and create a verification environment for CentOS 8!
Make a daily build of the TOPPERS kernel with Gitlab and Docker
How to build a Ruby on Rails environment using Docker (for Docker beginners)
Starting with installing Docker on EC2 and running Yellowfin in a container
A shell script that builds a Docker image and pushes it to ECR
[Copy and paste] Build a Laravel development environment with Docker Compose Part 2
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
[Copy and paste] Build a Laravel development environment with Docker Compose Participation
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
Install docker and docker-compose on Alpine Linux
Create a container image for arm64 of Kibana and register it in GitHub Container Registry. Start Elastic Stack with Docker Compose on Raspberry Pi 4 (64bit)
Build a PureScript development environment with Docker
Build a WAS execution environment from Docker
Build a Maven repository on AWS S3
Build a Java development environment on Mac
Build a Wordpress development environment with Docker
Publish JAR on Gradle on GitHub Package Registry
Build Redmine code reading environment on Docker
Build an environment with Docker on AWS
Build a JMeter environment on your Mac
Build by specifying docker as a file
Build an Ultra96v2 development environment on Docker 1
Build a simple Docker + Django development environment
Build a Doker-based development environment on Windows 10 Home 2020 ver. Part 1 Until WSL2-based Docker build
Test, build, and push your Docker image to GitHub Container Registry using GitHub Actions
Build a development environment to create Ruby on Jets + React apps with Docker
Notes on creating a many-to-many Factory with Rspec and testing it with SystemSpec [RSpec, FactoryBot]
How to build a Jenkins server with a Docker container on CentOS 7 of VirtualBox and access the Jenkins server from a local PC
left4dead2 I made a Docker image for the server and tried running it on GCE # 3 (I had a hard time building the server)