Hugo: Difference between revisions
m Categories |
m Category Go added |
||
(4 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:Applications]] | ||
[[Category:Server]] | [[Category:Server]] | ||
[[Category:Go]] |