shell: 使用 shell 脚本将博客同时提交至 github 和 gitcafe
June 4, 2015
由于 github 的访问速度比较慢,所以也选择了跟很多同学一样,选择了同时将 blog 部署至 github 和 gitcafe。
因此在写完博客之后需要执行
这里的前提是已经搭建好自己的博客,并会使用命令进行博客的创建、提交等等。。
下面进入正题
Table of Contents
同时提交至 github 与 gitcafe
-
这里假设你的博客根目录为 hexo,先确保该目录下的
_config.yml
文件的最后一行的内容为
type: git这里贴出最后几行的内容:
# Docs: http: //hexo.io/docs/deployment.html deploy: type: git
这里我没将 github 或者 gitcafe 的地址配进去,而是放在了后面的 shell 脚本当中
-
我的 gitcafe 仓库:
repo: https: //gitcafe.com/xuxu1988/xuxu1988.git branch: gitcafe-pages
github 仓库:
repo: https: //github.com/gb112211/gb112211.github.io.git branch: master
-
正常配置是将上面的仓库地址配在
type: git
的后面,这样才能提交,很笨的方法是先配置 github 的地址,提交后再将地址替换为 gitcafe的,接在再提交,相当于提交 2 次,可以想象,相当的累人 -
笨方法虽然手工的去执行,会很麻烦,但业务逻辑确实是如此,接下来通过 shell 脚本完成该功能,那么提交起来就相当的方便而且快速,这里直接将脚本 commit.sh 贴出(用的 Mac 环境):
#!/bin/sh hexo g #提交至 gitcafe #先将gitcafe 的地址追加到 _config.yml 的末尾,注意空格 echo " repo: https://gitcafe.com/xuxu1988/xuxu1988.git>" >> _config.yml echo " branch: gitcafe-pages>" >> _config.yml #提交 hexo d #删除gitcafe配置 sed -i '' '$d' _config.yml sed -i '' '$d' _config.yml #提交至github echo " repo: https://github.com/gb112211/gb112211.github.io.git>" >> _config.yml echo " branch: master>" >> _config.yml hexo d #删除github配置 sed -i '' '$d' _config.yml sed -i '' '$d' _config.yml
流程相当的简单,linux 下的话,sed 命令的 -i 选项后面应该不需要
”
,两个单引号,Mac 环境的按脚本中的格式写 -
脚本写好之后,执行
chmod +x commit.sh
,赋予可执行的权限后就可以以
./commit.sh
的方式提交博客了[xuxu: ~/blog/ hexo]$ ./commit.sh INFO Files loaded in 1.6 s INFO Generated: baidu_verify_0ZcfvtBusx.html INFO Generated: 2015 /05/ 16 /config-my-hexo/ index.html INFO Generated: 2015 /05/ 15 /android-adb-commands/ index.html INFO Generated: 2015 /05/ 14 /2015-05-02-Instrumentation01/ index.html INFO Generated: 2015 /05/ 14 /2015-05-02-Monkey/ index.html INFO Generated: 2015 /05/ 13 /2015-05-02-Android-Tree/ index.html INFO Generated: 2015 /05/ 12 /2015-05-02-MeiYiBu-XuXiaofeng/ index.html INFO Generated: archives/index.html INFO Generated: archives/2015/ index.html INFO Generated: archives/2015/ 05 /index.html INFO Generated: tags/其他/ index.html INFO Generated: tags/Android/ index.html INFO Generated: tags/测试基础/ index.html INFO Generated: tags/Monkey/ index.html INFO Generated: tags/粤语歌曲/ index.html INFO Generated: tags/Instrumentation/ index.html INFO Generated: tags/自动化/ index.html INFO Generated: index.html INFO Generated: categories/技术/ index.html INFO Generated: categories/音乐/ index.html INFO Generated: sitemap.xml INFO Generated: atom.xml INFO 22 files generated in 333 ms INFO Deploying: git INFO Clearing .deploy folder... INFO Copying files from public folder... [master 1 f2fbc6] Site updated: 2015 -05 -16 13 :53 :58 9 files changed, 16 insertions(+), 16 deletions(-) To https: //gitcafe.com/xuxu1988/xuxu1988.git 283 f9fd..1 f2fbc6 master -> gitcafe-pages Branch master set up to track remote branch gitcafe-pages from https: //gitcafe.com/xuxu1988/xuxu1988.git. INFO Deploy done: git INFO Deploying: git INFO Clearing .deploy folder... INFO Copying files from public folder... On branch master nothing to commit, working directory clean To https: //github.com/gb112211/gb112211.github.io.git 283 f9fd..1 f2fbc6 master -> master Branch master set up to track remote branch master from https: //github.com/gb112211/gb112211.github.io.git. INFO Deploy done: git
快速创建并打开 md 文档
通常我们用
-
使用 hexo new 命令创建博客后,使用 Mou.app 打开创建好的 md 文档,脚本
new.she
的内容如下:#!/bin/sh #文件名 filename=$@ file=./source /_posts/$filename .md #判断是否已经存在 if [ ! -e "$file >" ] then #不存在则新建博客并用Mou打开 hexo new $filename open -a /Applications/Mou.app $file else #存在则提示博客名已经存在 echo "This blog already exists!>" fi
new.sh 接收一个参数作为博客名
-
脚本完成之后,同样地执行
chmod +x new.sh
, 然后执行脚本
./new.sh my-blog
,如果不存在,就会创建博客,并使用 Mou.app 这个应用程序打开 my-blog.md 这个文档
0 Comments