Articles written shell hexo new generation script

Foreword

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:
test
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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash


= 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

if [ $i = "1" ];then
Tags=`echo "$Tags" |sed -n "s/^[ ]*//gp"`
else
Tags=`echo "$Tags" |sed -n "s/^[ ]*//gp"|sed -n "s/ /,/gp"`
fi

echo "---" >>"$CurFile"
echo "title: $CurTitle" >>"$CurFile"
echo "category: [$Category]" >>"$CurFile"
echo "tags: [$Tags]" >>"$CurFile"
echo "toc: true" >>"$CurFile"
echo "date: $Date" >>"$CurFile"
echo "---" >>"$CurFile"

done




Reprint please indicate the original content Chai Kun-yan and the source http://ykzhai.top/2017/02/09/ field / hexo / write shell hexo new article generated script /
 

Original: Large column  written a new article generated script shell hexo


Guess you like

Origin www.cnblogs.com/wangziqiang123/p/11618389.html