Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 62 additions & 54 deletions _learn/03-hugo-go-netlify.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ You can also set up Docker and then use this [Docker image](https://hub.docker.c

```
$ hugo version
Hugo Static Site Generator v0.74.3/extended darwin/amd64 BuildDate: unknown
hugo v0.135.0+extended darwin/amd64 BuildDate=2024-09-27T13:17:08Z VendorInfo=brew
```

## Starting a Hugo site

For a Hugo static site, you can choose your specific theme after you create the source files. The theme we'll use in this tutorial is [hugo-theme-learn](https://themes.gohugo.io/hugo-theme-learn/). To start a new site in the current folder, run:
For a Hugo static site, you can choose your specific theme after you create the source files. The theme we'll use in this tutorial is [hugo-theme-relearn](https://themes.gohugo.io/themes/hugo-theme-relearn/). To start a new site in the current folder, run:

```
$ hugo new site docs-as-code
Expand All @@ -48,95 +48,103 @@ For a Hugo static site, you can choose your specific theme after you create the
1. Take a look at the files created in the directory with an `ls` command:
```
$ ls -A
archetypes content layouts themes
config.toml data static
archetypes content hugo.toml layouts themes
assets data i18n static
```

1. Initialize the current directory as a Git repository, which will enable you to bring the theme in as a Git submodule.
```
$ git init
Initialized empty Git repository in /Users/annegentle/src/src/hugo-example/.git/
Initialized empty Git repository in /Users/agentle/src/hugo-example/.git/
```

1. Edit `config.toml` in any text editor you like to get started. Choose a title for your site and the theme, in our case, `hugo-theme-learn`. The theme name in your configuration file must match the name of the specific theme directory inside the `/themes` directory, so we will add those files in the next step.
1. Edit `hugo.toml` in any text editor you like to get started. Choose a title for your site and the theme, in our case, `hugo-theme-relearn`. (Find the [installation documentation for the Relearn Theme here](https://mcshelby.github.io/hugo-theme-relearn/basics/installation/index.html).) The theme name in your configuration file must match the name of the specific theme directory inside the `/themes` directory, so we will add those files in the next step.
```
baseURL = "http://example.org/"
languageCode = "en-us"
title = "Learning Hugo Site"
theme = "hugo-theme-learn"
[module]
[[module.imports]]
path = 'github.com/McShelby/hugo-theme-relearn'
```
1. To get the theme files in the `/themes` directory, and keep them updated, use a `git submodules` command to get the required theme files as well as keep them updated.
```
$ git submodule add https://github.com/matcornic/hugo-theme-learn.git themes/hugo-theme-learn
$ hugo mod init example.com
```
The terminal returns something like this:
```
go: creating new go.mod: module example.com
go: to add module requirements and sums:
go mod tidy
```
Next, add the theme as a Git submodule with this command:
```
$ git submodule add --depth 1 https://github.com/McShelby/hugo-theme-relearn.git themes/hugo-theme-relearn
```
1. For Hugo, the `content` folder contains the site source content. For your home page, make an `_index.md` document in the `content` folder and write it with Markdown content. Switch back up one level since you just cloned the theme files.
```
$ cd ..
$ hugo new _index.md
$ hugo new --kind home _index.md
Content "/Users/agentle/src/hugo-example/hugo-example/content/_index.md" created
```
1. Next, add a new page using the `hugo` command, `hugo new`:
1. Next, add a new chapter page using the `hugo` command, `hugo new`:
```
$ hugo new prerequisites.md
/Users/agentle/src/hugo-example/doc-machine/content/prerequisites.md created
$ hugo new --kind chapter get-started/_index.md
/Users/agentle/src/hugo-example/content/get-started/_index.md created
```
1. You can keep adding files with the `hugo new` command so that the Markdown files are pre-populated with the front matter:
1. You can keep adding files with the `hugo new` command so that the Markdown files are pre-populated with the front matter such as:
```
---
title: "Prerequisites"
date: 2018-06-16T10:38:19-05:00
draft: true
---
+++
archetype = "chapter"
title = "Get Started"
weight = 1
+++
```

## Build a Hugo site locally

Once you've prepared your local system, you can build locally and review the site in your browser.

For Hugo, it's important to know that draft pages are only served when using the `-D` parameter.
For Hugo, it's important to know that draft pages, where `draft = true` is in the front matter, won't be served.

1. Run the `hugo server` command with the `-D` parameter (to serve draft pages).
1. Run the `hugo server` (or `hugo serve`) command to run a local server with your draft website.

```
$ hugo server -D

| EN
+------------------+----+
Pages | 12
Paginator pages | 0
Non-page files | 0
Static files | 67
Processed images | 0
Aliases | 0
Sitemaps | 1
Cleaned | 0

Total in 48 ms
Watching for changes in /Users/agentle/src/hugo-example/doc-machine/{content,data,layouts,static,themes}
Watching for config changes in /Users/agentle/src/hugo-example/doc-machine/config.toml
Serving pages from memory
Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Press Ctrl+C to stop
$ hugo server

Watching for changes in /Users/agentle/src/hugo-learn/{archetypes,assets,content,data,i18n,layouts,static,themes}
Watching for config changes in /Users/agentle/src/hugo-learn/hugo.toml, /Users/agentle/src/hugo-learn/themes/hugo-theme-relearn/hugo.toml, /Users/agentle/src/hugo-learn/go.mod
Start building sites …
hugo v0.135.0+extended darwin/amd64 BuildDate=2024-09-27T13:17:08Z VendorInfo=brew

WARN deprecated: .Sites.First was deprecated in Hugo v0.127.0 and will be removed in a future release. Use .Sites.Default instead.
WARN deprecated: .Site.IsMultiLingual was deprecated in Hugo v0.124.0 and will be removed in a future release. Use hugo.IsMultilingual instead.

| EN
-------------------+------
Pages | 11
Paginator pages | 0
Non-page files | 0
Static files | 182
Processed images | 0
Aliases | 0
Cleaned | 0

Built in 276 ms
Environment: "development"
Serving pages from disk
Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Press Ctrl+C to stop
```
2. Open the **Web Server** URL, `http://localhost:1313/` in your local browser to view the site. (By default, the theme may be purple instead of green.)
2. Open the **Web Server** URL, `http://localhost:1313/` in your local browser to view the site.
![Example Hugo site](/images/learn/hugo-docs-page.png)
3. Press `Ctrl+C` in the server terminal to stop the Hugo server.
4. You can add your files to a Git commit. Refer to [Working with content in GitHub repositories](https://docslikecode.com/learn/04-add-content-workflow/) for a documentation workflow with your Hugo site.

## Modify the Hugo theme

By default, the Hugo Theme "Learn" has a purple sidebar. How about changing the color and logo displayed in the sidebar? Here's how. While we're at it, let's make sure to configure the search tool that works best with this theme.

1. Edit the `config.toml` file and add these lines to the `config.toml` file. This example shows setting the `themeVariant` to `green`.
```
[params]
themeVariant = "green"
```
1. You can make sure that the theme works with the `lunr.js` [JavaScript search engine](https://lunrjs.com/) by adding these lines to the `config.toml` file.
```
[outputs]
home = [ "HTML", "RSS", "JSON"]
```
The Hugo Theme "Relearn" has many ways to [customize the theme](https://mcshelby.github.io/hugo-theme-relearn/basics/customization/index.html), including activating print support and a dedicated search page. Refer to the [Relearn theme documentation](https://mcshelby.github.io/hugo-theme-relearn/) for details.

## What's next

Expand All @@ -152,5 +160,5 @@ home = [ "HTML", "RSS", "JSON"]

## Additional references

* [Hugo Quickstart](https://gohugo.io/getting-started/quick-start/)
* [Hugo Quick start](https://gohugo.io/getting-started/quick-start/)
* [Hugo Themes web site](https://themes.gohugo.io/)
Binary file modified images/learn/hugo-docs-page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.