Hugo: Difference between revisions
Imported from the old wiki. (Except off-topic parts) |
m Category Go added |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
''' | <languages/> | ||
<translate> | |||
<!--T:1--> | |||
'''Hugo''' is a static site generator written in Go. It builds websites from content files and templates, supporting features such as Markdown content, themes, and flexible deployment options. Hugo is available in the NixOS ecosystem and can be used for a variety of web publishing tasks.<ref>https://gohugo.io/documentation/</ref> | |||
</translate> | |||
== Installation == | |||
==== Shell ==== | |||
<translate> | |||
]; | <!--T:2--> | ||
To temporarily use Hugo in a shell environment, you can run: | |||
</ | </translate> | ||
{{ | <syntaxhighlight lang="bash"> | ||
nix-shell -p hugo | |||
</syntaxhighlight> | |||
<translate> | |||
<!--T:3--> | |||
This will provide a shell with Hugo available without adding it to your system configuration. | |||
</translate> | |||
==== System setup ==== | |||
<translate> | |||
<!--T:4--> | |||
To install Hugo, add it to either the system-wide <code>environment.systemPackages</code> in <code>/etc/nixos/configuration.nix</code> or to the user-specific <code>home.packages</code> in <code>~/.config/nixpkgs/home.nix</code>.<ref>https://nixos.org/manual/nixos/stable/</ref> | |||
</translate> | |||
<syntaxhighlight lang="nix"> | |||
# System-wide installation (in /etc/nixos/configuration.nix) | |||
environment.systemPackages = with pkgs; [ | |||
hugo | |||
git # Useful for managing Hugo themes and site repositories | |||
]; | |||
# User-specific installation (in ~/.config/nixpkgs/home.nix) | |||
home.packages = with pkgs; [ | |||
hugo | |||
git | |||
]; | |||
</syntaxhighlight> | |||
<translate> | |||
<!--T:5--> | |||
Then, rebuild your system or apply your Home Manager configuration: | |||
</translate> | |||
<syntaxhighlight lang="bash"> | |||
# For system-wide installation | |||
sudo nixos-rebuild switch | |||
# For Home Manager | |||
home-manager switch | |||
</syntaxhighlight> | |||
== Configuration == | |||
==== Basic ==== | |||
<translate> | |||
<!--T:8--> | |||
Basic Hugo configuration involves creating a new site and choosing themes. Use the following command to create a new Hugo site: | |||
</translate> | |||
<syntaxhighlight lang="bash"> | |||
hugo new site my-site | |||
</syntaxhighlight> | |||
<translate> | |||
<!--T:12--> | |||
Navigate to the site directory and add a theme as a git submodule or download it directly. For detailed steps, refer to the official Hugo documentation. | |||
</translate> | |||
==== Advanced ==== | |||
<translate> | |||
<!--T:9--> | |||
{{Expansion|reason=Section incomplete, needs detailed content on advanced configuration with NixOS}} | |||
</translate> | |||
== Tips and tricks == | |||
=== Development Shell === | <translate> | ||
=== Development Shell === <!--T:devshell--> | |||
You may | <!--T:13--> | ||
You may want to limit Hugo installation to your project only. This allows contributors to use the exact dependencies specified for the project: | |||
{{file|shell.nix|nix|<nowiki> | {{file|shell.nix|nix|<nowiki> | ||
{ pkgs ? import <nixpkgs> {} }: | { pkgs ? import <nixpkgs> {} }: | ||
Line 27: | Line 96: | ||
</nowiki>}} | </nowiki>}} | ||
To avoid | <!--T:14--> | ||
To avoid typing <code>nix-shell</code> or <code>nix develop</code> to access the dev shell, consider [[Direnv|enabling nix-direnv]]. | |||
</translate> | |||
=== Theming === | <translate> | ||
=== Theming === <!--T:theming--> | |||
<!--T:15--> | |||
Nix can be used to deterministically import Hugo themes by pinning them to a specific revision: | |||
{{file|shell.nix|nix|<nowiki> | {{file|shell.nix|nix|<nowiki> | ||
{ pkgs ? import <nixpkgs> {} }: let | { pkgs ? import <nixpkgs> {} }: let | ||
Line 47: | Line 119: | ||
# Other dependencies for your project. | # Other dependencies for your project. | ||
]; | ]; | ||
shellHook = '' | shellHook = '' | ||
mkdir -p themes | mkdir -p themes | ||
Line 55: | Line 126: | ||
</nowiki>}} | </nowiki>}} | ||
<!--T:16--> | |||
After creating a <code>hugo.toml</code> file like the following, activate the theme with <code>hugo new site . --force</code>: | |||
{{file|hugo.toml|toml|<nowiki> | {{file|hugo.toml|toml|<nowiki> | ||
baseURL = 'https://example.com/' | baseURL = 'https://example.com/' | ||
Line 63: | Line 134: | ||
theme = 'm10c' | theme = 'm10c' | ||
</nowiki>}} | </nowiki>}} | ||
</translate> | |||
== Troubleshooting == | |||
<translate> | |||
<!--T:11--> | |||
{{Expansion|reason=Section incomplete, needs detailed troubleshooting steps}} | |||
</translate> | |||
== References == | |||
[[Category:Applications]] | |||
[[Category:Server]] | |||
[[Category:Go]] |
Latest revision as of 20:31, 25 June 2025
Hugo is a static site generator written in Go. It builds websites from content files and templates, supporting features such as Markdown content, themes, and flexible deployment options. Hugo is available in the NixOS ecosystem and can be used for a variety of web publishing tasks.[1]
Installation
Shell
To temporarily use Hugo in a shell environment, you can run:
nix-shell -p hugo
This will provide a shell with Hugo available without adding it to your system configuration.
System setup
To install Hugo, add it to either the system-wide environment.systemPackages
in /etc/nixos/configuration.nix
or to the user-specific home.packages
in ~/.config/nixpkgs/home.nix
.[2]
# System-wide installation (in /etc/nixos/configuration.nix)
environment.systemPackages = with pkgs; [
hugo
git # Useful for managing Hugo themes and site repositories
];
# User-specific installation (in ~/.config/nixpkgs/home.nix)
home.packages = with pkgs; [
hugo
git
];
Then, rebuild your system or apply your Home Manager configuration:
# For system-wide installation
sudo nixos-rebuild switch
# For Home Manager
home-manager switch
Configuration
Basic
Basic Hugo configuration involves creating a new site and choosing themes. Use the following command to create a new Hugo site:
hugo new site my-site
Navigate to the site directory and add a theme as a git submodule or download it directly. For detailed steps, refer to the official Hugo documentation.
Advanced
Tips and tricks
Development Shell
You may want to limit Hugo installation to your project only. This allows contributors to use the exact dependencies specified for the project:
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShellNoCC {
packages = [
pkgs.hugo
# Other dependencies for your project.
];
}
To avoid typing nix-shell
or nix develop
to access the dev shell, consider enabling nix-direnv.
Theming
Nix can be used to deterministically import Hugo themes by pinning them to a specific revision:
{ pkgs ? import <nixpkgs> {} }: let
hugo-theme = pkgs.fetchFromGitHub {
owner = "vaga";
repo = "hugo-theme-m10c";
rev = "862c6e941be9bc46ce8adc6a2fa9e984ba647d6f";
hash = "sha256-wcJSGjL/u43hPLblPmUhusqiMmadVBWJhihRinRXqzg=";
};
in
pkgs.mkShellNoCC {
packages = [
pkgs.hugo
# Other dependencies for your project.
];
shellHook = ''
mkdir -p themes
ln -snf "${hugo-theme}" themes/m10c
'';
}
After creating a hugo.toml
file like the following, activate the theme with hugo new site . --force
:
baseURL = 'https://example.com/'
languageCode = 'en-us'
title = 'example-site'
theme = 'm10c'