Total Pageviews

Thursday, 17 October 2013

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

# gem install cri
# git clone git://github.com/nanoc/nanoc.git
# cd nanoc
# gem build nanoc.gemspec
# gem install nanoc-*.gem (至此nanoc安装完毕.建议不要用gem install nanoc的方式来安装nanoc,否则容易出错
as3:~/nanoc# ls
bin              doc      Gemfile.lock  nanoc.gemspec  README.md
ChangeLog        false    lib           NEWS.md        tasks
CONTRIBUTING.md  Gemfile  LICENSE       Rakefile       test
as3:~/nanoc# cd bin
as3:~/nanoc/bin# ls
nanoc (这个nanoc文件就是执行文件
as3:~/nanoc/bin# ~/nanoc/bin/nanoc --version (或者nanoc --version也行)
nanoc 3.7.0 © 2007-2013 Denis Defreyne.
Running ruby 2.0.0 (2013-05-14) on i686-linux with RubyGems 2.0.2. (表明安装nanoc成功)
 as3:~/nanoc/bin# ln -s ~/nanoc/bin/nanoc /usr/local/bin/nanoc
as3:~/nanoc/bin# nanoc create-site nanocblog (在当前目录~/nanoc/bin下会自动新建
nanocblog目录)
as3:~/nanoc/bin# ls
nanoc  nanocblog
as3:~/nanoc/bin# cd nanocblog
as3:~/nanoc/bin/nanocblog# nanoc compile (这个就是生成静态网站的命令。每次发布/修改帖子后,都要运行一次该命令)
as3:~/nanoc/bin/nanocblog# cd output
as3:~/nanoc/bin/nanocblog/output# ls
index.html  style.css
as3:~/nanoc/bin/nanocblog/output# (这个~/nanoc/bin/nanocblog/output/目录就是静态网站的根目录。你可绑定一个域名到该目录。示例:http://nn.brite.biz/ )
as3:~/nanoc/bin/nanocblog/output# cd ..
as3:~/nanoc/bin/nanocblog# gem install adsf
as3:~/nanoc/bin/nanocblog# nohup nanoc view > /dev/null &  (打开浏览器,访问http://ur-vps-hostname:3000,即可预览新建的站点。我的例子- http://as3.brite.biz:3000,
如果想指定其他端口,比如6666,则 nohup nanoc view --port 6666 > /dev/null &)

 创建一个页面的命令,比如要创建一个about页面,用命令nanoc create-item about即可:
 as3:~/nanoc/bin/nanocblog# nanoc create-item about (可访问http://nn.brite.biz/about/体验一下,但在首页却未显示http://nn.brite.biz/about/的链接。)

以上安装的网站 http://nn.brite.biz太简陋了。我们去克隆别人的站点,为己所用-
 as3:~/nanoc/bin/nanocblog# cd ~/nanoc/
as3:~/nanoc# git clone https://github.com/avdgaag/arjanvandergaag.nl arjanvandergaag.nl-site
as3:~/nanoc# cd arjanvandergaag.nl-site
as3:~/nanoc/arjanvandergaag.nl-site# ls
config.yaml  Gemfile       layouts     Rules
content      Gemfile.lock  lib            README.md 
as3:~/nanoc/arjanvandergaag.nl-site# nanoc compile  (这个就是生成/更新静态网站的命令)
 as3:~/nanoc/arjanvandergaag.nl-site# ls
config.yaml  Gemfile       layouts  output     Rules
content      Gemfile.lock  lib      README.md  tmp
(新出现了output目录)
 as3:~/nanoc/arjanvandergaag.nl-site# cd output
as3:~/nanoc/arjanvandergaag.nl-site/output# ls
blog  feed.xml  images  index.html  projects.html  script.js  styles.css
(可见~/nanoc/arjanvandergaag.nl-site/output/就是静态网站的根目录)
as3:~/nanoc/arjanvandergaag.nl-site/output# nohup Rwebserver 45326 > /dev/null &
as3:~/nanoc/arjanvandergaag.nl-site/output#
访问http://as3.brite.biz:45326/就可看到网站效果。

发贴方法:
as3:~/nanoc/arjanvandergaag.nl-site/output# cd ..
as3:~/nanoc/arjanvandergaag.nl-site# ls
config.yaml  Gemfile       layouts  output     Rules
content      Gemfile.lock  lib      README.md  tmp
as3:~/nanoc/arjanvandergaag.nl-site# cd content/blog
as3:~/nanoc/arjanvandergaag.nl-site/content/blog#  nano test1.md
按~/nanoc/arjanvandergaag.nl-site/content/blog/里面的某个md文件的内容格式,新建帖子test1.md,格式如下:
---
created_at: 2014-02-17 15:37:01
tags:
  - misc1
  - misc2
kind: article
title: test1
---

这是测试1.


然后,
as3:~/nanoc/arjanvandergaag.nl-site/content/blog# cd ~/nanoc/arjanvandergaag.nl-site
as3:~/nanoc/arjanvandergaag.nl-site# nanoc compile

演示站点:http://as3.brite.biz:45326/,http://nn.brite.biz.st
克隆的源码地址:https://github.com/avdgaag/arjanvandergaag.nl

一个用Nanoc and Susy(http://www.oddbird.net/susy/) 搭建的静态博客:
http://chriseppstein.github.io/blog/
http://arjanvandergaag.nl/ (一个用nanoc搭建的网站,源码为
https://github.com/avdgaag/arjanvandergaag.nl)
http://zacharyvoase.com  (The nanoc-powered source:
https://github.com/zacharyvoase/zacharyvoase.com,
https://github.com/zacharyvoase/blog.zacharyvoase.com)
 https://github.com/zmanji/zameermanji.com (Nanoc Powered.)
https://github.com/jakubgarfield/chodounsky.net  (Nanoc Powered.)
-------------------------------------------------------



  • Nanoc - Static Website Generator - Creating Simple Site with Nanoc
  • Nanoc - Static Website Generator - Nanoc Project Structure
  • Nanoc - Static Website Generator - Blogging with Nanoc