-
Notifications
You must be signed in to change notification settings - Fork 62
/
createNextMonth
executable file
·72 lines (55 loc) · 1.31 KB
/
createNextMonth
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
#!/usr/bin/env bash
set -e
DIRECTORY=$(cd `dirname $0` && pwd)
nextMonth=$(date -d"next month" +%Y-%m);
if [[ $1 =~ ^[0-9]{4}-[0-9]{2}$ ]];then
nextMonth=$1
fi
dayOfWeek=$(date -d"${nextMonth}-01" +%u)
tuesday=2
if [[ $dayOfWeek > $tuesday ]]; then
firstTuesday=$(echo "(7-${dayOfWeek})+1+${tuesday}" | bc)
else
firstTuesday=$(echo "(${tuesday}-${dayOfWeek})+1" | bc)
fi
fullDate=$(printf "%s-%02d" "${nextMonth}" ${firstTuesday});
n=$(date -d$fullDate +"%d")
if [ $n -ge 11 -a $n -le 13 ] ; then
ordinal="th"
else
case $(( $n%10 )) in
1)
ordinal=st
;;
2)
ordinal=nd
;;
3)
ordinal=rd
;;
*)
ordinal=th
;;
esac
fi
monthName=$(date -d$fullDate +%B)
day=$(date -d$fullDate +%e | tr -d " ")
year=$(date -d$fullDate +%Y)
head=$(echo "---
layout: post-slots
title: Meetup on the ${day}${ordinal} of $monthName, $year
datetitle: $monthName ${day}${ordinal}, 2015
published: false
meetupdate: $fullDate
---")
content=$(echo "$head"; tail -n +8 "${DIRECTORY}/_posts/_template.html");
lowerCaseMonth=$(echo $monthName|tr '[:upper:]' '[:lower:]')
fileNameMd="${DIRECTORY}/_posts/${fullDate}-${lowerCaseMonth}.md"
echo $fileNameMd
if [[ ! -f $fileNameMd ]]; then
echo "File not found!"
echo "Create a new Post"
echo "$content" > $fileNameMd
else
echo "Post already exists"
fi