Total Pageviews

Tuesday, 14 January 2014

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

gem install serve
serve create serve-site (此命令会在当前目录下,生成serve-site目录)
cd serve-site
serve export output (此命令会在当前目录下,生成output目录)

as3:~/serve-site# serve export output
    compiled  sass files
    compiled  output/layouts/default.html
    compiled  output/welcome.html
    compiled  output/index.html
      copied  output/.htaccess
      copied  output/images/serve-logo.png
      copied  output/stylesheets/screen.css
as3:~/serve-site# ls
compass.config  Gemfile       output  README.md    tmp
config.ru       Gemfile.lock  public  stylesheets  views
as3:~/serve-site# cd output
as3:~/serve-site/output# ls
images  index.html  layouts  stylesheets  welcome.html
as3:~/serve-site/output#
可见~/serve-site/output/就是静态网站的根目录。

发贴方法:
as3:~/serve-site/output# cd ../views/
as3:~/serve-site/views# ls
index.redirect  _layout.html.erb  layouts  view_helpers.rb  welcome.html.erb
as3:~/serve-site/views# mv index.redirect index.redirect.bak
as3:~/serve-site/views# cp welcome.html.erb welcome.html.erb.bak
as3:~/serve-site/views# mv welcome.html.erb index.html.erb
as3:~/serve-site/views# ls
index.html.erb      _layout.html.erb  view_helpers.rb
index.redirect.bak  layouts           welcome.html.erb.bak
as3:~/serve-site/views# nano test1.html.erb
test1.html.erb的格式为:
<h2>测试1</h2>
这是测试1.

然后,
as3:~/serve-site/views# cd ..
as3:~/serve-site# serve export output (这个就是生成/更新静态网站的命令)

演示站点:http://as3.brite.biz:32981/,http://as3.brite.biz:32981/test1.html,
http://as3.brite.biz:32981/test2.html,http://as3.brite.biz:32981/fengyuwuzu.html
http://as3.brite.biz:32981/chinese-economy.html
项目地址:https://github.com/jlong/serve,
官网:http://get-serve.com/

这个程序跟以前说的好几个程序一样,所发表的文章的超链并不会自动出现在首页。可这样处理:
(编辑源帖所在目录里的index文件)
as3:~/serve-site# nano views/index.html.erb
在index.html.erb的最上一行加入:
<p><a href=/test1.html>测试1</a></p>
<p><a href=/test2.html>测试2</a></p>
<p><a href=/fengyuwuzu.html>风雨无阻</a></p>
<p><a href=/chinese-economy.html>中国经济</a></p>

然后运行serve export output,更新一下静态网站。