之前使用过wordpress搭建过内容管理网站,但是运行环境搭建有些复杂而且页面内容创建需要不够方便,后来关注到静态页面网站框架,发现可以使用markdown进行内容编辑,这对于程序猿来说简直再有好不过了!

简单检索了一下静态内容管理的有很多实现,Ruby的Jekyll,Python的Sphinx doc,Go的Hugo,因为最近在学习Go所以决定搭建一个Hugo来研究下。

使用源码部署hugo

部署golang


  $ yum install golang

下载hugo源代码


  $ wget https://github.com/spf13/hugo/archive/v0.18.1.tar.gz
  $ tar xf v0.18.1.tar.gz
  $ cd hugo-0.18.1/
  $ export GOPATH=/usr/local/go
  $ go get -v github.com/spf13/hugo

hugo的基本使用

创建项目


  $ /usr/local/go/bin/hugo new site myblogs

创建post


  $ /usr/local/go/bin/hugo new post/first.md

使用themes


  $ cd themes/
  $ git clone https://github.com/kakawait/hugo-tranquilpeak-theme.git
  $ cp hugo-tranquilpeak-theme/exampleSite/* ..

构造页面


  $ cd content
  $ mkdir archives
  $ touch archives/_index.md
  $ mkdir categories
  $ touch categories/_index.md
  $ mkdir tags
  $ touch tags/_index.md
执行成功后创建出下面的页面:

  http://[Your_blog_DNS]/archives
  http://[Your_blog_DNS]/categories
  http://[Your_blog_DNS]/tags

服务部署

第一步,使用 hugo 命令生成静态文件内容

$ cd <hugo project home>
$ hugo

执行完以上操作后会在项目目录中产生 public 目录,这个目录中包括了可以部署的静态文件。把 public 目录复制到 nginx 的公开目录中。

第二步,配置 nginx

server {
  listen       80;
  listen       [::]:80;
  server_name  yourhostname;

  location / {
    root /directory/of/public;
  }
}

至此,系统的搭建基本完成,赶紧访问吧 :-)

hugo theme开发

  • templating
    • 变量访问: {{ var }}
  • front matter
  • variables
    • Site variables
      • 作用:访问站点配置文件中的内容
    • Page variables
    • File variables