Total Pageviews

Sunday, 8 December 2013

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

pip install hazel
(也可这样安装:
git clone https://github.com/shunfan/hazel.git
cd hazel
pip install -r requirements.txt
python setup.py install)
mkdir hazel-site
cd hazel-site
hazel init (此命令会初始化博客的目录结构)

as3:~/hazel-site# hazel init
as3:~/hazel-site# ls
config.yml  posts  site  templates
as3:~/hazel-site# ls site
as3:~/hazel-site#
as3:~/hazel-site# hazel -h
Usage: hazel init...
       hazel install <template>
       hazel write <title>
       hazel generate
       hazel deploy
Options: -h, --help
as3:~/hazel-site# hazel write test1 (这是新建帖子的命令。test1为postslug,一般用英文)
显示:
New post is written successfully.
as3:~/hazel-site# ls
config.yml  posts  site  templates
as3:~/hazel-site# ls posts
images  test1.md
as3:~/hazel-site# cd posts
as3:~/hazel-site/posts# cat test1.md
title: Your post title
date: 2013-12-08 09:29:50

Start writing here...
as3:~/hazel-site/posts# nano test1.md
as3:~/hazel-site/posts# cat test1.md
title: test1 (这里才是标题,英文/中文均可)
date: 2013-12-08 09:29:50

这是测试1.
as3:~/hazel-site/posts# cd ..
as3:~/hazel-site# hazel generate (这是生成/更新静态网站的命令)
显示:
Reading test1.md now...
> read successfully.
> rendered successfully.
> written successfully.
Complete.
as3:~/hazel-site# ls
config.yml  posts  site  templates
as3:~/hazel-site# cd site
as3:~/hazel-site/site# ls
404.html  archive.html  assets  feed.html  index.html  layout.html  post
as3:~/hazel-site/site#
可见~/hazel-site/site/就是静态网站的根目录。
as3:~/hazel-site/site# nohup Rwebserver 4517 > /dev/null &
访问http://as3.brite.biz:4517/,即可看到网站效果。

演示站点:http://as3.brite.biz:4517,http://hz.surmount.biz.wf
项目地址:https://github.com/shunfan/hazel/
使用指南:https://hazel.readthedocs.org/en/latest/

注意:我的webserver是apache,须如下修改apache的配置文件:
<VirtualHost vps-ip:80>
ServerName hz.surmount.biz.wf
DocumentRoot /root/hazel-site/site/
<Directory /root/hazel-site/site/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
        </Directory>

</VirtualHost>

如果不加上蓝色部分,那么在访问http://hz.surmount.biz.wf/post/fengyuwuzu之类没有.html的地址时,会显示not found.其实http://hz.surmount.biz.wf/post/fengyuwuzu.html也是可访问的。
这里http://briteming.blogspot.co.uk/2013/12/linux-vpspython-turtleblog.html也有类似问题。

这是国人(好像还在读高中,真是后生可畏啊)的作品,感觉不亚于pelican等程序。中国人的聪明才智是共匪压不住的!