-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnewPost.sh
More file actions
executable file
·74 lines (64 loc) · 1.17 KB
/
newPost.sh
File metadata and controls
executable file
·74 lines (64 loc) · 1.17 KB
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
# Use : ./newPost.sh "post title"
# Usage instruction function
function usage {
if [ $# -gt 0 ] ; then
echo
echo "$*"
echo
fi
echo 'usage: newPost.sh [--title "New article" --date 2014-04-17] | [-h]]'
}
# Script options analyze
while [ "$1" != "" ]; do
case $1 in
--title ) shift
TITLE=$1
;;
--date ) shift
DATE=$1
;;
-h | --help ) usage
exit
;;
* ) usage "The option is not recognized"
exit 1
esac
shift
done
# Domain exceptions
if [ -z "$TITLE" ]
then
echo "Title not specified"
exit 1
fi
if [ -z "$DATE" ]
then
DATE=$(date +"%Y-%m-%d")
fi
TITLE_NORMALIZED=$(echo $TITLE | iconv -f utf8 -t ascii//TRANSLIT//IGNORE | tr "[:upper:]" "[:lower:]" | tr ", '" "---")
FILENAME="$DATE-$TITLE_NORMALIZED.md"
# Pull the repository
git pull
# Make new article
POST=$(cat <<POST
---
comments: true
date: $DATE
layout: post
slug: $TITLE_NORMALIZED
title: $TITLE
categories:
- web
tags:
- blog
---
content
POST
)
printf "%b\n" "$POST" > _posts/$FILENAME
# Show new article's path
echo "_posts/$FILENAME"
# Show git helper commands
echo "git add ."
echo "git commit -m \"$TITLE\""
echo 'git push'