-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-template.sh
executable file
·65 lines (53 loc) · 1.77 KB
/
make-template.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
#!/usr/bin/env bash
d=$(date +%e)
case $d in
1?) d=${d}th ;;
*1) d=${d}st ;;
*2) d=${d}nd ;;
*3) d=${d}rd ;;
*) d=${d}th ;;
esac
til_date=$(date +"%A, %B ${d}, %Y %n%Y-%m-%d ")
feed_date=$(date +"%a, %d %b %Y %H:%M:00 -0600")
read -p "Enter path: " til_path
read -p "Enter subject: " til_subject
if test -d "./${til_path}" && test -x "./${til_path}" ; then
echo "Directory exists."
else
echo "Creating directory ./${til_path}"
mkdir "./${til_path}"
fi
# normalize subject to the filename
til_subject_normalized=${til_subject// /_}
til_subject_normalized=$(echo "${til_subject_normalized}" | tr '[:upper:]' '[:lower:]')
echo "Creating subject file ${til_path}/${til_subject_normalized}.md"
touch "./${til_path}/${til_subject_normalized}.md"
cat >"./${til_path}/${til_subject_normalized}.md" <<EOL
# ${til_subject}
## Context
REPLACE ME
## TIL
REPLACE ME
## Sources and References
*
## Date
${til_date}
EOL
echo "Updating feed.xml (remember to change <description>)"
mv feed.xml feed.xml.bak
awk -v path="${til_path}" \
-v filename="${til_subject_normalized}" \
-v subject="${til_subject^}" \
-v category="${til_path^}" \
-v feed_date=$"${feed_date}" \
'1;/<language>en-CA<\/language>/{
printf " <item>\n";
printf " <title>%s: %s</title>\n", category, subject;
printf " <description>REPLACE ME</description>\n";
printf " <pubDate>%s</pubDate>\n", feed_date;
printf " <dc:creator>shane doucette</dc:creator>\n";
printf " <link>{{ site.url }}{{ site.baseurl }}/%s/%s.html</link>\n", path, filename;
printf " <guid isPermaLink=\"true\">{{ site.url }}{{ site.baseurl }}/%s/%s.html</guid>\n", path, filename;
printf " <category>%s</category>\n", category;
printf " </item>\n"; }' feed.xml.bak > feed.xml
echo "Done!"