个人博客搭建Hugo

基于Macbook M2芯片(主要原因是换电脑了,同时自己主学go语言,于是打算将Hexo换成Hugo,练练手)

https://copyfuture.com/blogs-details/20191229203259169ljtxcq9vmlzjyvf
http://scarletsky.github.io/2019/05/02/migrate-hexo-to-hugo/
https://www.tomczhen.com/2019/06/04/getting-start-blog-with-hugo/
https://lequ7.com/guan-yu-hugo-bo-ke-qian-yi-zhi-lu-cong-hexo-huan-cheng-hugo.html
https://blog.csdn.net/hqweay/article/details/101233371

搭建过程从头开始

环境安装 #

安装Homebrew #

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

根据提示安装Git

根据提示往下选择

运行
source /Users/wangb/.zprofile

运行brew doctor根据提示处理现有的问题

brew doctor

安装Golang #

查看可安装的golang版本

brew search go  //最好使用手动安装,m2系列brew安装的go会出一些小问题 没找到什么原因

安装go环境:

brew install go@1.18//改成你喜欢的版本号

在.zshrc 文件中追加配置

vim  ~/.zshrc

在文件最后输入一下内容:

export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOROOT/bin:$GOBIN
export GO111MODULE=on

Esc 键退回一般模式,然后输入 :wq 命令并回车保存退出文件。再使用以下命令使变量立即生效。

source .zshrc

由于Golang的官方代理源速度慢有时候会出现包不能下载的情况,我们使用以下命令把代理源设置为国内的代理源。

go env -w GOPROXY=https://goproxy.cn,direct

使用以下命令查看Golang版本信息。

go version
go1.16.4 linux/amd64

使用以下命令查看Golang环境变量配置。

go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/lib/go-1.13"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.13/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build410299436=/tmp/go-build -gno-record-gcc-switches"

安装wget #

brew install wget

安装Hugo #

brew install hugo
hugo version

生成网站 #

生成站点 #

hugo new site MyHu

安装皮肤 #

git submodule add https://github.com/alex-shpak/hugo-book themes/hugo-book
echo theme = \"ananke\" >> config.toml

添加内容 #

hugo new posts/my-first-post.md

启动 Hugo 服务器 #

hugo server -D

Hexo迁移Hugo #

目录结构 #

docs目录 #

博客目录 #

bookFlatSection: true   //加粗,并跟前后空格隔开,后面的顶格
bookCollapseSection: true   //折叠效果

效果如下

本博客目录设置是基于Hugo-book主题设置

主题config.toml文件 #
baseURL = 'http://example.org/'
languageCode = 'zh-cn'
title = 'Soulmate'
theme = "hugo-book"

# Needed for mermaid/katex shortcodes
[markup]
[markup.goldmark.renderer]
  unsafe = true

[markup.tableOfContents]
  startLevel = 1

[menu]
# [[menu.before]]
[[menu.after]]
  name = "Gitee"
  url = "https://gitee.com/chaincode"
  weight = 10

[[menu.after]]
  name = "还没想好"
  url = "https://"
  weight = 20

# (可选)如果您使用它来跟踪您的网站,请设置 Google Analytics。
# 始终放在配置文件的最前面,否则不起作用
#googleAnalytics = "UA-XXXXXXXXX-X"

# (可选)如果您提供 Disqus 短名称,评论将启用
# 所有页面。
#disqusShortname = "my-site"

# (可选)如果您在文件名中使用大写字母,请将此设置为 true
disablePathToLower = true

# (可选)将此设置为 true 以启用 'Last Modified by' 日期和 git author'doc' 类型页面的信息。
#enableGitInfo = true

# (可选)主题用于文档用途,因此它不呈现分类。
# 您可以使用下面的配置删除相关文件
#disableKinds = ['taxonomy', 'taxonomyTerm']

[params]
  # (Optional, default light) Sets color theme: light, dark or auto.
  # Theme 'auto' switches between dark and light modes based on browser/os preferences
    # (可选,默认光)设置颜色主题:light, dark or auto.
  # 主题“自动”根据浏览器/操作系统偏好在暗模式和亮模式之间切换
  BookTheme = 'auto'

  # (可选,默认为 true)控制页面右侧的目录可见性。
  # 开始和结束级别可以通过 markup.tableOfContents 设置来控制。
  # 你也可以在front matter中每页指定这个参数。
  BookToC = true

  # (可选,默认无)设置图书徽标的路径。如果标志是
  # /static/logo.png 那么路径就是'logo.png'
  #BookLogo = 'logo.png'

  # (可选,默认无)设置叶子包渲染为侧边菜单
  # 如果没有指定文件结构和权重,将被使用
  # 已弃用,将于 2022 年 6 月移除
  #BookMenuBundle = '/menu'

  # (可选,默认文档)指定要呈现为菜单的内容部分
  # 您还可以将值设置为“*”以将所有部分呈现到菜单
  BookSection = 'docs'

  # 设置源仓库位置。
  # 用于“上次修改”和“编辑此页面”链接。
  BookRepo = 'https://github.com/alex-shpak/hugo-book'

  # 指定链接的提交部分到“doc”页面的页面的最后修改提交哈希类型。
  # 如果设置了“BookRepo”参数,则为必需。
  # 用于构造由 BookRepo/BookCommitPath/<commit-hash> 组成的 URL 的值
  # Github 使用'commit',Bitbucket 使用'commits'
  #BookCommitPath = 'commit'

  # 为“doc”页面类型启用“编辑此页面”链接。
  # 默认禁用。取消注释以启用。需要“BookRepo”参数。
  # 路径必须指向站点目录。
  #BookEditPath = 'edit/master/exampleSite'

  # (可选,默认为 2006 年 1 月 2 日)配置页面使用的日期格式
  # - 在 git 信息中
  # - 在博客文章中
  BookDateFormat = 'Jan 2, 2006'

  # (可选,默认 true)使用 flexsearch 启用搜索功能,
  # 索引是动态构建的,因此它可能会降低您的网站速度。
  # 索引配置可以在每个语言的 i18n 文件夹中进行调整。
  BookSearch = true

  # (可选,默认 true)在页面上启用评论模板
  # 默认情况下 partials/docs/comments.html 包含 Disqus 模板
  # See https://gohugo.io/content-management/comments/#configure-disqus
  # 可以被页面frontmatter中的相同参数覆盖
  #BookComments = true

gitee部署 #

生成静态文件

hugo

git全局设置(第一次使用)

Git 全局设置:   第一次需要设置
git config --global user.name "Soulmate"
git config --global user.email "xxxxxxx@163.com"

git上传仓库(我在旧仓库上传覆盖,没有仓库需要创建)

cd public
git init   初始化
git add .
git commit -m "first commit" 
git remote add origin https://gitee.com/chaincode/chaincode.git
git push -u origin master -f 

进入仓库更新一下 Gitee Pages 服务

大功告成