Static Site Generator
1 Week - Complete Guide
Static site generator tercepat di dunia - buat website dalam hitungan detik
# Download
wget https://github.com/gohugoio/hugo/releases/download/v0.123.0/hugo_extended_0.123.0_linux-amd64.tar.gz
# Extract
tar -zxf hugo_extended_*.tar.gz
# Install
sudo install hugo /usr/local/bin/
# Verify
hugo version
brew install hugo
# Via Chocolatey
choco install hugo -extended
# Via Scoop
scoop install hugo
# Buat site baru
hugo new site mysite
# Masuk ke folder
cd mysite
# Struktur folder
mysite/
├── archetypes/
├── content/
├── data/
├── layouts/
├── static/
├── public/ # Output build
├── config.toml # Konfigurasi
# Development server
hugo server
# Dengan draft
hugo server -D
# Specific port
hugo server -p 1313
# Buat halaman
hugo new about.md
# Buat post
hugo new posts/my-first-post.md
# Buat dengan folder
hugo new posts/2024/hello-world.md
---
title: "My First Post"
date: 2024-01-15
draft: false
author: "John Doe"
tags: ["hugo", "static-site"]
categories: ["Tech"]
---
# Konten di bawah ini
# Heading 1
## Heading 2
### Heading 3
**Bold** or __Bold__
*Italic* or _Italic_
~~Strikethrough~~
> Blockquote
- Item 1
- Item 2
- Nested
1. First
2. Second
[Link text](https://example.com)

Inline `code`
```
Code block
multiple lines
```
baseURL = 'https://example.com/'
languageCode = 'en-us'
title = 'My Hugo Site'
theme = ['theme-name']
[params]
description = "My awesome site"
author = "John Doe"
baseURL: https://example.com/
languageCode: en-us
title: My Hugo Site
theme:
- theme-name
params:
description: My awesome site
{
"baseURL": "https://example.com/",
"title": "My Hugo Site",
"params": {
"description": "My awesome site"
}
}
{{ define "main" }}
<h1>{{ .Title }}</h1>
<p>{{ .Date.Format "2006-01-02" }}</p>
{{ .Content }}
{{ end }}
{{ define "main" }}
<h1>{{ .Title }}</h1>
{{ range .Pages }}
<h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
<p>{{ .Summary }}</p>
{{ end }}
{{ end }}
{{ define "main" }}
<header>
<h1>{{ .Site.Title }}</h1>
<p>{{ .Site.Params.description }}</p>
</header>
<main>
{{ range first 5 (where .Site.RegularPages "Type" "in" .Site.Params.mainSections) }}
<article>
<h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
<p>{{ .Summary }}</p>
</article>
{{ end }}
</main>
{{ end }}
{{/* layouts/shortcodes/youtube.html */}}
<div class="video-wrapper">
<iframe src="https://www.youtube.com/embed/{{ .Get "id" }}"
frameborder="0" allowfullscreen></iframe>
</div>
{{ youtube id="dQw4w9WgXcQ" }}
{{/* Dengan inner content */}}
{{/* layouts/shortcodes/note.html */}}
<div class="note">{{ .Inner }}</div>
{{* note */}}
Ini adalah catatan penting!
{{/* /note */}}
{{/* layouts/partials/header.html */}}
<header>
<nav>
<a href="/">Home</a>
{{ range .Site.Menus.main }}
<a href="{{ .URL }}">{{ .Name }}</a>
{{ end }}
</nav>
</header>
{{ partial "header.html" . }}
{{/* Dengan parameter */}}
{{ partial "head.html" (dict "title" .Title "css" "style.css") }}
[taxonomies]
tag = "tags"
category = "categories"
series = "series"
---
title: "My Post"
tags: ["hugo", "web"]
categories: ["Tech"]
---
{{ range .Site.Taxonomies.tags }}
<a href="{{ .Page.RelPermalink }}">{{ .Page.Title }}</a>
{{ end }}
[menu]
[[menu.main]]
name = "Home"
url = "/"
weight = 1
[[menu.main]]
name = "Blog"
url = "/posts/"
weight = 2
[[menu.main]]
name = "About"
url = "/about/"
weight = 3
---
title: "About"
menu:
main:
weight: 10
---
{{ range .Site.Menus.main }}
<a href="{{ .URL }}" class="{{ if $.IsMenuCurrent "main" . }}active{{ end }}">
{{ .Name }}
</a>
{{ end }}
# Browse themes
https://themes.gohugo.io/
# Via git submodule (recommended)
git init
git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke
# Clone
git clone --depth 1 https://github.com/budparr/gohugo-theme-ananke.git themes/ananke
theme = "ananke"
# Atau dengan submodules
theme = ["ananke", "other-theme"]
# assets/css/main.scss
$primary: #FF3933;
body {
font-family: sans-serif;
color: $primary;
}
{{ $style := resources.Get "css/main.scss" | toCSS | minify }}
<link rel="stylesheet" href="{{ $style.RelPermalink }}">
{{ $js := resources.Get "js/main.js" | minify | fingerprint }}
<script src="{{ $js.RelPermalink }}"></script>
{{ $img := resources.Get "images/photo.jpg" }}
{{ $resized := $img.Resize "400x" }}
<img src="{{ $resized.RelPermalink }}">
[languages]
[languages.en]
languageName = "English"
weight = 1
title = "My Site"
[languages.id]
languageName = "Bahasa Indonesia"
weight = 2
title = "Situs Saya"
[languages.fr]
languageName = "Francais"
weight = 3
content/
├── posts/
│ ├── hello.en.md
│ ├── hello.id.md
│ └── hello.fr.md
{{ range .Site.Languages }}
<a href="{{ $.RelPermalink | relLangURL }}">{{ .LanguageName }}</a>
{{ end }}
[outputs]
home = ["HTML", "RSS"]
{{- $.Scratch.Add " feed" (printf "%s %s" .Title .RSSLink ) -}}
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{{ .Title }}</title>
<link>{{ .Permalink }}</link>
{{ range first 10 .Pages }}
<item>
<title>{{ .Title }}</title>
<link>{{ .Permalink }}</link>
<pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}</pubDate>
</item>
{{ end }}
</channel>
</rss>
<link rel="alternate" type="application/rss+xml"
title="{{ .Site.Title }}" href="{{ .RSSLink }}">
# Build ke folder public
hugo
# Build dengan environment
hugo --environment production
# .github/workflows/hugo.yaml
name: Deploy Hugo
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
- name: Build
run: hugo --minify
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
| Masalah | Solusi |
|---|---|
| Template error | Cek: hugo --verbose |
| Page not found | Cek front matter & URL |
| Theme not working | Update theme submodule |
| Build failed | Cek config & dependencies |
# Verbose output
hugo --verbose
# Drafts included
hugo -D
# Cek semua pages
hugo --printPathWarnings
# List taxonomies
hugo --printUnusedTemplates
Next Steps
1. Practice: buat site dengan Hugo
2. Eksplorasi themes di themes.gohugo.io
3. Deploy ke GitHub Pages/Netlify
4. Build portfolio atau blog
Apa itu Hugo?
Command apa untuk start Hugo server?
Di mana content Hugo disimpan?