编辑配置文件

Hugo默认配置文件格式是.toml,但.yml格式更易看懂,因此我们之前在新建站点时候执行的是hugo new site blog -f yml命令,因此生成的文件是.yml格式

配置文件内容请根据个人情况自行修改

baseURL: "https://muzi.gq/" # 绑定的域名
languageCode: zh-cn
title: 萧的博客
theme: PaperMod # 主题名字,和themes文件夹下的一致

defaultContentLanguage: zh # 最顶部首先展示的语言页面
paginate: 10 # 每页显示的文章数
enableEmoji: true # 允许使用 Emoji 表情,建议 true

outputs:
  home:
    - HTML
    - RSS
    - JSON

params:
  env: production
  defaultTheme: auto
  description: "萧的博客"
  DateFormat: "2006-01-02"

  ShowReadingTime: true
  disableSpecial1stPost: true
  ShowPostNavLinks: true
  ShowBreadCrumbs: true
  ShowCodeCopyButtons: true
  ShowRssButtonInSectionTermList: true
  ShowToc: true # 显示目录
  TocOpen: true # 自动展开目录
  ShowLastMod: true #显示文章更新时间

  assets:
    favicon: "x.png"
    favicon16x16: "x.png"
    favicon32x32: "x.png"
    apple_touch_icon: "x.png"

menu:
  main:
    - identifier: search
      name: 搜索
      url: search
      weight: 1
    # - identifier: home
    #   name: 首页
    #   url: /
    #   weight: 2
    - identifier: posts
      name: 文章
      url: /posts
      weight: 3
    - identifier: tags
      name: 标签
      url: /tags
      weight: 40
    - identifier: about
      name: 关于
      url: /about
      weight: 50

目录放在侧边

PaperMod目录默认是放在顶部的,这里放在侧边,更方便使用。
参考 https://www.sulvblog.cn/posts/blog/hugo_toc_side/

这里做了一点改动,将JS放到了layouts/partials/extend_footer.html,这样可以实现JS放在Body最后。

{{- if (and (eq .Kind "page") (ne .Layout "archives") (ne .Layout "search") (.Param "ShowToc")) }}
//js代码放这里
{{- end }}

添加搜索页面

添加以下配置到config.yml文件(上述配置文件已有,此处不用重复添加)

outputs:
  home:
    - HTML
    - RSS
    - JSON

content文件夹中创建search.md并添加以下配置:

---
title: "搜索"
layout: "search"
# description: "Description for Search"
summary: "search"
placeholder: ""
---

自定义文章模板

为了方便使用,这里覆盖了Hugo默认模板archetypes/default.md

---
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
lastmod: {{ .Date }}
author: ["萧"]
categories: 
- 
tags: 
- 

description: "" #Meta描述
weight:  # 输入1可以顶置文章,用来给文章展示排序,不填就默认按时间排序
slug: ""
draft: false # 是否为草稿
comments: true #是否展示评论
showToc: true # 显示目录
TocOpen: true # 自动展开目录
hidemeta: false # 是否隐藏文章的元信息
disableShare: true # 底部不显示分享栏
showbreadcrumbs: true #顶部显示当前路径
cover:
    image: "" #图片路径:img/picture.png
    caption: "" #图片底部描述
    alt: ""
    relative: false
---

参考链接

https://dvel.me/posts/hugo-papermod-config/
https://shaohanyun.top/posts/env/blog_build2/