-
Notifications
You must be signed in to change notification settings - Fork 2
/
gsoc_blog.sh
106 lines (84 loc) · 3.21 KB
/
gsoc_blog.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/sh
read -p "File name: " file_name
read -p "URL alias: " url_alias
read -p "Summary: " summ
# Get title from the first line of the file
title=$(sed -n '1s/^#\s*//p' "${file_name}")
# Old way, decided to use less stuff but left it here cuz why not
#title=$(cat "${file_name}" | head -1 | cut -c 3-)
# Get the post header from the "head" file
headerContent=$(cat blogposts/gsoc/head)
# Get the post abstract from the second line of the file
postTitle=$(cat ${file_name} | grep --line-number \#\# | grep 2 | cut -c 6-)
# Convert markdown content to HTML
htmlContent=$(md2html "${file_name}")
# Get the current date and time in the RFC 3339 format and regular format
postDate=$(date +"%a, %d %b. %Y - %r")
xmlDate=$(date --rfc-3339=seconds | sed 's/ /T/')
remNums=$(cat atom.xml | wc -l)
remNums2=$(cat atom-gsoc.xml | wc -l)
# Write the HTML file
{
echo "<!DOCTYPE html>"
echo "<html lang=\"en\">"
echo "<head>"
echo "<meta charset=\"UTF-8\">"
echo "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">"
echo "<title>${title}</title>"
echo "${headerContent}"
echo "</head>"
echo "<body>"
echo "${htmlContent}"
echo "<br/><em style='color: #333333;'>Posted at ${postDate}</em><br/><br/>"
echo "</body>"
echo "</html>"
cat "blogposts/gsoc/tail"
} > "blogposts/gsoc/${url_alias}.html"
# Add RSS entry
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<feed xmlns=\"http://www.w3.org/2005/Atom\">
<title>Tokhy's hub</title>
<link href=\"https://tokiesan.github.io/atom.xml\" rel=\"self\"/>
<updated>"${xmlDate}"</updated>
<author>
<name>Ahmed Gamal Eltokhy</name>
</author>
<id>https://tokiesan.github.io</id>
""$(sed -n 10,$(echo ${remNums}-1 | bc)p atom.xml)" > atom.xml
echo "<entry>
<title>"${title}"</title><summary>"${summ}"</summary>""
<link href=\"https://tokiesan.github.io/blogposts/gsoc/${url_alias}.html\"/>
<updated>"${xmlDate}"</updated>
<id>https://tokiesan.github.io/blogposts/gsoc/${url_alias}.html</id>
</entry>
</feed>" >> atom.xml
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<feed xmlns=\"http://www.w3.org/2005/Atom\">
<title>Tokhy's hub</title>
<link href=\"https://tokiesan.github.io/atom-gsoc.xml\" rel=\"self\"/>
<updated>"${xmlDate}"</updated>
<author>
<name>Ahmed Gamal Eltokhy</name>
</author>
<id>https://tokiesan.github.io</id>
""$(sed -n 10,$(echo ${remNums2}-1 | bc)p atom-gsoc.xml)" > atom-gsoc.xml
echo "<entry>
<title>"${title}"</title><summary>"${summ}"</summary>""
<link href=\"https://tokiesan.github.io/blogposts/gsoc/${url_alias}.html\"/>
<updated>"${xmlDate}"</updated>
<id>https://tokiesan.github.io/blogposts/gsoc/${url_alias}.html</id>
</entry>
</feed>" >> atom-gsoc.xml
#Add entry to blogposts/index.html
newElem="<tr>\n<td class=\"title\"><a href=\"${url_alias}.html\">${title}</a></td>\n<td><em>$(date +"%a, %d %b. %Y")</em></td>\n</tr>"
awk -v FOO1="${newElem}" '{
sub(/<!---->/, "<!----> " FOO1);
print;
}' blogposts/gsoc/index.html > temporary_output
cat temporary_output > blogposts/gsoc/index.html
rm -rf temporary_output
mv ${file_name} junk/
# Add new post to repo
git add "blogposts/gsoc/${url_alias}.html" "atom-gsoc.xml" "blogposts/gsoc/index.html" "atom.xml"
git commit -m "Added ${title} post"
git push -u origin