Modified media page
[mob-repo.git] / make.sh
blob7c81c7fdc31e91bca1e32ec3ff87c98a98859d45
1 #!/bin/sh
3 DATE="$(date +"%D")"
5 header_wiki() { cat<<EOF
6 <html>
7 <head>
8 <title>Potolandia | Potosi's wiki</title>
9 <link rel="stylesheet" type="text/css" href="../style.css"/>
10 </head>
11 <h1>Potolandia</h1>
12 <a href="index.html">main page</a>,
13 <a href="essays.html">essays</a>,
14 <a href="about.html">about</a>,
15 <a href="filelist.html">file list ($(find -- wiki/*.md | wc -l))</a>,
16 <a href="single_page.html">single page html</a>,
17 <a>Last updated on $DATE</a><hr />
18 EOF
21 footer_wiki() { cat<<EOF
22 This website is licensed under <a class="notdead" href="https://creativecommons.org/publicdomain/zero/1.0/">CC0</a> (Public Domain). Contact me at potosi@disroot.org
23 </html>
24 EOF
27 header_media() { cat<<EOF
28 <html>
29 <head>
30 <title>Potolandia | File Hosting</title>
31 <link rel="stylesheet" type="text/css" href="../style.css"/>
32 </head>
33 <h1>Potolandia</h1>
34 <a href="index.html">main page</a>,
35 <a href="filelist.html">file list ($(find -- files/* | wc -l))</a>,
36 <a href="../wiki/index.html">back to wiki</a>,
37 <a>Last updated on $DATE</a><hr />
38 EOF
41 md() {
42 cmark "$@" | sed "s/\.md\"/.html\"/g"
45 mark_dead_links() {
46 # Marks dead links on specified dir
47 if ! [ -f "mark_dead_links" ] ; then
48 cc -O3 mark_dead_links.c -o mark_dead_links
50 cd "$1" || exit
51 for f in $(find . | grep .html); do
52 printf "Marking dead links: %s \n" "$f"
53 "$OLDPWD"/mark_dead_links < "$f" > tmp
54 mv tmp "$f"
55 done
56 cd "$OLDPWD" || exit
59 contains() {
60 (echo "$1" | grep "$2") > /dev/null
63 do_media() {
64 echo "<pre>"
65 (header_media ; echo "<ul>") > html/media/filelist.html
66 for f in $(cd files && find -- * | sort); do
67 echo "<li><a href=\"../../files/$f\">$f</a></li>" >> html/media/filelist.html
68 filetype="$(file -b files/"$f")"
69 if contains "$filetype" text ; then
70 cat files/"$f"
71 elif contains "$filetype" image ; then
72 echo "<img src=\"../../$f\" alt=\"$f\" /></a>"
73 elif contains "$filetype" audio ; then
74 echo "<audio controls><source src=\"../../files/$f\""
75 if contains "$filetype" Ogg ; then
76 echo " type=\"audio/ogg\"></audio>"
77 elif contains "$filetype" MPEG ; then
78 echo " type=\"audio/mpeg\"></audio>"
79 else
80 echo " type=\"audio/wav\"></audio>"
82 else
83 echo "<a href=\"../../files/$f\">$f</a><br>"
85 echo "<br>"
86 done
87 echo "</pre>"
88 echo "</ul><hr>" >> html/media/filelist.html
91 if [ "$(find -- html/*.html)" ] ; then
92 rm $(find -- html/*.html)
95 cp potosi.html html/index.html
97 header_wiki > html/wiki/single_page.html
98 (header_wiki && echo "<ul>") > html/wiki/filelist.html
99 for f in $(cd wiki && find -- *.md | sort); do
100 printf "Processing %s\n" "$f"
101 fname="$(echo "$f" | sed "s/\.md//g")"
102 (header_wiki; md "wiki/$f" ; echo "<hr>" ; footer_wiki) > "html/wiki/$fname.html"
103 (echo "<li><a href=\"$fname.html\"> $fname </a></li>") >> html/wiki/filelist.html
104 (echo "<span>$fname</span><br />" ; md "wiki/$f" ; echo "<hr>") >> html/wiki/single_page.html
105 done
106 mark_dead_links html/wiki
107 footer_wiki > html/wiki/single_page.html
108 (echo "</ul><hr>" && footer_wiki) >> html/wiki/filelist.html
110 echo "Doing media"
111 (header_media ; do_media; echo "<hr>" ; footer_wiki) > html/media/index.html