下载安装
winget install Hugo.Hugo.Extended #下载的拓展版本,官方推荐使用
主题
一般推荐使用PaperMod
git init
git submodule add https://github.com/adityatelange/hugo-PaperMod.git themes/PaperMod
配置上需要添加
theme="PaperMod"
配置模板
baseURL = "/"
languageCode = "zh-cn"
title = "我的第一个博客"
mainSections = ["posts"]
theme="PaperMod"
hasCJKLanguage=true
[pagination]
pagerSize = 10
[params]
disableSpecial1stPost = true
ShowReadingTime = true
ShowWordCount = true
defaultTheme = "auto"
baseURL部分本地测试留/即可,根据部署需要更改
关于hugo基本指令
hugo new posts/文章名字.md #创建新文章
hugo server -D #启用本地代理开发者浏览模式,去除掉尾部-D正常浏览
关于关键字
-
draft :如果设置为true,正常浏览将看不到这篇文章,开发者除外
-
tags :合适的标签可以使得知识检索更快
-
date :时间胶囊,记录着你每一次的文章日期
-
type :提升layouts某个文件夹的优先级,比如 type : test 他就优先去找layouts下test文件目录下的模板
-
layout :直接指定用某个模板,优先前后缀同时匹配,查找的文件夹目录默认是他自己根据content根目录推断的.Type,可以根据type改变
以单页模板为例
layouts/<.Type>/→
layouts/<.Type>/single.html→
layouts/_default/→
_layouts/_default/single.html
查找顺序从上到下
关于配置文件内容
-
[params]:
作为主要的参数块被PaperMod主题读取
[params]的内容会被模板文件调用
参数名 类型 作用说明 disableSpecial1stPostbool是否禁用首页第一篇文章的特殊样式 ShowReadingTimebool是否在文章页显示 “阅读时长” ShowWordCountbool是否显示 “字数统计” defaultThemestring默认主题模式,可选 "light"/"dark"/"auto"profilePagestring指定点击头像后跳转到的页面(例如 “about/”) -
[params.profileMode]
作为[params]的子内容出现
主要功能:控制主页的profile模式
参数名 类型 作用 enabledbool是否启用 Profile 模式(true 开启) titlestring头像下方的标题(通常是你的昵称) subtitlestring副标题或一句个性签名 imageUrlstring头像图片路径(相对路径或完整 URL) imageTitlestring头像的悬停提示文字 imageWidth/imageHeightint头像显示尺寸(像素) -
[[…]]
表示数组(列表)项
例如:[[params.profileMode.buttons]]作为列表出现,每个按钮都是一组键值对
键名 说明 name按钮文字 url按钮跳转链接(相对路径或完整 URL) [[params.profileMode.buttons]] name = "内容" url = "/content" -
层次结构
params └─ profileMode └─ buttons[]
-