How to use CleanWhite Hugo Theme?

Posted by yaohong on Friday, April 24, 2020

TOC

How to use CleanWhite Hugo Theme?

CleanWhite Hugo Theme 是Huabing Zhao制作的hugo主题,非常高雅好用,再次感谢Huabing。

我在使用时,花了一点时间,主要遇到以下问题:

  • 1.config.toml怎么配置?
  • 2.怎么在主页显示文章列表?
  • 3.怎么在顶部菜单栏添加分类?
  • 4.主页图片怎么设置?
  • 5.怎么部署到github上?
  • 6.什么设置个人域名?[可选]
  • 7.怎么开启评论?
  • 8.点击右上角的搜索,怎么提示404?

一个一个讲。

1.config.toml配置文件怎么配置?

其实Huabing在themes里有exampleSite文件夹,配置可以参考exampleSite下的config.toml配置;

2.怎么在主页显示文章列表?

需要在content目录下创建post文件夹,然后把所有markdown文件都放这里。

3.怎么在顶部菜单栏添加分类?

如果你想添加一个分类,可以按如下方式操作:

1.可以在config.toml文件中,将omit_categories改为fasle,如

[params]
  ...
  omit_categories = false
  ...

...表示省略其它内容。

2.在content/post/里某一个md文件中,在其文件头添加categories这一项,如:

---
title:       "Hello World"
subtitle:    ""
description: ""
date:        2020-04-24T15:57:20+08:00
author:       "yaohong"
image:       ""
tags:        ["How to do"]
categories:	 ["TECH"]
---

这里categories: ["TECH"]是个数组,可以在中括号里添加多个值,注意需要有引号,还有就是这个值有用,需要在下一步创建一个叫tech.md的空文件,看第3步。

3.在content/目录下创建categories文件夹,然后在categories添加tech.md文件,tech的值为md文件头中categories的值,这样就可以使用啦。

4.主页图片怎么设置?

在项目根目录的static文件夹下,创建img文件夹,图片放在这里面。

5.怎么部署到github上

#!/bin/sh
if [ "`git status -s`" ]
then
    echo "The working directory is dirty. Please commit any pending changes."
    exit 1;
fi

echo "Deleting old publication"
rm -rf public
mkdir public
git worktree prune
rm -rf .git/worktrees/public/

echo "Checking out gh-pages branch into public"
git worktree add -B gh-pages public origin/gh-pages

echo "Removing existing files"
rm -rf public/*

echo "Generating site"
hugo

# add CNAME only for customing domain
# touch public/CNAME
# echo "www.yaohong.vip" > public/CNAME


echo "Updating gh-pages branch"
cd public && git add --all && git commit -m "Publishing to gh-pages (publish.sh)"

echo "Pushing to github"
git push --all

6.什么设置个人域名?

待补充

7.怎么快速开启评论?

hugo-theme-cleanwhite内置支持disqus评论,但在中国不能用,需要添加服务器代理,评论还需要登录。

因此我在网上找了其它方式来实现,发现valine可以实现这个功能,且不用添加代理。

valine是一款快速、简洁且高效的无后端评论系统,集成方法如下:

1.在config.toml[params]下添加

[params]
  ...
  # valine
  valine_comment = true 
  leancloud_app_id_for_valine = "" # 改成你的leancloud_app_id
  leancloud_app_key_for_valine = "" # 改成你的leancloud_app_key
  ...

2.同时在themes/hugo-theme-cleanwhite/layouts/partials/comments.html添加如下代码:

<!-- vcomments 评论框 end -->
{{ if .Site.Params.valine_comment }}
<script src='//unpkg.com/valine/dist/Valine.min.js'></script>
<div id="vcomments"></div>
<script>
    new Valine({
        el: '#vcomments',
        appId: '{{ .Site.Params.leancloud_app_id_for_valine }}',
        appKey: '{{ .Site.Params.leancloud_app_key_for_valine }}'
    })
</script>
{{ end }}

参考:valine

8.点击右上角的搜索,怎么提示404?

需要在content/里添加search文件夹,然后在search下建一个空文件,名字叫placeholder.md

「点个赞」

Yaohong

点个赞

使用微信扫描二维码完成支付