-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpublish.sh
executable file
·80 lines (69 loc) · 1.94 KB
/
publish.sh
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
#!/bin/bash
# Script to publish a post into the _posts folder and take care of the annoying details,
# like entering the date and getting the filename right.
if [ -z $1 ]; then
echo Usage: $0 post-source-file
exit 1
fi
postsrc=$1
year="00"
month="00"
date="00"
hour="00"
minute="00"
second="00"
read_manual_date() {
read -p "Enter year: " year
read -p "Enter month as a 2-digit number: " month
read -p "Enter date as a 2-digit number: " date
read -p "Enter hour as a 2-digit number: " hour
read -p "Enter minute as a 2-digit number: " minute
read -p "Enter second as a 2-digit number: " second
}
good_date() {
echo "Your date is $1"
read -p "Is this correct? [Yn] " yn
case $yn in
[Nn]* ) return 1
esac
return 0
}
# get title from the post title
title=$(grep -m 1 '^title' $postsrc | sed -e 's/^title: *//' -e 's/"//g')
echo The title is:
echo $title
read -p "Is this correct? [Yn] " yn
case $yn in
[Nn]* ) echo "Fix the title and start over."; exit 1;;
esac
# same for the author, although this doesn't get used
echo The author is:
echo $(grep -m 1 '^author' $postsrc | sed -e 's/^author: *//' -e 's/"//g')
read -p "Is this correct? [Yn] " yn
case $yn in
[Nn]* ) echo "Fix the author and start over."; exit 1;;
esac
read -p "Set a publish date of right now? [Yn] " yn
case $yn in
[Nn]* )
echo "Entering the publish date manually."
while [ 1 ]; do
read_manual_date
timestamp="$year-$month-$date $hour:$minute:$second"
if good_date "$timestamp"; then
break
fi
done;;
[Yy]*|* ) timestamp=$(date +"%Y-%m-%d %H:%M:%S");;
esac
dateonly=$(echo $timestamp | sed 's/ .*$//g')
convtitle=$(echo $title | awk '{print tolower($0)}' | sed 's/ /-/g')
destfile="_posts/$dateonly-$convtitle.md"
cp -i $postsrc $destfile
echo "Successfully copied into _posts."
read -p "Remove your original file? [yN] " yn
case $yn in
[Yy]* ) rm $postsrc
esac
sed -i "s/^date: .*$/date: $timestamp/" $destfile
# echo $timestamp