Building a Personal Blog with Hugo (1)
Hugo is a static website generator written in Go. Its features are as follows:
- Simple, easy to use, efficient, easy to extend, and quick to deploy.
- Hugo can be hosted with GitHub Pages.
Steps
1. Install Hugo
Download the binary or archive for your platform from Hugo Releases. The installation methods are as follows.
General
- Unpack and install the tar.gz archive:
1 2 3tar -zxvf <your-platform>.tar.gz -C /usr/local/bin \ && cd /usr/local/bin \ && rm LICENSE README.md
- Unpack and install the tar.gz archive:
Debian-based
Install the .deb file (recommended):
1dpkg -i <your-platform>.debUninstalling is also easy; whether you need to keep the configuration files depends on your needs (
it seems hugo doesn’t have a config file anyway XD).1 2 3dpkg -l # List installed packages and find hugo's package name. dpkg -r package-name # Remove the package but keep the configuration files. dpkg -P package-name # Remove the package and the configuration files.Install via APT (not recommended by the official docs because the version is older):
1apt install hugo
Other systems: Refer to the official Installation Docs
Run the following command; if version information is printed, the installation was successful.
| |
2. Generate the Site
| |
3. Install a Theme
This demo uses Hugo PaperMod. The installation guide is here, and we’ll go with Method 1 :
- Just run the command in the site’s root directory:
1git clone https://github.com/adityatelange/hugo-PaperMod themes/PaperMod --depth=1 - To update the theme:
1 2cd themes/PaperMod git pull
4. Create a New Post
Create an about page:
| |
about.md is automatically generated at content/about.md. Open about.md and take a look:
| |
The content is in Markdown format, and the content between the --- lines is in YAML format. Depending on your preference, you can switch to TOML format (using +++ delimiters) or JSON format. I personally recommend YAML.
Create your first post and put it in the post directory, so that aggregate pages can be generated later.
| |
You can now edit the content of first.md using Markdown syntax.
5. Run Hugo and Go Live
Run the following in the site’s root directory:
| |
The command above is the default way to start. --buildDrafts controls whether draft posts are displayed. By default, only the local machine is allowed to access the server; if you want others to access it via IP, use the following command:
| |
-b http://ip:8080: because static resources default to localhost when other people access the site, this flag points to your own IP address and default port.-p 8080: the default port is 1313; this specifies port 8080.--bind "0.0.0.0": the default startup only allows access from the local machine, so you need to bind it so that all machines can access the site.
Official command documentation: Commands