sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

build-page.sh (2669B)


      1 #!/bin/sh -e
      2 
      3 # Given a directory name, generate a static page out of:
      4 # - ./**/index.md - the markdown files.
      5 # - ./title - the title of the website.
      6 # - ./domains - file with one domain per line (corresponding to ./<domain>/)
      7 # - ./*/title - one file per subdirectory with the subtitle.
      8 
      9 
     10 ## setup ##
     11 
     12 page="$1/index.md"
     13 this_domain="${page%%/*}"
     14 
     15 domain_list='
     16 	home.suckless.org
     17 	dwm.suckless.org
     18 	st.suckless.org
     19 	core.suckless.org
     20 	surf.suckless.org
     21 	tools.suckless.org
     22 	libs.suckless.org
     23 '
     24 
     25 
     26 ## functions ##
     27 
     28 #1 current page
     29 #2 directory to list
     30 nav() {
     31 	ls "$2" | while IFS= read dir
     32 	do
     33 		test -d "$2/$dir" || continue
     34 		expr "$1" : "$2/$dir/." >/dev/null &&
     35 			match=' class="thisPage"' ||
     36 			match=
     37 		printf '<li><a%s href="%s">' "$match" "//$2/$dir/"
     38 		printf '%s/</a>' "$dir" | tr _- '  '
     39 		if test "$match"
     40 		then
     41 			printf '<ul>\n'
     42 			nav "$1" "$2/$dir"
     43 			printf '</ul>\n'
     44 		fi
     45 		printf '</li>\n'
     46 	done
     47 }
     48 
     49 
     50 ## header ##
     51 
     52 test -f "$page" &&
     53 	title=$(sed 's,^#* *,,; q' "$page") ||
     54 	title=$(basename "$(dirname "$page")")
     55 
     56 cat <<EOF
     57 <!doctype html>
     58 <html>
     59 <head>
     60 	<meta charset="utf-8">
     61 	<title>$title | suckless.org software that sucks less</title>
     62 	<link rel="stylesheet" type="text/css" href="//suckless.org/pub/style.css">
     63 </head>
     64 
     65 <div id="header">
     66 	<a href="//suckless.org/"><img src="//suckless.org/logo.svg"/></a>
     67 	<a id="headerLink" href="//suckless.org/">suckless.org</a>
     68 	<span id="headerSubtitle">$subtitle</span>
     69 </div>
     70 EOF
     71 
     72 
     73 ## nav bar ##
     74 
     75 printf '<div id="menu">\n'
     76 for domain in $domain_list
     77 do
     78 	printf '<a '
     79 	test "$this_domain" = "$domain" && printf 'class="thisSite" '
     80 	printf 'href="%s">%s</a>\n' "//$domain" "${domain%%.*}"
     81 done
     82 
     83 cat <<EOF
     84 <span class="right">
     85 	<a href="//dl.suckless.org">download</a>
     86 	<a href="//git.suckless.org">source</a>
     87 </span>
     88 EOF
     89 
     90 printf '</div>\n\n'
     91 
     92 
     93 printf '<div id="content">\n\n'
     94 
     95 
     96 ## menu panel ##
     97 
     98 printf '<div id="nav">\n<ul>\n<li><a'
     99 test "${page%/*}" = "$this_domain"  && printf ' class="thisPage"'
    100 printf ' href="/">about</a></li>'
    101 nav "$page" "$this_domain"
    102 printf '</ul>\n</div>\n\n'
    103 
    104 
    105 ## content ##
    106 
    107 printf '<div id="main">\n'
    108 if test -f "$page"
    109 then
    110 	smu < "$page"
    111 else
    112 	printf '<ul>\n'
    113 	ls "${page%/index.md}" | while IFS= read -r dir
    114 	do
    115 		path=${page%/index.md}/$dir/
    116 		test -d "$path" || continue
    117 		printf '<li><a href="%s">' "//$path"
    118 		printf '%s</a></li>\n' "$dir" | tr _- '  '
    119 	done
    120 	printf '</ul>\n'
    121 fi
    122 printf '</div>\n\n'
    123 
    124 
    125 printf '</div>\n\n' # end of id="content"
    126 
    127 
    128 ## footer ##
    129 
    130 cat <<EOF
    131 <div id="footer">
    132 <span class="right">
    133 &copy; 2006-2018 suckless.org community
    134 | <a href="//ev.suckless.org/impressum">Impressum</a>
    135 | <a href="//ev.suckless.org">e.V.</a>
    136 </span>
    137 </div>
    138 EOF