零基础搭建hugo博客 windows

2/18/2023 hugofixit

提前需要准备的东西

# 操作步骤

  1. # 安装hugo

下载安装hugo (opens new window)选择hugo_extended_0.110.0_windows-amd64.zip进行下载 把hugo.exe配置到全局环境变量

PS E:\> hugo  version
hugo v0.101.0-466fa43c16709b4483689930a4f9ac8add5c9f66 windows/amd64 BuildDate=2022-06-16T07:09:16Z VendorInfo=gohugoio
PS E:\>
1
2
3
  1. # 创建项目

hugo new site hugo-demo
1

创建完项目后,Hugo会帮我们生成一堆文件,我们需要知道这些文件的用途。

PS E:\demo\hugo-demo> tree /F
卷 Work 的文件夹 PATH 列表
卷序列号为 A861-7C83
E:.
│  config.toml        # 配置文件
│
├─archetypes
│      default.md
│
├─content     # 存放博客和单页文章
├─data        # 存放其他数据
├─layouts     
├─public      # 博客构建后的静态文件路径
├─static      # 用于存放静态资源
└─themes      # 主题路径
PS E:\demo\hugo-demo>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  1. # 创建第一篇文章

hugo new posts/my-first-post.md
1
  1. # 配置主题

git init
git submodule add https://github.com/hugo-fixit/FixIt.git themes/FixIt # 添加子模块
sudo cp themes/FixIt/config.toml config.toml # 复制主题配置到本地
1
2
3

修改配置文件 (config.toml) fixit文档 (opens new window)

title = "我的全新 Hugo FixIt 网站"
baseURL = "http://example.org/"
# 设置默认的语言 ["en", "zh-cn", "fr", "pl", ...]
defaultContentLanguage = "zh-cn"
# 网站语言, 仅在这里 CN 大写 ["en", "zh-CN", "fr", "pl", ...]
languageCode = "zh-CN"
# 是否包括中日韩文字
hasCJKLanguage = true

# 更改使用 Hugo 构建网站时使用的默认主题
# 如果使用 Hugo Module 加载主题,则不需要配置该参数
theme = "FixIt"

[params]
  # FixIt 主题版本
  version = "0.2.X"

[menu]
  [[menu.main]]
    identifier = "posts"
    # 你可以在名称(允许 HTML 格式)之前添加其他信息,例如图标
    pre = ""
    # 你可以在名称(允许 HTML 格式)之后添加其他信息,例如图标
    post = ""
    name = "文章"
    url = "/posts/"
    # 当你将鼠标悬停在此菜单链接上时,将显示的标题
    title = ""
    weight = 1
    # 向菜单项添加用户定义的内容
    [menu.main.params]
      # 添加 CSS 类到菜单项
      class = ""
      # 是否为草稿菜单,类似草稿页面
      draft = false
      # 添加 fontawesome 图标到菜单项
      icon = "fa-solid fa-archive"
      # 设置菜单项类型,可选值:["mobile", "desktop"]
      type = ""
  [[menu.main]]
    identifier = "categories"
    pre = ""
    post = ""
    name = "分类"
    url = "/categories/"
    title = ""
    weight = 2
    [menu.main.params]
      icon = "fa-solid fa-th"
  [[menu.main]]
    identifier = "tags"
    pre = ""
    post = ""
    name = "标签"
    url = "/tags/"
    title = ""
    weight = 3
    [menu.main.params]
      icon = "fa-solid fa-tags"

# Hugo 解析文档的配置
[markup]
  # 语法高亮设置 (https://gohugo.io/content-management/syntax-highlighting)
  [markup.highlight]
    # false 是必要的设置 (https://github.com/hugo-fixit/FixIt/issues/43)
    noClasses = false
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  1. # 在本地启动网站

hugo server
1

去查看 http://localhost:1313

更多详细配置fixit (opens new window)

Last Updated: 4/28/2023, 10:05:11 AM