[wiki] [sites] use heredocs instead of files scattered around || Josuah Demangeon

From: <git_AT_suckless.org>
Date: Thu, 06 Sep 2018 21:25:06 +0200

commit 4ac91a1a07cc9186cbe8536f4dbd384fc569bf66
Author: Josuah Demangeon <mail_AT_josuah.net>
Date: Thu Sep 6 21:24:01 2018 +0200

    use heredocs instead of files scattered around
    
    Given how ad-hoc is the script, there is no need for such a strong
    separation between the content and the script.
    
    Using heredocs make it also easier to edit the whole layout.

diff --git a/build b/build
new file mode 100755
index 00000000..7a706a54
--- /dev/null
+++ b/build
_AT_@ -0,0 +1 @@
+find * -type d -exec sh -exc './build-page "$0" >$0/index.html' {} \;
diff --git a/build-page b/build-page
new file mode 100755
index 00000000..e68276e6
--- /dev/null
+++ b/build-page
_AT_@ -0,0 +1,138 @@
+#!/bin/sh -e
+
+# Given a directory name, generate a static page out of:
+# - ./**/index.md - the markdown files
+# - ./title - the title of the website
+# - ./domains - file with one domain per line (corresponding to ./<domain>/)
+# - ./*/title - one file per subdirectory with the subtitle
+
+
+## setup ##
+
+page="$1/index.md"
+this_domain="${page%%/*}"
+
+domain_list='
+ home.suckless.org
+ dwm.suckless.org
+ st.suckless.org
+ core.suckless.org
+ surf.suckless.org
+ tools.suckless.org
+ libs.suckless.org
+'
+
+
+## functions ##
+
+#1 current page
+#2 directory to list
+nav() {
+ ls "$2" | while IFS= read dir
+ do
+ test -d "$2/$dir" || continue
+ expr "$1" : "$2/$dir/." >/dev/null &&
+ match=' class="thisPage"' ||
+ match=
+ printf '<li><a%s href="%s">' "$match" "//$2/$dir/"
+ printf '%s/</a>' "$dir" | tr _- ' '
+ if test "$match"
+ then
+ printf '<ul>
'
+ nav "$1" "$2/$dir"
+ printf '</ul>
'
+ fi
+ printf '</li>
'
+ done
+}
+
+
+## header ##
+
+test -f "$page" &&
+ title=$(sed 's,^#* *,,; q' "$page") ||
+ title=$(basename "$(dirname "$page")")
+
+cat <<EOF
+<!doctype html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>$title | suckless.org software that sucks less</title>
+ <link rel="stylesheet" type="text/css" href="//suckless.org/pub/style.css">
+</head>
+
+<div id="header">
+ <a href="//suckless.org/"><img src="//suckless.org/logo.svg"/></a>
+ <a id="headerLink" href="//suckless.org/">suckless.org</a>
+ <span id="headerSubtitle">$subtitle</span>
+</div>
+EOF
+
+
+## nav bar ##
+
+printf '<div id="menu">
'
+for domain in $domain_list
+do
+ printf '<a href="%s"' "//$domain"
+ test "$this_domain" = "$domain" && printf ' class="thisSite"'
+ printf '">%s</a>
' "${domain%%.*}"
+done
+
+cat <<EOF
+<span class="right">
+ <a href="//dl.suckless.org">download</a>
+ <a href="//git.suckless.org">source</a>
+</span>
+EOF
+
+printf '</div>

'
+
+
+printf '<div id="content">

'
+
+
+## menu panel ##
+
+printf '<div id="nav">
<ul>
<li><a'
+test "${page%/*}" = "$this_domain" && printf ' class="thisPage"'
+printf ' href="/">about</a></li>'
+nav "$page" "$this_domain"
+printf '</ul>
</div>

'
+
+
+## content ##
+
+printf '<div id="main">
'
+if test -f "$page"
+then
+ smu "$page"
+else
+ printf '<ul>
'
+ ls "${page%/index.md}" | while IFS= read -r dir
+ do
+ path=${page%/index.md}/$dir/
+ test -d "$path" || continue
+ printf '<li><a href="%s">' "//$path"
+ printf '%s</a></li>
' "$dir" | tr _- ' '
+ done
+ printf '</ul>
'
+fi
+printf '</div>

'
+
+
+printf '</div>

' # end of id="content"
+
+
+## footer ##
+
+cat <<EOF
+<div id="footer">
+<span class="right">
+&copy; 2006-2018 suckless.org community
+| <a href="//ev.suckless.org/impressum">Impressum</a>
+| <a href="//ev.suckless.org">e.V.</a>
+</span>
+</div>
+EOF
diff --git a/domains b/domains
deleted file mode 100644
index 950bcbf8..00000000
--- a/domains
+++ /dev/null
_AT_@ -1,7 +0,0 @@
-home.suckless.org
-dwm.suckless.org
-st.suckless.org
-core.suckless.org
-surf.suckless.org
-tools.suckless.org
-libs.suckless.org
diff --git a/foot.html b/foot.html
deleted file mode 100644
index c53226be..00000000
--- a/foot.html
+++ /dev/null
_AT_@ -1,5 +0,0 @@
-<div id="footer">
-<span class="right">
-&copy; 2006-2018 suckless.org community | <a href="//ev.suckless.org/impressum">Impressum</a> | <a href="//ev.suckless.org">e.V.</a>
-</span>
-</div>
diff --git a/head.html b/head.html
deleted file mode 100644
index 20ad1231..00000000
--- a/head.html
+++ /dev/null
_AT_@ -1,14 +0,0 @@
-<!doctype html>
-<html>
-<head>
-<link rel="stylesheet" type="text/css" href="/static/css/banner-styles.css?v=1533593143.0" />
-<link rel="stylesheet" type="text/css" href="/static/css/iconochive.css?v=1533593143.0" />
-<title>%t | suckless.org software that sucks less</title>
-<link rel="stylesheet" type="text/css" href="//suckless.org/pub/style.css">
-<meta charset="utf-8">
-</head>
-<body>
-<div id="header">
- <a href="//suckless.org/"><img src="//suckless.org/logo.svg"/></a>
- <a id="headerLink" href="//suckless.org/">suckless.org</a> <span id="headerSubtitle">%s</span>
-</div>
diff --git a/links.html b/links.html
deleted file mode 100644
index c1e41271..00000000
--- a/links.html
+++ /dev/null
_AT_@ -1,4 +0,0 @@
-<span class="right">
- <a href="//dl.suckless.org">download</a>
- <a href="//git.suckless.org">source</a>
-</span>
diff --git a/make b/make
deleted file mode 100755
index fdba9b73..00000000
--- a/make
+++ /dev/null
_AT_@ -1,90 +0,0 @@
-#!/bin/sh -e
-
-# Generate a static website out of:
-# - ./**.md - the markdown files. Must be "*/index.md"
-# - ./title - the title of the website
-# - ./domains - file with one domain per line (corresponding to ./<domain>/)
-# - ./*/title - one file per subdirectory with the subtitle
-# - ./head.html - content added at the top,
-# - ./foot.html - content added at the bottom,
-# - ./links.html - content added at the right side of the navigation bar,
-
-#1 current page
-#2 directory to list
-nav() {
- ls "$2" | while read dir
- do
- test -d "$2/$dir" || continue
- test -z "${1##$2/$dir/*?}" && match=' class="thisPage"' || match=
- printf '<li><a%s href="%s">' "$match" "//$2/$dir/"
- printf '%s/</a>' "$dir" | tr _- ' '
- if test "$match"
- then
- printf '<ul>
'
- nav "$1" "$2/$dir"
- printf '</ul>
'
- fi
- printf '</li>
'
- done
-}
-
-find * -type d | while IFS='' read -r page
-do
- exec >$page/index.html
- page="$page/index.md"
- this_domain="${page%%/*}"
- printf 'Generating %s
' "$page" 1>&2
-
- # header
- if test -f "$page"
- then
- title=$(sed 's,^#* *,,; q' "$page")
- else
- title=$(basename "$(dirname "$page")")
- fi
- awk -v title="$title" -v subtitle="$(cat "$this_domain/title")" \
- '{ gsub("%t", title); gsub("%s", subtitle); print; }' head.html
-
- # navigation bar
- printf '<div id="menu">
'
- while IFS='' read -r domain
- do
- printf '<a href="%s"' "//$domain"
- test "$this_domain" = "$domain" && printf ' class="thisSite"'
- printf '">%s</a>
' "${domain%%.*}"
- done <domains
- cat links.html
- printf '</div>

'
-
- printf '<div id="content">

'
-
- # left navigation panel
- printf '<div id="nav">
<ul><li><a'
- test "${page%/*}" = "$this_domain" && printf ' class="thisPage"'
- printf ' href="/">about</a></li>'
- nav "$page" "$this_domain"
- printf '</ul></div>

'
-
- # main
- printf '<div id="main">
'
- if test -f "$page"
- then
- smu "$page"
- else
- printf '<ul>
'
- ls "${page%/index.md}" | while IFS='' read -r dir
- do
- path=${page%/index.md}/$dir/
- test -d "$path" || continue
- printf '<li><a href="%s">' "//$path"
- printf '%s</a></li>
' "$dir" | tr _- ' '
- done
- printf '</ul>
'
- fi
- printf '</div>

'
-
- printf '</div>

' # end of id="content"
-
- # footer
- cat foot.html
-done
Received on Thu Sep 06 2018 - 21:25:06 CEST

This archive was generated by hypermail 2.3.0 : Thu Sep 06 2018 - 21:36:24 CEST