Generate and Deploy a Static Website with Hugo + GitHub Actions[NOT FINISHED]¶
Objectives¶
Prerequisites¶
The following prerequisites must be filled to run this service:
- Docker must be installed.
- Docker Compose must be installed (it should be installed by default with Docker in most cases).
- Visual Studio Code must be installed.
- Dev containers must be installed in Visual Studio Code.
Steps¶
Initiate the project¶
- Create a new repository on GitHub.
- Clone the repository on your computer.
- Open the repository in Visual Studio Code.
Initiate the dev container¶
- Add devcontainer configuration files by clicking on the bottom left corner of Visual Studio Code and selecting "Remote-Containers: Add Development Container Configuration Files...".
- Select "Go" in the list of available containers.
- Select the latest version of Go (1.21 at the time of this commit) in the list of available versions.
- Select "Hugo" in the list of available features.
- Select "Keep Defaults" in the next prompt.
- Add Visual Studio Code Extensions to the
devcontainer.json
by clicking on the extensions tab on the left.- Search for "GitHub Actions", click on the gear icon (⚙️) and select "Add to devcontainer.json".
- Search for "
tamasfe.even-better-toml
", click on the gear icon (⚙️) and select "Add to devcontainer.json". - Search for "
davidanson.vscode-markdownlint
", click on the gear icon (⚙️) and select "Add to devcontainer.json". - (Optional) Search for "GitHub Copilot", click on the gear icon (⚙️) and select "Add to devcontainer.json".
- Remove unnecessary comments from the
devcontainer.json
file.
Your devcontainer.json
file should look like this:
Add this attribute at the end of the devcontainer.json
file so you can use Git in the container:
- Open the command palette in Visual Studio Code by pressing
Ctrl+Shift+P
orCmd+Shift+P
. - Select "Remote-Containers: Reopen in Container".
Your folder should look like that:
Initiate the Hugo project¶
Create a new Hugo project by running the following command in the terminal of Visual Studio Code:
Your root folder should look like that:
If you try to run the Hugo server, running the following command in the terminal of Visual Studio Code:
You will get the following message, when you try to access the website at http://localhost:1313
:
Hugo is telling you that you don't have any content in your website and that you need a theme.
Add a theme¶
You are going to use the Ananke theme for this project.
From your project's root directory, initiate the hugo module system:
Info
Replace <your-username>
and <your-repository-name>
with your GitHub username and the name of your repository.
Example
Add the theme's repository to your project's config.toml
file:
Your config.toml
file should look like this:
Start the Hugo server¶
Run the following command in the terminal of Visual Studio Code:
The output should look like this:
You can now access your website at http://localhost:1313
. You should see a main page with a big title and a footer not at the bottom of the page.
There lacks a few things to make this website look good.
Add content¶
As the Ananke theme is a blog theme, you need to add some content to your website.
Create the first post of your blog
content/posts/my-first-post.md | |
---|---|
If your server is still running, you should see your post at http://localhost:1313/
. The footer is at the bottom of the page, like it should be.
Add a second post¶
You can use Hugo to create a new post:
As you can see, Hugo created a new post in the content/posts
folder. That should look like this:
content/posts/my-second-post.md | |
---|---|
- The date is set to the current date. You can change it to the date you want.
Hugo used the archetypes/default.md
file to create the new post. You can change the default content of the post by changing the content of this file.
archetypes/default.md | |
---|---|
If your server is still running, you should see qonly one post at http://localhost:1313/
. That's because the second post is a draft. You can see it by adding the --buildDrafts
flag to the hugo server
command:
You can now see both posts at http://localhost:1313/
.
Add a menu¶
You can add a menu to your website by adding the following code to your config.toml
file: