Total Pageviews

Tuesday, 8 April 2014

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

npm install -g lineman
会显示:
...
/root/npm/bin/lineman -> /root/npm/lib/node_modules/lineman/cli.js
...

as3:~# /root/npm/bin/lineman -h
  Usage: lineman [options] [command]
  Commands:
   new                     - generates a new lineman project in the specified folder : lineman new my-project
    run                     - runs the development server from /generated and watches files for updates
    build                   - compiles all assets into a production ready form in the /dist folder
as3:~# /root/npm/bin/lineman new lineman-site (此命令会在当前目录下,生成lineman-site目录)
显示:
- Assembling your new project directory in '/root/lineman-site'
- Created a new project in "lineman-site/" with Lineman. Yay!
Getting started:
  1. `cd lineman-site` into your new project directory'
  2. Start working on your project!
    * `lineman run` starts a web server at http://localhost:8000
    * `lineman build` bundles a distribution in the "dist" directory
    * `lineman clean` empties the "dist" and "generated" directories
    * `lineman spec` runs specs from the "specs" directory using testem
as3:~# cd lineman-site
as3:~/lineman-site# ls
app  config  Gruntfile.js  package.json  README.md  spec  tasks  vendor
as3:~/lineman-site# /root/npm/bin/lineman build (这个就是生成/更新静态网站的命令)
as3:~/lineman-site# ls
app     dist generated     package.json  spec   vendor
config  Gruntfile.js  README.md     tasks
(生成了dist和generated目录)
as3:~/lineman-site#
as3:~/lineman-site# git clone https://github.com/linemanjs/lineman-blog-template
as3:~/lineman-site# cd lineman-blog-template
as3:~/lineman-site/lineman-blog-template#
as3:~/lineman-site/lineman-blog-template# ls
app  config  Gruntfile.js  package.json  README.md  spec  tasks  vendor
as3:~/lineman-site/lineman-blog-template# npm install
as3:~/lineman-site/lineman-blog-template# ls
app     Gruntfile.js  package.json  spec   vendor
config  node_modules  README.md     tasks
as3:~/lineman-site/lineman-blog-template# /root/npm/bin/lineman build
as3:~/lineman-site/lineman-blog-template# ls
app     dist       Gruntfile.js  package.json  spec   vendor
config  generated  node_modules  README.md     tasks
(新出现了dist和generated目录)
as3:~/lineman-site/lineman-blog-template#
as3:~/lineman-site/lineman-blog-template# cd dist
as3:~/lineman-site/lineman-blog-template/dist# ls
about.html    css          index.html  js          posts
archive.html  favicon.ico  index.xml   plain.html
as3:~/lineman-site/lineman-blog-template/dist# nohup Rwebserver 36317 > /dev/null &
as3:~/lineman-site/lineman-blog-template/dist# cd ../generated
as3:~/lineman-site/lineman-blog-template/generated# ls
about.html    css          index.html  js          posts
archive.html  favicon.ico  index.xml   plain.html  template
as3:~/lineman-site/lineman-blog-template/generated# nohup Rwebserver 36318 > /dev/null &
访问http://as3.brite.biz:36317和http://as3.brite.biz:36318/即可看到网站效果。

发贴方法:
as3:~/lineman-site/lineman-blog-template/generated# cd ~/lineman-site/lineman-blog-template/app/posts/
as3:~/lineman-site/lineman-blog-template/app/posts# nano 2014-04-08-test1.md
格式如下:
---
title: "测试1,看看如何"
author:
  name: "ym"
date: "2014-04-08 23:45:10"
---

这是测试1.

注意:上面的date那行建议加上,否则发表的帖子不会按时间顺序排列。
然后,
as3:~/lineman-site/lineman-blog-template/app/posts# cd ~/lineman-site/lineman-blog-template/
as3:~/lineman-site/lineman-blog-template# /root/npm/bin/lineman build

演示站点:http://as3.brite.biz:36317/,http://as3.brite.biz:36318,
http://lm2.brite.biz.st
项目地址:https://github.com/linemanjs/lineman,
https://github.com/linemanjs/lineman-blog-template
http://www.linemanjs.com/

不过这个博客示例模板~/lineman-site/lineman-blog-template/还是简陋了点,我们可克隆程序作者的博客来使用。
as3:~/lineman-site/lineman-blog-template# cd ..
as3:~/lineman-site# git clone https://github.com/testdouble/double-takes double-takes-site
as3:~/lineman-site# cd double-takes-site
as3:~/lineman-site/double-takes-site# ls
app     Gemfile       Gruntfile.js  README.md  static  vendor
config  Gemfile.lock  package.json  spec       tasks
as3:~/lineman-site/double-takes-site# npm install
as3:~/lineman-site/double-takes-site# ls
app     Gemfile       Gruntfile.js  package.json  spec    tasks
config  Gemfile.lock  node_modules  README.md     static  vendor
as3:~/lineman-site/double-takes-site# npm install grunt-markdown-blog
as3:~/lineman-site/double-takes-site# /root/npm/bin/lineman build
as3:~/lineman-site/double-takes-site# ls
app     dist     Gemfile.lock  Gruntfile.js  package.json  spec    tasks
config  Gemfile  generated     node_modules  README.md     static  vendor
(新出现了dist和generated目录)
as3:~/lineman-site/double-takes-site# cd generated
as3:~/lineman-site/double-takes-site/generated# ls
archive.html  css  img  index.html  index.xml  js  posts  template  webfonts
as3:~/lineman-site/double-takes-site/generated# nohup Rwebserver 28375 > /dev/null &
as3:~/lineman-site/double-takes-site/generated# cd ../dist
as3:~/lineman-site/double-takes-site/dist# ls
archive.html  assets.json  css  img  index.html  index.xml  js  posts  webfonts
as3:~/lineman-site/double-takes-site/dist# nohup Rwebserver 28374 > /dev/null &
访问http://as3.brite.biz:28374和http://as3.brite.biz:28375/即可看到网站效果。
经实际测试http://as3.brite.biz:28375/要比http://as3.brite.biz:28374好,因为点击
http://as3.brite.biz:28375/右上角的三个绿色横杠图标,会弹出东西而http://as3.brite.biz:28374则不行。这表明http://as3.brite.biz:28375/所对应的generated目录才是真正的网站根目录,所以在绑定域名时,应绑定generated目录而非dist目录。

发贴方法:
as3:~/lineman-site/double-takes-site/dist# cd ..
as3:~/lineman-site/double-takes-site# cd app/posts
as3:~/lineman-site/double-takes-site/app/posts# nano 2014-04-08-test-a.md
---
title: "测试a,看看如何"
author:
  name: "ym"
date: "2014-04-08 23:45:10"
---

这是测试a.

然后,
as3:~/lineman-site/double-takes-site/app/posts# cd ../..
as3:~/lineman-site/double-takes-site# /root/npm/bin/lineman build

演示站点:http://as3.brite.biz:28375/,http://lm.brite.biz.st
项目地址:https://github.com/linemanjs/lineman,
https://github.com/testdouble/double-takes

还有一个博客站点blog.davemo.com的模板也可克隆下来使用。(这个有问题)
as3:~/lineman-site/double-takes-site# cd ..
as3:~/lineman-site# git clone https://github.com/davemo/blog.davemo.com blog.davemo.com-site
as3:~/lineman-site# cd blog.davemo.com-site
as3:~/lineman-site/blog.davemo.com-site# ls
app  config  Gruntfile.js  package.json  README.md  spec  tasks  vendor
as3:~/lineman-site/blog.davemo.com-site# npm install lineman-less
as3:~/lineman-site/blog.davemo.com-site# npm install