Total Pageviews

Thursday, 6 March 2014

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

cd ~/mygo/
as3:~/mygo# go get github.com/peterbourgon/grender
as3:~/mygo# grender -h
Usage of grender:
  -debug=false: print debug information
  -global.key="files": template node name for per-file metadata
  -source="src": path to site source (input)
  -target="tgt": path to site target (output)
as3:~/mygo# cd ~
as3:~# git clone https://github.com/peterbourgon/grender grender-site
as3:~# cd grender-site
as3:~/grender-site# ls
examples    helpers_test.go  log.go   README.md  stack_test.go
helpers.go  LICENSE          main.go  stack.go
as3:~/grender-site# cd examples
as3:~/grender-site/examples# ls
01-single-file    03-layering-metadata  05-templates
02-separate-json  04-imports            06-basic-blog
as3:~/grender-site/examples# cd 06-basic-blog
as3:~/grender-site/examples/06-basic-blog# ls
src  tgt
as3:~/grender-site/examples/06-basic-blog# cd tgt
as3:~/grender-site/examples/06-basic-blog/tgt# ls
blog  index.html
as3:~/grender-site/examples/06-basic-blog/tgt# ls blog
2013                         2013-01-15-second-blog-entry.html
2013-01-02-first-entry.html  index.html
(可见~/grender-site/examples/06-basic-blog/tgt/就是静态网站的根目录)
as3:~/grender-site/examples/06-basic-blog/tgt# nohup Rwebserver 24532 > /dev/null &
访问http://as3.brite.biz:24532/就可看到网站效果。
以上的 ~/grender-site/examples/06-basic-blog/src/里的代码太简陋,我们可克隆作者的站点peter.bourgon.org的源码:
 as3:~/grender-site/examples/06-basic-blog/tgt# cd ~/grender-site/examples/
as3:~/grender-site/examples# git clone https://github.com/peterbourgon/peter-bourgon-org peter.bourgon.org-site
as3:~/grender-site/examples# cd peter.bourgon.org-site
as3:~/grender-site/examples/peter.bourgon.org-site# ls
README.md  src
as3:~/grender-site/examples/peter.bourgon.org-site# grender
(这个就是生成/更新静态网站的命令)
as3:~/grender-site/examples/peter.bourgon.org-site# ls
README.md  src  tgt
(新出现了tgt目录)
as3:~/grender-site/examples/peter.bourgon.org-site# cd tgt
as3:~/grender-site/examples/peter.bourgon.org-site/tgt# ls
about  blog  css  go-do  index.html  js  postmodernism
(可见~/grender-site/examples/peter.bourgon.org-site/tgt/就是静态网站的根目录)
as3:~/grender-site/examples/peter.bourgon.org-site/tgt# nohup Rwebserver 35418 > /dev/null &
访问http://as3.brite.biz:35418/就可看到网站效果。


发贴方法:
as3:~/grender-site/examples/06-basic-blog/tgt# cd ../src
as3:~/grender-site/examples/06-basic-blog/src# ls
blog  index.html
as3:~/grender-site/examples/06-basic-blog/src# cd blog
as3:~/grender-site/examples/06-basic-blog/src/blog# ls
2013-01-02-first-entry.md        entry.template  _.json
2013-01-15-second-blog-entry.md  index.html
as3:~/grender-site/examples/06-basic-blog/src/blog# cat 2013-01-02-first-entry.md
{"title":"My first entry"}
---
This is my **first** blog entry!
as3:~/grender-site/examples/06-basic-blog/src/blog# nano 2014-03-06-test1.md
格式为:
{"title":"test1"}
---

这是测试1.

然后,
as3:~/grender-site/examples/06-basic-blog/src/blog# cd ~/grender-site/examples/06-basic-blog/
as3:~/grender-site/examples/06-basic-blog# ls
src  tgt
as3:~/grender-site/examples/06-basic-blog# grender (这个就是生成/更新静态网站的命令)
as3:~/grender-site/examples/06-basic-blog#
 按上述这样2014-03-06-smiling-face.md,2014-03-06-chinese-economy.md建立帖子的名称,发布帖子后,所发表的文章在网页中往往并不是按时间顺序排列的。我们可这样做,
这样来给帖子命名:
 2014-03-07-15_23-super-talk.md,2014-03-07-15_27-various-names-of-marriage.md
其中的15_23表示15点23分。
这样命名后,发表的帖子就是按时间顺序排列的,最新的帖子在网页的最上面。

演示站点:http://as3.brite.biz:24532/,http://grd.bright.za.net;
http://as3.brite.biz:35418/blog/,http://grd2.bright.za.net
项目地址:https://github.com/peterbourgon/grender,
https://github.com/peterbourgon/peter-bourgon-org