Hugo

github, 下载, 官网

Hugo 是一个用 Go 编写的 静态站点生成器,针对速度进行了优化,并设计为具有灵活性。凭借其先进的模板系统和快速的资产管道,Hugo 可以在几秒钟内(通常更短)呈现完整的站点。

由于其灵活的框架、多语言支持和强大的分类系统,Hugo 被广泛用于创建:

在开发过程中使用 Hugo 的嵌入式 Web 服务器可以立即查看内容、结构、行为和演示的变化。然后将站点部署到您的主机,或将更改推送到您的 Git 提供程序以进行自动构建和部署。

Hugo 的快速资产管道包括:

借助 Hugo 模块,您可以通过公共或私有 Git 存储库与其他项目共享内容、资产、数据、翻译、主题、模板和配置。

安装 Hugo

# 使用 Hugo Extended 版本
#wget https://github.com/gohugoio/hugo/releases/download/v0.127.0/hugo_0.127.0_linux-amd64.tar.gz
wget https://github.com/gohugoio/hugo/releases/download/v0.127.0/hugo_extended_0.127.0_Linux-64bit.tar.gz

mkdir -p /usr/local/hugo
tar -xf hugo_extended_*_Linux-64bit.tar.gz -C /usr/local/hugo
ln -s /usr/local/hugo/hugo /usr/sbin/

# 查看版本
hugo version

.
|-- archetypes
|-- assets
|-- content # 内容,后续博客文章将放置在这里
|-- data
|-- hugo.toml # 配置文件,菜单、评论、网站统计等所有功能,均可以通过直接配置进行开启
|-- i18n # 多语言
|-- layouts  # 网站布局
|-- public
|-- resources
|-- static # 静态文件,如头像图片等
|-- themes # 所有主题以子文件夹的形式存放

新建站点,配置主题

hugo new site quickstart
cd quickstart
#git init
#git submodule add https://github.com/adityatelange/hugo-PaperMod.git themes/hugo-PaperMod
echo "theme = 'hugo-PaperMod'" >> hugo.toml

启动,hugo.toml 中的 baseURL 配置项似乎没用,启动命令添加参数: --baseURL=http://xxx/

Usage:
  hugo server [command] [flags]
  hugo server [command]

Flags:
      --appendPort               append port to baseURL (default true)
  -b, --baseURL string           hostname (and path) to the root, e.g. https://spf13.com/
      --bind string              interface to which the server will bind (default "127.0.0.1")
  -D, --buildDrafts              include content marked as draft
  -p, --port int                 port on which the server will listen (default 1313)

#内网直联
hugo server -D --bind="0.0.0.0" --port=1313 --baseURL=http://192.168.1.1/
#nginx代理
hugo server -D --bind="0.0.0.0" --port=1313 --baseURL=https://hugo.gotodev.cn/ --appendPort=false

nohup hugo server -D --bind="0.0.0.0" --port=1313 --baseURL=https://hugo.gotodev.cn/ &

添加内容

hugo new content content/posts/my-first-post.md

+++
title = 'My First Post'
date = 2024-01-14T07:07:07+01:00
draft = true
featured = false
+++
## Introduction

This is **bold** text, and this is *emphasized* text.

Visit the [Hugo](https://gohugo.io) website!

draft = true 草稿,默认不发布,需要改成 false,或使用 hugo -D 发布

配置站点 hugo.toml

baseURL = 'https://example.org/'
languageCode = 'en-us'
title = 'My New Hugo Site'
theme = 'hugo-PaperMod'
paginate = 100    <- 全局的分页参数

使用浏览器打开 http://localhost:1313, http://192.168.237.130:1313 预览

发布网址

添加内容、配置站点后需要发布站点(hugo server -D启动时会覆盖配置,需要重新发布)

hugo

# 包括草稿
hugo -D

Hugo 会在项目根目录的public目录中创建整个静态网站。包括 HTML 文件和资源,例如images、CSS 文件和 JavaScript 文件。

rm -rf public/
hugo --cleanDestinationDir