-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-site.sh
executable file
·64 lines (54 loc) · 1.8 KB
/
generate-site.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
#!/usr/bin/env bash
# Go through all the articles and generates:
# - the index
# - each article
function printusage {
echo "Usage: $0"
echo ""
echo "Example:"
echo " $0"
}
if [[ $# -eq 1 && ( $1 == "--help" || $1 == "-h" ) ]];
then
echo "$0 - generate an article"
echo ""
echo "The template contains variables that will be replaced by values."
echo " file content: {{ file: somefile.txt }} is replaced by the content of"
echo " somefile.txt"
echo " article : {{ article }} is replaced by the content of the"
echo " provided file"
echo ""
printusage
exit 0
fi
if [ $# -ne 0 ];
then
echo "error: Incorrect number of arguments"
printusage
exit 1
fi
mkdir -p dist
rm -fr dist/*
# Generate the index
rm -fr index-urls.html
for article in $(ls blog/20[0-9]* | sort -n | tac)
do
article_url=$(echo $article | sed -e 's/.*\(20[0-9]\{6\}.*\)/\1/')
article_raw_date=$(echo $article | sed -e 's/.*\(20[0-9]\{6\}\).*/\1/')
article_date=${article_raw_date:0:4}-${article_raw_date:4:2}-${article_raw_date:6:2}
article_title=$(cat $article | grep 'class="title"' | sed -e 's/.*class="title">\([^<]*\).*/\1/g')
# echo $article_date $article_title
echo '<li><a href="/'${article_url}'"><span class="date">'${article_date}'</span> '${article_title}'</a></li>' >> index-urls.html
done
./generate-article.sh index.html nothing > dist/index.html
rm -fr index-urls.html
# Generate the articles
for article in $(ls blog/20[0-9]* | sort -n | tac)
do
article_output_file=$(echo $article | sed -e 's@blog/\(.*\)@\1@')
./generate-article.sh blog/blog-entry.html ${article} > dist/${article_output_file}
done
./generate-article.sh contact.html nothing > dist/contact.html
./generate-article.sh about.html nothing > dist/about.html
cp -r static/* dist/
cp -r assets dist/