用vim写博客(vim+git+gitblog)

用vim写博客,git上传

一、gitblog安装配置

详见https://github.com/jockchou/gitblogdoc/tree/master/posts/gitblog

二、git与vim在服务器和客户端安装

三、服务器端git配置

以www.junzilou.com为例

1.各种前提

nginx设置的root: /var/www.junzilou.com

/var/www.junzilou.com的拥有者hehe

nginx.conf中的user:www-data

git的裸仓库位置:/var/bare/www.junzilou.com.git

/var/bare/www.junzilou.com.git的拥有者hehe

2.操作流程

下面所有操作以用户hehe操作

sudo mkdir -v /var/bare 
sudo chown -R hehe:hehe /var/bare
cd /var/bare
git init --bare www.junzilou.com.git
cd /var 
git clone /var/bare/www.junzilou.com.git
cd /var/bare/www.junzilou.com.git/hooks/
vim post-receive

post-receive内容如下

#!/bin/sh
#
# An example hook script to prepare a packed repository for use over
# dumb transports.
#
# To enable this hook, rename this file to "post-update".

#exec git update-server-info


#author: embbnux
#Blog of Embbnux: http://www.embbnux.com

#判断是不是远端仓库
IS_BARE=$(git rev-parse --is-bare-repository)
if [ -z "$IS_BARE"  ]; then
        echo >&2 "fatal: post-receive: IS_NOT_BARE"
        exit 1
fi
unset GIT_DIR
DeployPath="/var/www.junzilou.com"

echo "==============================================="
cd $DeployPath
echo "deploying the test web"

#git stash
#git pull origin master
git fetch --all
git reset --hard origin/master

time=`date`
echo "web server pull at webserver at time: $time."
echo "================================================"

四、客户端

此客户端windows和linux均可,但均需要安装有git、ssh、vim

下面命令以linux为例,windows略

git clone ssh://[email protected]//var/bare/www.junzilou.com.git
git clone https://github.com/jockchou/gitblog.git
cd gitblog/app
rm -rfv cache
cd ..
rm -rfv .git 
cp -rv * ../www.junzilou.com
cd ../www.junzilou.com/blog
vim test.md # test.md文件就是要上传的博客文档,将要写的内容写好保存退出vim
git add ./*
git commit -m "test"
git push origin master #到此处成功了,则可以打开www.junzilou.com/test.html查看刚才写的博客了

四、注意

使用这种方法需要删除gitblog的app下面的cache目录,前面命令已经展示了

添加新评论