Recently nothing else, have for a long time did not write the article, and found that each time a new article hexo of time in copy and paste some configuration, it is quite troublesome, just some time ago studied under shell programming, then use the shell to write a script automatically generated.
Instructions
Assume the name of a shell script is newFile.sh, execute the following command:
1
newFile.sh test file -c programming shell -t shell hexo
Wherein the parameters are as follows:
-c: Classification creates a corresponding directory in hexo / source / _posts directory based on the value of this parameter
-t: Tags can add tags in the article based on this parameter value
After the execution, it will create a new directory in your blog hexo _posts in respective directories and files, FIG follows:
the generated content files as follows:
1 2 3 4 5 6 7
title: Test file category: [programming, the shell] Tags: [the shell, HEXO] TOC: to true DATE: 2017 -02 -09 09 : 38 is: 25
This way you save a lot of things, every province, and then copy and paste,
Script content
Use script is very simple, you need to first before using scripts written _post directory to save, then you can use the script reads as follows:
= Tags the Category = the Title = CurState = "title" IsParam = "to true" PostPath = "/ E / Blog / Source / _posts /" # will be replaced here for you _posts directory address # PostPath = "./" a Date = ` +% F` DATE a Date = "$ DATE +% T` `a Date"
if [ "$#" -lt "1" ];then echo "Input Error" exit fi
i=0 j=0 for argv in $* do #echo$argv if [ $argv = "-t" ];then CurState="Tags" IsParam="true" elif [ $argv = "-c" ];then CurState="Category" IsParam="true" else IsParam="false" fi
if [ $IsParam = "false" ];then if [ $CurState = "Tags" ];then let i++ Tags="$Tags $argv" elif [ $CurState = "Category" ];then let j++ Category="$Category $argv" else Title="$Title $argv" fi fi done
#echo"Tags=$Tags" #echo"Category=$Category" #echo"Title=$Title" #echo"CurDate=$Date" for path in $Category do if test -d "$PostPath$path" ; then PostPath="$PostPath$path/" continue else mkdir $PostPath$path PostPath="$PostPath$path/" fi done for CurFile in $Title do
cd $PostPath mkdir $CurFile CurTitle=$CurFile CurFile="$CurFile.md" if [ $j = "1" ];then Category=`echo "$Category" |sed -n "s/^[ ]*//gp"` else Category=`echo "$Category" |sed -n "s/^[ ]*//gp"|sed -n "s/ /,/gp"` fi