hexo不支持在线编辑功能,因此想到通过git同步windows下文件到github中,linux服务器再通过github同步,这样可以方便的进行本地进行文章的编辑,提交的话双击脚本在网站上就可以查看刚刚编辑好的内容,这样就可以省去了在服务器上操作的过程,全部在本地执行。
linux 端配置
初始化文件夹
先在GitHub上建好仓库,进入要同步的文件夹,进行同步
git config --global user.name "xxwdll"
git config --global user.email "gqoyvf@163.com"
cd /usr/blog/source/
git init
git clone git@github.com:xxwdll/myblog.git
cd myblog/
上传文件夹内容
cp ../_posts/* ./
git add .
git commit -m 'update'
git push -u origin master
cd ..
mv _posts _posts_bak
mv myblog _posts
更新脚本
将这个脚本设为定时脚本,定时从github上同步内容
1 * * * * /usr/blog/update_blog.sh
#!/bin/bash
cd /usr/blog/source/_posts
git fetch origin master:temp
git merge temp
git branch -d temp
windows 端配置
更新目录到本地
以后只需在widows端这个文件夹下进行编辑即可
git clone git@github.com:xxwdll/myblog.git
提交及更新脚本
#!/bin/bash
echo "1) update 2) commit"
read -p "input:" op
case $op in
1)
git fetch origin master:temp
git merge temp
git branch -d temp
;;
2)
git add .
git commit -m 'update'
git push origin master
;;
*)
echo "maybe something wrong............."
;;
esac
19/09/04更新
上面是个愚蠢的行为,定时脚本频率太过频繁,github已经把我IP封了
现在优化脚本,更新脚本如下:
#!/bin/bash
git fetch origin master:temp
git merge temp
git branch -d temp
推送脚本如下(需要绑定密钥):
#!/bin/bash
git add .
git commit -m 'update'
git push -u origin master
ssh root@推送的服务器IP <<EOF
cd /usr/blog
sh ./update_blog.sh
exit
EOF
网友评论