-
Notifications
You must be signed in to change notification settings - Fork 0
/
siteTools.sh
executable file
·196 lines (159 loc) · 4.57 KB
/
siteTools.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
# bash application to maintain your jekyll website
function new_post()
{
create_post "_posts"
}
function draft_post()
{
create_post "_drafts"
}
function create_post()
{
imagedir="public/images"
postdir=$1
echo "Enter title of the post: ";
read title;
origTitle=$title;
title=$(echo "$title" | tr '[:upper:]' '[:lower:]' | sed -e 's/[^0-9a-z\-]/ /g' | sed -e 's/ */ /g' | sed -e 's/ $//g' | tr " " -);
echo "Enter type of the post(ref|blog): "
read typepost;
site_meta_info
echo "Enter tags to classify your post (comma separated): "
read tags;
echo "Enter Category to which your post belong (comma separated): "
read categories;
postdate=$(date +%Y-%m-%d);
echo $postdate
echo "Enter banner image: "
read banner_image;
if [ ! -z $banner_image ];
then
banner_image=$(echo $imagedir/$banner_image)
echo "Enter banner image alt: "
read banner_image_alt;
fi
# check whether post exists or not
filename="$postdate-$title.md"
if [ -f "$postdir/$filename" ];
then
echo "File $postdir/$filename exists."
return;
fi
echo "Creating new post: $postdir/$filename"
echo "---" >> "$postdir/$filename"
echo "layout: post" >> "$postdir/$filename"
echo "title: $origTitle" >> "$postdir/$filename"
echo "type: $typepost" >> "$postdir/$filename"
echo "tags: [$tags]" >> "$postdir/$filename"
echo "categories: [$categories]" >> "$postdir/$filename"
if [ ! -z $banner_image ];
then
echo "banner_image: $banner_image" >> "$postdir/$filename"
echo "banner_image_alt: $banner_image_alt" >> "$postdir/$filename"
fi
echo "---" >> "$postdir/$filename";
}
# Create new_page
function new_page()
{
imagedir="public/images"
pagedir="blog"
echo "Enter title of the page: ";
read title;
origTitle=$title;
title=$(echo "$title" | tr '[:upper:]' '[:lower:]' | sed -e 's/[^0-9a-z\-]/ /g' | sed -e 's/ */ /g' | sed -e 's/ $//g' | tr " " -);
echo "Enter banner image: "
read banner_image;
if [ ! -z $banner_image ];
then
banner_image=$(echo $imagedir/$banner_image)
echo "Enter banner image alt: "
read banner_image_alt;
fi
# check whether post exists or not
filename="$title.md"
if [ -f "$filename" ];
then
echo "File $filename exists."
return;
fi
echo "Creating new page: $filename"
echo "---" >> "$pagedir/$filename"
echo "layout: page" >> "$pagedir/$filename"
echo "title: $origTitle" >> "$pagedir/$filename"
if [ ! -z $banner_image ];
then
echo "banner_image: $banner_image" >> "$pagedir/$filename"
echo "banner_image_alt: $banner_image_alt" >> "$pagedir/$filename"
else
echo "banner_image: " >> "$pagedir/$filename"
echo "banner_image_alt: " >> "$pagedir/$filename"
fi
echo "---" >> "$pagedir/$filename";
}
function site_preview()
{
bundle exec jekyll serve --host 0.0.0.0 --drafts --incremental --watch;
}
function check()
{
bundle exec jekyll doctor;
}
function init()
{
bundle install
}
function tikzconvert()
{
FileName=$(echo $1 | cut -d '.' -f1 | rev | cut -d '/' -f1 | rev);
convert -density 300 $1 -quality 90 $FileName.png
}
function projects()
{
curl -i https://api.github.com/repos/$1 > repo.data
STARS=$(cat repo.data | grep stargazers_count | cut -d " " -f4 | cut -d "," -f1)
REPONAME=$(echo $1 | cut -d "/" -f2)
REPOURL=$1
echo "Enter description for Repository:";
read REPODESC;
echo $STARS
echo "${REPONAME^}"
echo $REPOURL
echo $REPODESC
div1='''| <a href="https://github.com/''';
div2='''"> <font size="4"> '''
div3=''' </font></a>| ''';
div4=''' | <font size="3"> '''
div5=''' </font> |'''
echo $div1$REPOURL $div2 ${REPONAME^} $div3 $STARS $div4 $REPODESC $div5;
#echo $REPODESC $div
rm repo.data
}
function site_meta_info()
{
tput setaf 2
echo "Site Wide Tags"
echo "=============="
tput setaf 5
cat _posts/* | grep tags | cut -d '[' -f2 | cut -d ']' -f1 | sed -e "s/,/\n/g"\
| sort | uniq | awk '{print}' ORS=', ' | sed -e "s/$/\n\n/g" | fold -w 70 -s
tput setaf 2
echo "Site Wide Categories"
echo "===================="
tput setaf 5
cat _posts/* | grep categories | cut -d '[' -f2 | cut -d ']' -f1 | sed -e "s/,/\n/g"\
| sort | uniq | awk '{print}' ORS=', ' | sed -e "s/$/\n\n/g" | fold -w 70 -s
tput setaf 9
}
echo ''' siteTools: Usage
init: Install jekyll prerequisties
new_post: Create new_post
draft_post: Create draft_post
new_page: Create new_page
site_preview: Previewing site with jekyll
check: Search site and print specific deprecation warnings
projects: Build projects post
tikzconvert: Convert tikz pdf files to png
'''
export RARCHK_HOME_DIR=$PWD