Total Pageviews

Wednesday, 13 November 2013

在linux vps上搭建基于go的静态博客程序-gostatic

wget https://go.googlecode.com/files/go1.1.2.linux-386.tar.gz
tar zxvf go1.1.2.linux-386.tar.gz
cd go
设置PATH,export PATH=$PATH:/root/go/bin/ (这样go环境就搭建好了)

wget http://solovyov.net/files/gostatic-32-linux
chmod 755 gostatic-32-linux
./gostatic-32-linux -i gostatic-site (在当前目录下会生成gostatic-site目录)
cd gostatic-site
as3:~/gostatic-site# ls
config  site.tmpl  src
as3:~/gostatic-site# /root/gostatic-32-linux --watch --port=7843 config &
[2] 488
as3:~/gostatic-site# Rendering 0 changed pages of 5 total
Starting server at *:7843...
as3:~/gostatic-site#
立马就可访问http://as3.brite.biz:7843/,查看网站。

as3:~/gostatic-site# ls
config  site  site.tmpl  src (新出现了site目录)
as3:~/gostatic-site# ls site
blog  blog.atom  index.html  static  tags (可见~/gostatic-site/site/就是静态网站的根目录)
as3:~/gostatic-site# cd src/blog/
as3:~/gostatic-site/src/blog# ls
first.md
as3:~/gostatic-site/src/blog# nano test1.md
(按first.md的格式,新建帖子test1.md,格式如下:
title: test1
date: 2013-11-13
tags: misc
----
这是测试1.

保存更改,网站就自动更新了,因为此命令“/root/gostatic-32-linux --watch --port=7843 config &”是在后台运行的,--watch表示关注着源目录~/gostatic-site/src/的任何变动而自动把变动内容生成到~/gostatic-site/site/目录。

演示站点:http://as3.brite.biz:7843/,http://gs.brite.biz/
项目地址:https://github.com/piranha/gostatic
------------
你也可编译gostatic如下:
先安装go1.4环境。

cd /usr/local/go
mkdir gospace
cd gospace
export GOPATH=`pwd`
go get github.com/piranha/gostatic

稍等片刻,在gospace下面的bin目录里就会出现可执行文件gostatic。
root@AR:/usr/local/go/gospace# /usr/local/go/gospace/bin/gostatic -h
Usage:
  gostatic [OPTIONS] path/to/config

Build a site.

Application Options:
      --processors   show page processors
      --show-config  print config as JSON
      --summary      print all pages on stdout
  -i, --init=        create example site
  -d, --dump=        print page metadata as JSON (pass path to source or target
                     file)
  -f, --force        force building all pages
  -w, --watch        serve site on HTTP and rebuild on changes
  -p, --port=        port to serve on (default: 8000)
  -v, --verbose      enable verbose output
  -V, --version      show version and exit

Help Options:
  -h, --help         Show this help message


root@AR:/usr/local/go/gospace#