summaryrefslogtreecommitdiff
path: root/make.sh
blob: bf4909495d9b68dba5bec8ca3a3e15535b9e264b (plain)
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
#!/bin/sh

rm -r html
mkdir html

cp -r media html
cp css/*.css html
cp *.php html
cp *.js html
# cp favicon.ico html

# Generate Pages

echo "generating pages..."

cd content

pages=".pages"

echo "<div class="box">\n" >> $pages
echo "### Last 10 Modified Pages:\n" >> $pages

for page in $(ls *.* -t | head -10); do # todo: use git for this (if its better)
	name=${page%.md}
	echo "* **[$name]($name.html)** - <small>$(date -r $page "+%d/%m/%y")</small>" >> $pages
done

echo "</div>" >> $pages

# echo "<div class="box">\n" >> $pages
# echo "### Last 10 Recently Created Pages:\n" >> $pages

# for page in $(ls *.* -t --time=birth | head -10); do
# 	name=${page%.md}
# 	echo "* **[$name]($name.html)**" >> $pages
# done

# echo "</div>" >> $pages

echo "\n### All Pages:\n" >> $pages

first=true 

for page in *.*; do

	name=${page%.md}

	if [ "$first" = true ]; then
		first=false
	else
		echo " // " >> $pages
	fi

	echo "**[$name]($name.html)**" >> $pages

done

# Excluded pages.md from last modified, as it will always be the last modified D:
mv $pages pages.md

for page in *.md; do
	name="${page%.md}"
	title="$(echo $name | sed "s/_/ /g")"
	pagename="../html/$name.html"

	if [ "$name" = "index" ]; then
		sed -e "s|{{ page }}||g" -e "s|{{ title }}|neetlo.li|g" ../template.html >> $pagename
	else
		sed -e "s|{{ page }}|\&gt;\&lt;\&gt; $title|g" -e "s|{{ title }}|$title|g" ../template.html >> $pagename
	fi

	cmark-gfm --unsafe -e table -e autolink -e strikethrough $page >> $pagename

	ordinal="th"

	day="$(date -r "$page" "+%e")"
	day=$((day))

	case $day in
		1 | 21 | 31 )
			ordinal="st"
			;;

		2 | 22 )
			ordinal="nd"
			;;

		3 | 23 )
			ordinal="rd"
			;;
			
	esac

	echo "<hr>Last Modified: $(date -r "$page" "+$day$ordinal of %B, %Y")" >> $pagename

	echo "</main></body></html>" >> $pagename
done

rm pages.md

cd ..

echo "generated pages"