空空如也的页面,需要好好配置一番才能丰富多彩。

配置config.yml

隐性配置

上一篇config.yml的基础上先加入以下内容:

 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
copyright: "© 20xx [xxx](https://github.com/xxx)" # 版权说明
paginate: 5 # 每页文章数
enableInlineShortcodes: true # 是否使用短码
enableRobotsTXT: true # 是否允许被搜索引擎收录
buildDrafts: false
buildFuture: false
buildExpired: false
enableEmoji: true # 是否使用emoji表情
pygmentsUseClasses: true
mainsections: ["posts", "papermod"]
minify:
  disableXML: true
outputs:
  home:
    - HTML
    - RSS
    - JSON
markup:
  goldmark:
    renderer:
      unsafe: true
  highlight:
    noClasses: false
    codeFences: true
    guessSyntax: true
    lineNos: true
services:
  instagram:
    disableInlineCSS: true
  twitter:
    disableInlineCSS: true
params:
  env: production
  description: "xxx's blog"
  author: xxx # 作者
  defaultTheme: auto
  ShowShareButtons: false # 是否显示分享按钮
  ShowReadingTime: true # 是否显示阅读时间
  displayFullLangName: true
  ShowPostNavLinks: true # 是否显示上一页下一页
  ShowBreadCrumbs: true
  ShowCodeCopyButtons: true # 是否在代码上显示复制按钮
  ShowRssButtonInSectionTermList: false
  ShowAllPagesInArchive: true
  ShowPageNums: true # 是否显示页数
  ShowToc: false # 是否显示目录
  DateFormat: "2006-01-02 15:04:05" # 时间格式
  socialIcons:
    - name: github
      title: View Source on Github
      url: "https://github.com/xxx"
  label:
    text: "xxx"
    icon: icon.png
    iconHeight: 35
  assets:
    disableHLJS: true

以上的xxx换成自己的内容。当然,此时看到的页面不会有太大的变化,因为这些都是相对比较隐性的设置。

后期一些细节上的调整基本上是在这一部分进行修改。

首页配置

然后再加入以下内容:

 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
defaultContentLanguage: zh
languages:
  zh:
    languageName: "简体中文"
    weight: 1
    taxonomies:
      category: categories
      tag: tags
      series: series
    menu: # 导航菜单
      main:
        - name: 搜索
          url: search/
          weight: 1
        - name: 主页
          url: /
          weight: 2
        - name: 文章
          url: posts/
          weight: 3
        - name: 时间轴
          url: archives/
          weight: 998
        - name: 关于
          url: about/
          weight: 999
    params:
      profileMode:
        enabled: true
        title: "这是个大标题"
        imageUrl: "" # 头像地址
        imageTitle: 头像
        imageWidth: 320 # 头像尺寸
        imageHeight: 320 # 头像尺寸
        subtitle: "这是个小标题"
        buttons: # 首页展示的按钮
          - name: 分类
            url: categories/
          - name: 标签
            url: tag/
          - name: 系列
            url: series/

此时的页面已经像那么回事了,后期的维护也主要是调整这一部分的内容。

目录维护

经过以上配置,页面是有了,不过只是徒有其表罢了,因为还没有内容框架的支撑,点菜单按钮还是会没内容或显示404

按如下目录结构创建文件夹及文件:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
content/
├── about.md
├── archives.md
├── categories
│   └── _index.md
├── posts
│   └── _index.md
├── search.md
├── series
│   └── _index.md
└── tags
    └── _index.md

about.md

加入以下内容,并在其后写上具体的自我介绍,点关于菜单即可看到具体内容。

1
2
3
4
5
---
title: "关于"
layout: about
hidemeta: true
---

archives.md

加入以下内容,不需要写其它内容,以后添加的文章会自动按时间倒序显示在此处。

1
2
3
4
5
---
title: "时间轴"
layout: archives
summary: archives
---

search.md

加入以下内容,不需要写其它内容,搜索功能即可使用

1
2
3
4
---
title: "搜索"
layout: search
---

categories/_index.md

加入以下内容,不需要写其它内容,文章指定了categories即可按categories的内容自动分类,点分类按钮即查看具体分类。

1
2
3
4
5
---
title: "分类"
layout: categories
summary: categories
---

series/_index.md

加入以下内容,不需要写其它内容,文章指定了series即可按series的内容自动分类,点系列按钮即查看具体分组。

1
2
3
4
5
---
title: "系列"
layout: series
summary: series
---

tags/_index.md

加入以下内容,不需要写其它内容,文章指定了tags即可按tags的内容自动分类,点标签按钮即查看具体分组。

1
2
3
4
5
---
title: "标签"
layout: tags
summary: tags
---

posts

posts是以后存放文章的根目录,可以根据需要再建子目录,子目录内也可继续建子目录,但要求每个目录下都要有一个_index.md文件,内容如下,根据实际情况进行调整。

1
2
3
4
---
title: "文章"
hidemeta: true
---

模板维护

修改archetypes/default.md内容为:

1
2
3
4
5
6
7
8
9
---
title: "{{ replace .File.ContentBaseName "-" " " | title }}"
date: {{ .Date }}
weight: 0
categories: []
tags: []
series: []
draft: true
---

使用hugo new content content/posts/*.md创建文章时,默认使用的就是该模板。

  • weight:权重,同一目录下,值越小(不含0)排名越靠前,类似置顶功能。

  • categoriestagsseries:分别对应分类标签系列,可填0~n个词或短语,注意要用""括起来,并用,进行分隔。

  • draft:草稿,为true时,运行hugo server-D可看到,不加看不到,hugo编译时也看不到;为false时都能看到,文章确定没问题后记得修改为false,否则最终是看不到的。


以上配置完之后,就可以正式开启写博文之路了。至于一些更加个性化的配置,详见PaperMod wiki或搜索引擎。