Last active
May 6, 2018 01:47
-
-
Save kyon0304/8900982 to your computer and use it in GitHub Desktop.
auto generate YAML front-matter for jekyll post, scrape a background image from bing and normalize it for post's header
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cover=`date --iso-8601=seconds | cut -d'+' -f1`.jpg | |
function getCover { | |
### get jpeg file from bing home page | |
url="http://cn.bing.com" | |
echo "Find header image..." | |
wget -q $url -O index.html | |
# jpgUrl=`cat index.html | grep background-image | awk -F\' '{print $2}'` | |
jpgUrl=`cat index.html | tr ";" "\n" | grep -o "url:'http://.*[.]jpg"| cut -d\' -f2` | |
echo "Start Fetch header image:" $jpgUrl | |
wget -q $jpgUrl -O $cover | |
echo "Fetch header image done." | |
rm index.html | |
### normalize jpg for header | |
convert $cover -resize 734x320^ -gravity center -extent 734x320 ../images/$cover | |
rm $cover | |
echo "normalize header image done." | |
} | |
function touchFile { | |
touch $fn | |
getCover | |
echo '---' >>$fn | |
echo 'title:' $title >> $fn | |
echo 'tags:' $tags >> $fn | |
echo 'cover:' $cover >> $fn | |
echo 'layout: post' >> $fn | |
echo '---' >> $fn | |
echo file $fn touched. | |
} | |
echo "Now enter title:" | |
read title | |
echo "Now enter tags:" | |
read tags | |
fn=`date -I`-$title.md | |
if [ -f $fn ]; then | |
echo file $fn exsits, remove it and recreate?[y/n] | |
read ans | |
if [ "$ans" = 'y' ]; then | |
rm $fn | |
oldCover=`grep cover: $fn | cut -d' ' -f2` | |
rm ../images/$oldCover | |
touchFile | |
else | |
echo please handle exist one: | |
fi | |
else | |
touchFile | |
fi | |
echo $fn | |
cat $fn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment