Stackedit 是一個 online markdown editor,功能非常強大。4.0 版還支援了 UML。雖然官方可以免費直接用,但是官方試用的平台把存檔成 pdf 的功能關閉了,因此決定要來嘗試自己裝。(裝完之後才發現,PDF功能依然還是鎖定了Orz)

Install Node.JS

根據學弟給的建議,NodeJS 跟 Ruby 一樣,最好可以透過 version manager 來安裝與管理,也就是 NVM

安裝步驟如下: (一般 user 身份即可)

  • 安裝 NVM
curl https://raw.githubusercontent.com/creationix/nvm/v0.19.0/install.sh | bash
source ~/.nvm/nvm.sh
echo 'source ~/.nvm/nvm.sh' >> .profile
  • 安裝 NodeJS
nvm install stable
nvm alias default stable

Install Stackedit

sudo apt-get install git
git clone https://github.com/benweet/stackedit
cd stackedit
npm install -g bower
npm install -g gulp
npm install
bower install --save
gulp

在執行 npm install 時,出現了以下 error :

stackedit@stackedit:~$ npm install --no-bin-link
npm WARN deprecated gulp-clean@0.3.1: use gulp-rimraf instead
npm ERR! Failed resolving git HEAD (git://github.com/RobinThrift/gulp-requirejs.git) fatal: bad object 6fb08d427dda7463a07b25be3fc931f58e660b54
npm ERR! Failed resolving git HEAD (git://github.com/RobinThrift/gulp-requirejs.git) 
npm ERR! Error: Command failed: fatal: bad object 6fb08d427dda7463a07b25be3fc931f58e660b54
npm ERR! 
npm ERR!     at ChildProcess.exithandler (child_process.js:648:15)
npm ERR!     at ChildProcess.emit (events.js:98:17)
npm ERR!     at maybeClose (child_process.js:756:16)
npm ERR!     at Socket.<anonymous> (child_process.js:969:11)
npm ERR!     at Socket.emit (events.js:95:17)
npm ERR!     at Pipe.close (net.js:465:12)
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR!     <http://github.com/npm/npm/issues>

npm ERR! System Linux 3.13.0-36-generic
npm ERR! command "/opt/stackedit/.nvm/v0.10.33/bin/node" "/opt/stackedit/.nvm/v0.10.33/bin/npm" "install"
npm ERR! cwd /opt/stackedit
npm ERR! node -v v0.10.33
npm ERR! npm -v 1.4.28
npm ERR! code 128
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /opt/stackedit/npm-debug.log
npm ERR! not ok code 0
stackedit@stackedit:~$

google 了一下"猜測"大概是 gulp-requirejs.git 已經沒有 6fb08d427dda7463a07b25be3fc931f58e660b54 這個 commit (亂猜的,未經求證)

因此我去 GitHub 上查了一下,gulp-requirejs.git 最新的 commit 是 e97aac03bfc3f6aadd3b68da32e6e44fc8c75d06

然後修改 stackedit/package.json,將

"gulp-requirejs": "git://github.com/RobinThrift/gulp-requirejs.git#6fb08d427dda7463a07b25be3fc931f58e660b54"

改成

"gulp-requirejs": "git://github.com/RobinThrift/gulp-requirejs.git#e97aac03bfc3f6aadd3b68da32e6e44fc8c75d06"

然後重新再 run 一次 npm install 就過了

Start Daemon

Run command

export PORT=3000 && node server.js

Upstart

建立一個新檔案 /etc/init/stackedit.conf,並新增以下內容:

/etc/init/stackedit.conf
# Stackedit - an opensource online markdown editor
#

description "Stackedit"

start on runlevel [2345]
stop on runlevel [!2345]

setuid stackedit
setgid stackedit

exec /opt/stackedit/.nvm/v0.10.33/bin/node /opt/stackedit/server.js

然後建立 upstart link

cd /etc/init.d
sudo ln -s /lib/init/upstart-job stackedit

接下來就可以利用 service 指令來啟動/關閉 stackedit

sudo service stackedit start

利用 netstat 檢查是否有提供服務

user@localhost:~$ sudo netstat -tnlup | grep 3000
tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN      29780/node

參考資料

Comments

comments powered by Disqus