-
Notifications
You must be signed in to change notification settings - Fork 480
/
assemble_calendar_pages.sh
68 lines (66 loc) · 1.94 KB
/
assemble_calendar_pages.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
#!/bin/bash
startYear=2021
startMonth=6
endYear=2024
endMonth=12
currentDir=$(pwd)
calendarDir="$currentDir/_calendars"
sampleCalendarFile="$calendarDir/_sample.md"
declare -a monthNames=(
[0]=none
[1]=january
[2]=february
[3]=march
[4]=april
[5]=may
[6]=june
[7]=july
[8]=august
[9]=september
[10]=october
[11]=november
[12]=december
)
echo "Calendar directory..."
echo $calendarDir
for (( i=$startYear; i<=$endYear; i++));
do
for (( j=$startMonth; j<=$endMonth; j++ ));
do
if [ $j -lt 10 ];
then
calendarFileName="$i-0$j.md"
else
calendarFileName="$i-$j.md"
fi
calendarFilePath="$calendarDir/$calendarFileName"
if [ -f "$calendarFilePath" ];
then
echo "$calendarFilePath already exists"
else
echo "Copying sample to new calendar file named $calendarFilePath"
cp $sampleCalendarFile $calendarFilePath
yearSearch="1900"
yearReplace="$i"
monthIndexSearch="888"
monthIndexReplace=$(( $j - 1))
monthNumberSearch="999"
monthNumberReplace="$j"
monthNameSearch="MONTH_NAME"
monthNameReplace="${monthNames[$j]}"
monthRedirectFromSearch="777"
if [ $j -lt 10 ];
then
monthRedirectoFromReplace="0$j"
else
monthRedirectoFromReplace="$j"
fi
sed -i '' -e "s/$yearSearch/$yearReplace/gi" $calendarFilePath
sed -i '' -e "s/$monthIndexSearch/$monthIndexReplace/gi" $calendarFilePath
sed -i '' -e "s/$monthNumberSearch/$monthNumberReplace/gi" $calendarFilePath
sed -i '' -e "s/$monthNameSearch/$monthNameReplace/gi" $calendarFilePath
sed -i '' -e "s/$monthRedirectFromSearch/$monthRedirectoFromReplace/gi" $calendarFilePath
fi
done
startMonth=1
done