Total Pageviews

Wednesday, 5 April 2017

搭建基于nodejs的静态博客程序leo.im

首先搭建nodejs环境,最好为6.x版。

cd /usr/local
git clone https://github.com/leo/site leo.im
cd leo.im

root@localhost:/usr/local/leo.im# ls
components  layouts  package.json  readme.md
data        license.md   pages         static
root@localhost:/usr/local/leo.im# npm install
root@localhost:/usr/local/leo.im# ls
components  layouts     node_modules   package.json  readme.md
data        license.md   pages         static
root@localhost:/usr/local/leo.im#

新建源帖:
root@localhost:/usr/local/leo.im# cd pages
root@localhost:/usr/local/leo.im/pages# ls
2013  2014  2015  2016  2017  essays.js  index.js
root@localhost:/usr/local/leo.im/pages# cd 2017
root@localhost:/usr/local/leo.im/pages/2017# nano test-1.js (test-1.js就是源帖)
root@localhost:/usr/local/leo.im/pages/2017# cat test-1.js
// Layouts
import Post from '../../layouts/essay';

// Components
import P from '../../components/paragraph';
import Link from '../../components/link';
import Meta from '../../components/meta';

export default () => (
  <Post>
    <Meta id="test-1" />

    <p>这是测试1.</p>
<p>看看如何?</p>
  </Post>
);

root@localhost:/usr/local/leo.im/pages/2017# cd ../..
root@localhost:/usr/local/leo.im# cd data
root@localhost:/usr/local/leo.im/data# ls
essays.json
root@localhost:/usr/local/leo.im/data# nano essays.json
(在essays.json文件最上面的第二行"{“的上方加上:
 {
    "id": "test-1",
    "title": "测试1",
    "date": "05-04-2017"
  },

root@localhost:/usr/local/leo.im/data# cd ..
root@localhost:/usr/local/leo.im# npm run dev -- -p 3001 > /dev/null &

以后要新建源帖的话,只需按上面的步骤新建js文件,还要记得修改essays.json文件。然后,
lsof -i:3001 查看npm所占用的进程号,比如2678。
kill 2678
lsof -i:3001 (确保此次显示的内容为空)
cd  /usr/local/leo.im
root@localhost:/usr/local/leo.im# npm run dev -- -p 3001 > /dev/null &

演示网站:http://gcv.bright.biz.st:3001,http://gcv.bright.biz.st:3001/essays

有问题!


No comments:

Post a Comment