git(五)自动更新blog

这里的自动更新,并不是说人工智能时代可以不用写blog,都交给机器来写:)

当把markdown格式文件放在/root/Desktop目录下,再运行该脚本。

可以给图片添加水平,并且上传到搭建好的blog。

1
2
vi /root/.bashrc
alias update='cd /home/Whale3070.github.io;git add .;git commit -m "update";git push;cd /'

重启linux,输入update命令,即可更新本地blog到远程。

updateBlog.sh

输入文章标题,该输入内容会显示在更新的blog中。
输入该文章的类型。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash
#update blog
read -p "markdown name : " mdname
read -p "markdown acticle type? " itype
pic=`date +%m-%d-%I`
time=`date +%Y-%m-%d-%I`

mv /root/Desktop/*.md /root/Desktop/${time}-x.md
mv /root/Desktop/*.md /home/Whale3070.github.io/_posts
mkdir /home/Whale3070.github.io/img/${pic}
cp /root/Desktop/*.resource/* /home/Whale3070.github.io/img/${pic} && rm -rf /root/Desktop/*resource

cd /home/Whale3070.github.io/_posts
sed -i 's/\https://raw.githubusercontent.com/Whale3070/Whale3070.github.io/master/img/04-12-04/https:\/\/raw.githubusercontent.com\/Whale3070\/Whale3070.github.io\/master\/img\/'${pic}'/g' ${time}-x.md
python /root/tool/mark.py /home/Whale3070.github.io/img/${pic}

sed -i '1 i---' ${time}-x.md
sed -i "2 ititle: ${mdname}" ${time}-x.md
sed -i '3 icategories:' ${time}-x.md
sed -i "4 i- $itype" ${time}-x.md
sed -i '5 itags:' ${time}-x.md
sed -i "6 i- $itype" ${time}-x.md
sed -i "7 i---" ${time}-x.md

mark.py

/root/tool/i.png,是水印图片

1
2
3
4
5
6
7
8
9
10
11
12
import png
import Image
import sys
import os

wpath = sys.argv[1]

filelist = os.listdir(wpath)
for filename in filelist:
png_path = wpath+"/"+filename
mark = Image.open("/root/tool/i.png")
png.water(png_path,mark)