Skip to content

Instantly share code, notes, and snippets.

@wzpan
Last active February 19, 2019 13:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wzpan/9636385 to your computer and use it in GitHub Desktop.
Save wzpan/9636385 to your computer and use it in GitHub Desktop.
A script to help me generate hexo blog and publish it to gitcafe.
#!/bin/zsh
CUR_DIR=$PWD
HEXO=/Users/wzpan/Documents/workspace/repositories/hexo-blog
PUBLISH=/Users/wzpan/Documents/workspace/repositories/wzpan
CSS=$HEXO/themes/bootstrap/source/css
JS=$HEXO/themes/bootstrap/source/js
DIST=$HEXO/themes/bootstrap/source/dist
PUBLIC=$HEXO/public
cd $HEXO
hexo clean
# Compress stylesheets and Javascripts
cd $CSS
for file in `basename -s .css *.css`;do
yuicompressor ${file}.css -o $DIST/${file}.min.css
done
cd $JS
for file in `basename -s .js *.js`;do
yuicompressor ${file}.js -o $DIST/${file}.min.js
done
# Generate blog
cd $HEXO
hexo generate
# Publish blog
echo -n "Copy the compiled result to your site repo?[y/n]"
read copy_yn
if [ "$copy_yn" = "y" ]; then
if [ -d $PUBLISH ]
then
cd $PUBLISH
rm -r *
fi
cd $HEXO
cp -av $PUBLIC/* $PUBLISH/
echo -n "Update your site repo?[y/n]"
read update_site_yn
case "$update_site_yn" in
y )
cd $PUBLISH
git add --all
echo -e "\033[34m Please enter commit message: \033[0m"
read commit_message
git commit -m $commit_message
git push -u origin gitcafe-pages:gitcafe-pages
cd -
echo "Congrats! The site repo has been updated"
cd $HEXO
git add --all
git commit -m $commit_message
git push
cd -
echo "Congrats! The blog repo has been updated"
;;
n )
echo "Don't copy them this time."
;;
*)
echo "Please enter y or n."
exit 1
;;
esac
elif [ "$copy_yn" = "n" ]; then
echo "Don't copy them this time."
else
echo "Please enter y or n."
exit 1
fi
echo "All done!"
cd $CUR_DIR
exit 0
@mlosun
Copy link

mlosun commented May 7, 2014

我对这个不是很熟,自己大致理解了一下代码,麻烦看下对么?

首先定义自己hexo博客的路径,以及主题的css、js、images等
然后定义username.github.com和hexo public文件夹的路径

打开hexo文件夹执行hexo clean
然后hexo generate
然后询问是否重新编译,如果yes
询问是否更新站点
输入commit信息
提交更新
all done

然后使用git推送username.github.com的本地仓库到github上

@wzpan
Copy link
Author

wzpan commented Sep 20, 2014

@piratf
Copy link

piratf commented Dec 27, 2014

你好,请问这个PUBLISH路径是做什么用的?

@wzpan
Copy link
Author

wzpan commented Mar 10, 2015

@piratf , 渲染出来的页面的仓库所在路径。

@baininghan
Copy link

@wzpan 学习了,这个应该是mac用的吧,有没有windows的?:)

@wzpan
Copy link
Author

wzpan commented Mar 10, 2015

@baininghan , 这里头只用到了一个跨平台的 java 工具 YuiCompressor 用于压缩 js 和 css ,不需要压缩的可以去掉相关语句。没有什么平台特定的命令或语法。如果你需要在 Windows 下使用,只需装一个 msys 环境即可。git 自带的 msys 应该就已满足需求。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment