blog系统

Posted on Oct 12, 2021

想搭建一个blog系统,写一些总结自娱自乐,然后发现了Hugo。

最后方案如下:

  1. 部署在云端,nginx做web服务器
  2. 使用hugo
    1. hugo的theme为eureka
    2. 留言评论:集成disqus js插件
  3. 文档格式:主要是markdown格式,用typora编辑
  4. 版本管理:文档以git方式存储在github

Hugo是什么?

不同于动态网站,是静态renderer的。

Hugo is a static HTML and CSS website generator written in Go. It is optimized for speed, ease of use, and configurability. Hugo takes a directory with content and templates and renders them into a full HTML website.

Hugo relies on Markdown files with front matter for metadata, and you can run Hugo from any directory.

安装比较简单,注意linux上apt源可能不够新,最好从github上下载最新的版本。

暂时使用nginx的反向代理实现,static文件目录直接让nginx访问,效率更高。

hugo #This generates your website to the `public/` directory by default

遇到的问题

baseurl中去掉port

问题:输出html中url为blog.time9.xyz:8889,默认带有端口,使得在nginx反向代理时有问题。

解决方案:命令行中设置appendPort=false

nohup hugo server -D --bind 127.0.0.1 --port 8889 -d public -b blog.time9.xyz --appendPort=false &

需要注意:

  1. appendPort=false中需要=
  2. appendPort设置到config中似乎没有用。
  3. {{ .Site.BaseURL }} 读取baseurl,并不是config中直接设置的,而是通过-b选项从命令行读取。

参考

  1. 官方

  2. appendPort=false works for .Site.BaseURL but not .Permalink

  3. Excluding port from sitemap baseurl

  4. RTFM