又换主题了,这回使用的是hugo-theme-stack,无意发现这款主题,正合我意,够简单,最重要的是支持本地搜索,再不用弄哪个Alogia了。
下载主题&更新主题
- 下载主题
| |
- 更新主题
| |
查看主题版本号
| |
config.yaml配置文件
| |
archetypes默认模板
| |
显示右侧工具栏分类目录
参考 https://github.com/CaiJimmy/hugo-theme-stack/issues/169
最新版主题已默认开启分类目录工具栏
- Create
categories.htmlin layouts/partials/widget
| |
- 修改
config.yaml
| |
- 网站根目录新建
\i18n\zh-CN.yaml
| |
- Download categories.svg paste to
assets/icons, from here
注意:可以按需删除图标。
文章底部添加在 GitHub 上编辑此页
- 拷贝主题目录
/layouts/partials/article/components/footer.html到网站根目录,修改为:
| |
- 编辑
config.yaml:
| |
以后只要在Frontmatter添加edit: false来关闭。
- 拷贝
external-link.svg图标到网站根目录/assets/icons下。图标地址:点击直达
自动更新文章最后修改时间
1.在config.yaml里写:
| |
:git:git 文件提交修改时间:fileModTime:文件修改时间lastmod:文章里 lastmod 字段:defalut:默认时间
config.toml里写:[frontmatter] lastmod = [":git", “lastmod”, “:fileModTime”, “:defalut”]
enableGitInfo = true
gitRepo = “https://github.com/iwyang/hugo"
2..github/workflows/xx.yml:
yml 文件中添加 2 行设置当前环境时区
| |
3.gihutb action 里 yaml 上配置
建构前新增以下配置,主要是 quotePath,默认情况下,文件名包含中文时,git 会使用引号吧文件名括起来,这会导致 action 中无法读取:GitInfo 变量,所以要设置 Disable quotePath
| |
使用 checkout 的话 fetch-depth 需要设为 0,depth 默认是为 1,默认只拉取分支最近一次 commit,可能会导致一些文章的 GitInfo 变量无法获取,设为 0 代表拉去所有分支所有提交。
| |
以下是我最终的 yml 配置文件:
| |
别人:
| |
删除文章底部更新于
| |
删除相关文章、分类图片,修改相关文章数目
删除相关文章图片
请在你的 article.scss 文件中找到 .related-content 这一块(大约在文件中间偏下的位置),将它完全替换为以下代码:
| |
删除分类图片
根目录assets/scss/partials/layout/list.scss
| |
修改相关文章数目
根目录layouts/partials/article/components/related-contents.html
| |
数字设为0,即关闭相关文章。
加入字数统计、站点总字数统计
加入字数统计
1.直接用阅读时间改的,图标路径为根目录assets\icons
根目录layouts\partials\article\components\details.html
| |
2.然后在config.yaml中加入一行,以正确显示中文字符数量
| |
3.config.yaml中确保readingTime: true
站点总字数统计
1.根目录layouts\partials\footer\footer.html里写上总字数参数
| |
2.根目录layouts\partials\footer\footer.html
| |
PS:如果加入站点总字数统计,Github Action部署到服务器就会变慢。
添加友情链接 shortcodes
网站根目录新建文件
layouts\page\links.html: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{{ define "body-class" }}article-page keep-sidebar{{ end }} {{ define "main" }} {{ partial "article/article.html" . }} <div class="article-list--compact links"> {{ $siteResources := resources }} {{ range $i, $link := $.Site.Data.links }} <article> <a href="{{ $link.website }}" target="_blank" rel="noopener"> <div class="article-details"> <h2 class="article-title"> {{- $link.title -}} </h2> <footer class="article-time"> {{ with $link.description }} {{ . }} {{ else }} {{ $link.website }} {{ end }} </footer> </div> {{ if $link.image }} {{ $image := $siteResources.Get (delimit (slice "link-img/" $link.image) "") | resources.Fingerprint "md5" }} {{ $imageResized := $image.Resize "120x120" }} <div class="article-image"> <img src="{{ $imageResized.RelPermalink }}" width="{{ $imageResized.Width }}" height="{{ $imageResized.Height }}" loading="lazy" data-key="links-{{ $link.website }}" data-hash="{{ $image.Data.Integrity }}"> </div> {{ end }} </a> </article> {{ end }} </div> {{ if or (not (isset .Params "comments")) (eq .Params.comments "true")}} {{ partial "comments/include" . }} {{ end }} {{ partialCached "footer/footer" . }} {{ partialCached "article/components/photoswipe" . }} {{ end }}网站根目录新建文件
\layouts\shortcodes\link.html:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19{{$URL := .Get 0}} {{ with .Site.GetPage $URL }} <div class="post-preview"> <div class="post-preview--meta" style="width:100%;"> <div class="post-preview--middle"> <h4 class="post-preview--title"> <a target="_blank" href="{{ .Permalink }}">{{ .Title }}</a> </h4> <time class="post-preview--date">{{ .Date.Format ( default "2006-01-02") }}</time> {{ if .Params.tags }} <small>{{ range .Params.tags }}#{{ . }} {{ end }}</small> {{ end }} <section style="max-height:105px;overflow:hidden;" class="post-preview--excerpt"> {{ .Summary | plainify}} </section> </div> </div> </div> {{ end }}网站图像放在网站根目录\assets\link-img\文件夹下。- 网站根目录新建文件
\data\links.json:
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 67 68 69 70 71 72 73 74[ { "title": "Upptime", "website": "https://iwyang.github.io/check", "image": "upptime.jpg", "description": "利用Github Actions查看网站运行状态。" }, { "title": "ConstOwn", "website": "https://blog.juanertu.com", "image": "constown.jpg", "description": "能与你一起成长,我荣幸之至。" }, { "title": "小丁的个人博客", "website": "https://tding.top", "image": "ding.jpg", "description": "世间所有的相遇,都是久别重逢。" }, { "title": "Xu's Blog", "website": "https://hasaik.com", "image": "xu.jpg", "description": "简单不先于复杂,而是在复杂之后。" }, { "title": "知行志", "website": "https://baozi.fun", "image": "zhi.jpg", "description": "Halo Theme Xue作者。" }, { "title": "Takagi", "website": "https://lixingyong.com", "image": "takagi.jpg", "description": "Takagi是啥呀??当然是最喜欢的Takagi了吖ヾ(≧∇≦*)ゝ" }, { "title": "千与千寻", "website": "https://www.chihiro.org.cn", "image": "qian.jpg", "description": "所以,看不到光,算是不幸吗?需要光才是真正的不幸吧。" }, { "title": "Bill Yang's Blog", "website": "https://blog.bill.moe", "image": "bill.jpg", "description": "这辈子都不可能更新的 。" }, { "title": "Sanarous's Blog", "website": "https://bestzuo.cn", "image": "sanarous.jpg", "description": "Dream it possible, make it possible" }, { "title": "JACK小桔子的小屋", "website": "https://jackxjz.top/", "image": "jack.jpg", "description": "一个分享科技/日常的网站。" }, { "title": "若只如初见", "website": "https://joyli.net.cn/", "image": "ruo.jpg", "description": "世间所有的相遇,都是久别重逢。" }, { "title": "大大的小蜗牛", "website": "https://eallion.com/", "image": "eallion.jpg", "description": "机会总是垂青于有准备的人。" } ]
5.调整布局,设置友情链接为双栏:
修改根目录/assets/scss/custom.scss
| |
添加音乐短代码
1.网站根目录新建文件layouts\shortcodes\music.html
| |
2.添加歌曲列表(注意:去掉注释/* */)
| |
3.添加单曲(注意:去掉注释/* */)
| |
4.其它参数
music shortcode 有一些可以应用于以上三种方式的其它命名参数:
autoplay [可选]
是否自动播放音乐, 默认值是
false.
更改分类、标签、页面显示中文
content目录下新建categories\_index.md:
| |
content目录下新建tags\_index.md:
| |
- 根目录
\i18n\zh-CN.yaml输入:
| |
最终根目录\i18n\zh-CN.yaml
| |
附:使用Git Submodule管理Hugo主题
- 如果克隆库的时候要初始化子模块,请加上
--recursive参数,如:
| |
- 如果已经克隆了主库但没初始化子模块,则用:
| |
- 如果已经克隆并初始化子模块,而需要从子模块的源更新这个子模块,则:
| |
更新之后主库的 git 差异中会显示新的 SHA 码,把这个差异选中提交即可。
- 其他命令:在主仓库更新所有子模块:
git submodule foreach git pull origin master
附:hugo注释
| |