搭建个人博客的工具很多,如wordpress,但wordpress架构太庞大,不够轻量级。Hugo是Go语言的静态网站生成工具,使用markdown进行编辑,生成静态html页面速度极快,是一款不错的软件。

准备

安装hugo

直接到hugode github release下载二进制文件

wget https://github.com/gohugoio/hugo/releases/download/v0.53/hugo_0.53_Linux-64bit.deb

安装完成后,可以执行以下命令验证是否安装成功

hugo version

创建站点

hugo new site blog

添加主题theme

推荐使用飞雪无情的maupassant改版主题

cd blog
git clone https://github.com/rujews/maupassant-hugo themes/maupassant

修改config.toml下的theme配置

theme = "maupassant"

添加文章

hugo new posts/helloworld.md

启动hugo内置server

hugo server -D

然后可以通过 http://127.0.0.1:1313 进行访问

发布静态html页面

hugo

成功后,会生成一个public目录,完整的静态页面都放在里面,如下:

cire@MacBook:public$ tree -L 1
.
├── 2019
├── 404.html
├── archives
├── categories
├── css
├── index.html
├── index.xml
├── js
├── page
├── posts
├── sitemap.xml
└── tags

自定义文件链接地址

在每个md文件开头增加如下内容,可以生成类似 https://www.aibay.net/blog/2019/01/05/build-hugo-website.html 的链接

---
title: "Hello world"
date: 2019-01-03T15:01:42+08:00
draft: false
url: /2019/01/03/helloworld.html
tags: ["计划"]
---

其中url是自定义链接地址,tags是标签

完整的config.toml配置文件

baseURL = "https://www.aibay.net/blog/"
languageCode = "zh-CN"
title = "AIBAY"
theme = "maupassant"
googleAnalytics = "UA-xxxxxxxxx"
## 保持分类的原始名字(false会做转小写处理)
preserveTaxonomyNames = true
## 是否禁止URL Path转小写
disablePathToLower = true
# 摘要的最大长度
summaryLength = 140
# 中文需要设置hasCJKLanguage=true,摘要才能生效
hasCJKLanguage = true

[author]
  name = "CIRE"

[params]
  author = "CIRE"
  subtitle = "蜗牛的技术分享"
  keywords = "xxxxxxx"
  description = "xxxxxxxxxx"
  # 使用busuanzi统计
  busuanzi = true
  #google广告
  googleAd = "ca-pub-xxxxxxxxxx"
  
# 加入飞雪无情的推广链接,表示对TA的感谢
[[params.links]]
  title = "Android Gradle权威指南"
  name = "Android Gradle权威指南"
  url = "http://yuedu.baidu.com/ebook/14a722970740be1e640e9a3e"
[[params.links]]
  title = "常用开发工具CDN镜像"
  name = "常用开发工具CDN镜像"
  url = "http://mirrors.flysnow.org/"

[menu]
  
  [[menu.main]]
    identifier = "archives"
    name = "归档"
    url = "/archives/"
    weight = 3


[[params.ads]]
  title = "推广者专属福利,新客户无门槛领取总价值高达2775元代金券,每种代金券限量500张,先到先得。"
  url = "https://cloud.tencent.com/redirect.php?redirect=1025&cps_key=134077a732cc98dc157b3d8bb5aba245&from=console"
  img = "https://upload-dianshi-1255598498.file.myqcloud.com/%E6%96%B0%E7%94%A8%E6%88%B7%E4%B8%93%E5%B1%9E%E5%A4%A7%E7%A4%BC%E5%8C%85345x200-40fddedb235328c59779ae071cf378deab547ba5.jpg"
[[params.ads]]
  title = "云服务器、云数据库特惠,服务更稳,速度更快,价格更优"
  url = "https://cloud.tencent.com/redirect.php?redirect=1014&cps_key=134077a732cc98dc157b3d8bb5aba245&from=console"
  img = "https://upload-dianshi-1255598498.file.myqcloud.com/%E4%BA%91%E4%BA%A7%E5%93%81%E7%89%B9%E6%83%A03%E6%8A%98%E8%B5%B7345x200-02b8a4e7f6f785612b8b2a278cb0b7aed251d91d.jpg"
[[params.ads]]
  title = "国内首家采用 amd EPYC™霄龙处理器的实例,业界领先的性价比,0.57元/天起"
  url = "https://cloud.tencent.com/redirect.php?redirect=1032&cps_key=134077a732cc98dc157b3d8bb5aba245&from=console"
  img = "https://upload-dianshi-1255598498.file.myqcloud.com/AMD%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8345x200-e185198c0dfe0f262fee0633fb41bafe63dc104b.jpg"

参考

  1. 从Hexo迁移到Hugo-送漂亮的Hugo Theme主题