使用 Hugo 搭建个人博客

本文详细介绍使用Hugo静态站点生成器创建、配置和运行个人网站的过程,包括安装Hugo、创建新网站、添加主题、内容及启动本地服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

0. Hugo 简介

官网:Hugo

1. 安装 Hugo

ArchLinux为例:

$ sudo pacman -S hugo
...
$ hugo version  # 验证安装
Hugo Static Site Generator v0.54.0/extended linux/amd64 BuildDate: unknown
复制代码

其他操作系统请参考:Installing Hugo

2. 创建网站

$ hugo new site quickstart
Congratulations! Your new Hugo site is created in /xxx/xxx/quickstart.

Just a few more steps and you're ready to go:

1. Download a theme into the same-named folder.
   Choose a theme from https://themes.gohugo.io/, or
   create your own with the "hugo new theme <THEMENAME>" command.
2. Perhaps you want to add some content. You can add single files
   with "hugo new <SECTIONNAME>/<FILENAME>.<FORMAT>".
3. Start the built-in live server via "hugo server".

Visit https://gohugo.io/ for quickstart guide and full documentation.
复制代码

3. 添加一个主题

全部主题见themes.gohugo.io,这里以Ananke主题为例:

$ cd quickstart
$ git init
$ git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke
$ cat config.toml
baseURL = "http://example.org/"
languageCode = "en-us"
title = "My New Hugo Site"
$ echo 'theme = "ananke"' >> config.toml
$ cat config.toml
baseURL = "http://example.org/"
languageCode = "en-us"
title = "My New Hugo Site"
theme = "ananke"
复制代码

4. 添加一些内容

$ hugo new posts/my-first-post.md
复制代码

然后在my-first-post.md中任意添加一些内容。

5. 启动 Hugo 服务

$ hugo server -D

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

Total in 12 ms
Watching for changes in /home/ronald/go/src/quickstart/{content,data,layouts,static,themes}
Watching for config changes in /home/ronald/go/src/quickstart/config.toml
Environment: "development"
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
复制代码

然后打开http://localhost:1313/访问。

6. 自定义主题

详情请参考Theme Components

-1. 迁移

先把blog仓库克隆下来,然后删除此仓库并重建此仓库,然后换一个目录将此仓库再克隆下来,然后讲原仓库的文件全部复制进新仓库。

然后:

$ cd blog
$ git submodule add https://github.com/aubm/hugo-code-editor-theme.git themes/code-editor
$ git submodule add -b master git@github.com:RonaldZhao/RonaldZhao.github.io.git public
复制代码

然后将public文件夹中除.git文件外全部删除,然后在blog文件夹中执行hugo -D

最后分别在blogpublic文件夹中push

转载于:https://juejin.im/post/5cb533e251882532b96ca994

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值