Total Pageviews

Sunday, 8 June 2014

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

git clone https://github.com/g4b1nagy/helpful-site g4b1nagy-site
cd g4b1nagy-site

as3:~/g4b1nagy-site# ls
config  LICENSE  manage.py  README.md  src
as3:~/g4b1nagy-site# pip install click
as3:~/g4b1nagy-site# ./manage.py new (这个是新建帖子/发贴的命令)
as3:~/g4b1nagy-site# cd src
as3:~/g4b1nagy-site/src# ls
2014-05-28-an-older-post.md      2014-06-08-test1.md  fonts
2014-05-28-hello-and-welcome.md  css                  js
as3:~/g4b1nagy-site/src# nano 2014-06-08-test1.md
(或者不使用它的新建帖子的命令也行。我们可按~/g4b1nagy-site/src/里面某个已有的源贴的格式,新建帖子2014-06-08-test2.md,
as3:~/g4b1nagy-site/src# nano 2014-06-08-test2.md
格式为:
===========================================================================
categories: 'misc1, misc2'
date: 2014-06-08 06:24
description: ''
icon: ''
ogimage: ''
script: ''
style: ''
template: post.html
title: !!python/unicode '测试2'
===========================================================================

这是测试2.

然后,
as3:~/g4b1nagy-site/src# cd ..
as3:~/g4b1nagy-site# ./manage.py build (这个就是生成/更新静态网站的命令)
as3:~/g4b1nagy-site# ls
config  dist  LICENSE  manage.py  README.md  src
(新出现了dist目录)
as3:~/g4b1nagy-site# cd dist
as3:~/g4b1nagy-site/dist# ls
2014-05-28-an-older-post      2014-06-08-test1  index.html
2014-05-28-hello-and-welcome  category
(可见~/g4b1nagy-site/dist/就是静态网站的根目录)
as3:~/g4b1nagy-site/dist# nohup Rwebserver 43984 > /dev/null &
访问http://as3.brite.biz:43984/即可看到网站效果。
以上访问网站时,网站未作styling处理,所以网站比较难看。我们可以这样:
 as3:~/g4b1nagy-site/dist# cd ..
  as3:~/g4b1nagy-site# nano manage.py
(修改manage.py的 第102行 为:
subprocess.call('crammit -c config/config.yaml', shell=True)
 as3:~/g4b1nagy-site# pip install crammit
 as3:~/g4b1nagy-site# ./manage.py mini (这步就是给网站做styling处理)
然后,访问http://gbng.brite.biz.st/,你会发现网站漂亮多了。

演示站点:http://as3.brite.biz:43984/,http://gbng.brite.biz.st
项目地址:https://github.com/g4b1nagy/helpful-site
----------------------------------------
作者更新了代码,以前的代码不支持分页,新的代码则支持了。
首先谈旧的代码:
root@as3:~# cd g4b1nagy-site
root@as3:~/g4b1nagy-site# rm config/config.yaml (删除旧的config.yaml)
root@as3:~/g4b1nagy-site# git pull (这个是更新git仓库源码的命令
Updating 45d538d..130097d
Fast-forward
 README.md                       |    9 +---
 config/config.yaml              |    7 +++
 config/templates/home.html      |   14 ++++--
 manage.py                       |   86 ++++++++++++++++++++++++++++++++------
 src/2014-05-28-an-older-post.md |    2 +-
 5 files changed, 92 insertions(+), 26 deletions(-)
root@as3:~/g4b1nagy-site# nano config/config.yaml
(修改"posts_per_page" 的值为3)
这样,旧的网站http://gbng.brite.biz.st/就有分页功能了。


git clone https://github.com/g4b1nagy/helpful-site g4b1nagy-site2
(现在克隆的版本是作者更新源码后的版本,具有分页功能)
cd g4b1nagy-site2
root@as3:~/g4b1nagy-site2# ./manage.py build
Building pages
root@as3:~/g4b1nagy-site2# ./manage.py mini
root@as3:~/g4b1nagy-site2# ls
config dist LICENSE manage.py README.md src
root@as3:~/g4b1nagy-site2# cd dist
root@as3:~/g4b1nagy-site2/dist# ls
2014-05-28-an-older-post 2014-06-18-Ce-Shi-1 assets index.html
2014-05-28-hello-and-welcome 2014-06-18-mother-s-kiss category page-2.html
root@as3:~/g4b1nagy-site2/dist# cd ..
root@as3:~/g4b1nagy-site2# cd config
root@as3:~/g4b1nagy-site2/config# ls
config.yaml page_attributes.yaml requirements.txt templates
root@as3:~/g4b1nagy-site2/config# nano config.yaml
(我修改了"posts_per_page" 的值为3)
root@as3:~/g4b1nagy-site2/config# cd ..
root@as3:~/g4b1nagy-site2# ls
config dist LICENSE manage.py README.md src
root@as3:~/g4b1nagy-site2# ./manage.py build
Building pages
root@as3:~/g4b1nagy-site2# cd dist
root@as3:~/g4b1nagy-site2/dist# ls
2014-05-28-an-older-post 2014-06-18-Ce-Shi-1 assets index.html
2014-05-28-hello-and-welcome 2014-06-18-mother-s-kiss category page-2.html
root@as3:~/g4b1nagy-site2/dist# nohup Rwebserver 34284 > /dev/null &
访问 http://as3.brite.biz:34284/即可看到网站效果。

发贴方法:
 root@as3:~/g4b1nagy-site2/dist# cd ../src
  root@as3:~/g4b1nagy-site2/src# nano 2014-06-18-mother-s-kiss.md
格式为:
===========================================================================
categories: ''
date: 2014-06-18 03:17
description: ''
icon: ''
ogimage: ''
script: ''
style: ''
template: post.html
title: !!python/unicode '妈妈的吻'
===========================================================================

葫芦丝曲。<!--more-->
此处为播放器的代码

然后,
  root@as3:~/g4b1nagy-site2/src# cd ..
root@as3:~/g4b1nagy-site2# ./manage.py build

演示站点:http://as3.brite.biz:34284/, http://gbng2.brite.biz.st
项目地址:https://github.com/g4b1nagy/helpful-site
https://github.com/g4b1nagy/helpful-site/issues/1#issuecomment-46425373