Total Pageviews

Sunday, 7 August 2016

搭建基于nodejs的静态博客程序pub-server

登陆vps,
npm install -g pub-server
安装后,得到的可执行文件为pub.

cd /usr/local
git clone https://github.com/jldec/pubblog-src
cd pubblog-src

root@AR:/usr/local/pubblog-src# ls
CNAME markdown      pub-config.js
images package.json  README.md
root@AR:/usr/local/pubblog-src# npm install
(因为存在package.json文件,  所以运行npm install以安装程序所指定的node模块)
root@AR:/usr/local/pubblog-src# npm run generate  (这个就是生成/更新静态网站的命令)
root@AR:/usr/local/pubblog-src# ls
CNAME markdown      out     pub-config.js
images node_modules  package.json  README.md
(生成了out目录)
root@AR:/usr/local/pubblog-src# cd out
root@AR:/usr/local/pubblog-src/out# ls
about.html
CNAME
css
feature-wishlist-for-github-pages.html
fonts
images
index.html
js
pub
publishing-html-on-github-pages.html
pub-server-fragments.html
README.md
robots.txt
sitemap.xml
why-the-web-needs-better-html-editing-components.html
root@AR:/usr/local/pubblog-src/out#
(/usr/local/pubblog-src/out/里面有index.html文件,所以/usr/local/pubblog-src/out/就是静态网站的根目录)

新建源贴:
root@AR:/usr/local/pubblog-src/out# cd ..
root@AR:/usr/local/pubblog-src# ls
CNAME markdown      out     pub-config.js
images node_modules  package.json  README.md
root@AR:/usr/local/pubblog-src# cd markdown
root@AR:/usr/local/pubblog-src/markdown# ls
about.md
feature-wishlist-for-gh-pages.md
home.md
publishing-html-on-github-pages.md
pub-server-fragments.md
why-the-web-needs-better-html-editing-components.md
root@AR:/usr/local/pubblog-src/markdown# nano test-1.md
(根据feature-wishlist-for-gh-pages.md的格式,新建帖子test-1.md,内容如下:
---- /test-1 ----
name: 测试1
image: /images/cover-me.jpg
date: 2016-08-07 21:31
template: post

这是测试1.看看如何呢? )
root@AR:/usr/local/pubblog-src/markdown# cd ..
root@AR:/usr/local/pubblog-src# npm run generate

演示网站:http://pub.smt.biz.st
需在里面的帖子的url地址后加上.html后,才能访问。(我的webserver是nginx,还需了解一下如何设置url重写规则以去掉.html后缀。
项目地址:
https://github.com/jldec/pub-server
(http://jldec.github.io/pub-doc/installation)
https://github.com/jldec/pubblog-src

PS:
其实帖子的url地址问题的简单解决办法:
就是修改源贴中的/test-1/test-1.html即可。