cleanup and use consistent variable naming - static-site-scripts - static site … | |
git clone git://git.codemadness.org/static-site-scripts | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit e249829a851b58876124433b43c72c02b8ca81df | |
parent 94bed6022e16b4095581d31c38056be14675d4c3 | |
Author: Hiltjo Posthuma <[email protected]> | |
Date: Sun, 15 Dec 2013 20:32:59 +0100 | |
cleanup and use consistent variable naming | |
Signed-off-by: Hiltjo Posthuma <[email protected]> | |
Diffstat: | |
M generate.sh | 110 ++++++++++++++++-------------… | |
D layout/atom/atom.sh | 14 -------------- | |
D layout/atom/atomitem.sh | 16 ---------------- | |
D layout/index/index.sh | 52 -----------------------------… | |
D layout/index/indexitem.sh | 3 --- | |
D layout/page/page.sh | 50 -----------------------------… | |
D layout/rss/rssitem.sh | 12 ------------ | |
A site/layout/atom/atom.sh | 14 ++++++++++++++ | |
A site/layout/atom/atomitem.sh | 16 ++++++++++++++++ | |
A site/layout/index/index.sh | 52 +++++++++++++++++++++++++++++… | |
A site/layout/index/indexitem.sh | 3 +++ | |
A site/layout/page/page.sh | 50 +++++++++++++++++++++++++++++… | |
R layout/rss/rss.sh -> site/layout/r… | 0 | |
A site/layout/rss/rssitem.sh | 12 ++++++++++++ | |
R pages/example-page-template.html -… | 0 | |
R pages/example-page-template.sh -> … | 0 | |
16 files changed, 204 insertions(+), 200 deletions(-) | |
--- | |
diff --git a/generate.sh b/generate.sh | |
@@ -1,14 +1,11 @@ | |
#!/bin/sh | |
-# Generate a simple static site with an index page. | |
-# Author: Hiltjo Posthuma <[email protected]> | |
-# License: WTFPL | |
# Syntax highlight code. | |
code_highlight() { | |
- echo '<pre>' | |
+ printf '%s\n' '<pre>' | |
# escape some HTML entities, prefix code with linenumbers. | |
sed -e 's@&@\&@g' -e 's@>@\>@g' -e 's@<@\<@g' | nl -w 4 -s '… | |
- echo '</pre>' | |
+ printf '%s\n' '</pre>' | |
} | |
# page_metadata(filename) | |
@@ -17,82 +14,93 @@ page_metadata() { | |
tags="" | |
title="" | |
url="" | |
- pagetitle="" | |
description="${sitedescription}" | |
keywords="${sitekeywords}" | |
filename="" | |
content="" | |
categories="" | |
timestamp="" | |
- [ -f "$1" ] && . "$1" # load page metadata. | |
+ [ ! "$1" = "" ] && [ -f "$1" ] && . "$1" # load page metadata. | |
} | |
-# Read config file. | |
-configfile="$1" | |
-if [ "$configfile" = "" ]; then | |
- configfile="./config.sh" | |
-fi | |
-if [ -f "$configfile" ]; then | |
- . "$configfile" | |
-else | |
- echo "$configfile not found or not a file." >&2 | |
- exit 1 | |
-fi | |
+# load config (evaluate shellscript). | |
+# loadconfig(configfile) | |
+loadconfig() { | |
+ # allow to specify config via argv[1]. | |
+ if [ ! "$1" = "" ]; then | |
+ # get absolute path of config file. | |
+ config=$(readlink -f "$1") | |
+ else | |
+ # default config location. | |
+ config="./site.conf" | |
+ fi | |
+ # load config: config is loaded here to be able to override above vari… | |
+ # (sfeedpath, sfeedfile, etc). | |
+ if [ -r "$config" ]; then | |
+ . "$config" | |
+ else | |
+ echo "$0 [configfile]" >&2 | |
+ echo "" >&2 | |
+ echo "Configuration file \"$config\" does not exist or is not … | |
+ exit 1 | |
+ fi | |
+} | |
-# Remember current dir. | |
-pwddir="$(pwd)" | |
+# Read config file. | |
+loadconfig "$1" | |
+config="$1" | |
-# Make output dir. | |
-mkdir -p "$outputdir" | |
+# Try to make output dir. | |
+mkdir -p "${outputdir}" | |
# process pages. | |
# truncate pages where content is appended. | |
for name in "rss.xml" "atom.xml" "index.html"; do | |
- echo > "$outputdir/$name" | |
+ echo > "${outputdir}/${name}" | |
done | |
-find "$pagesdir" -name "*.sh" | while read page; do | |
- page_metadata "$page" # load page metadata. | |
- printf "%s\t%s\n" "$timestamp" "$page" | |
-done | sort -rn | while read ts meta; do # process in order of time descending. | |
- pagename=$(basename "$meta" ".sh") | |
- page_metadata "$meta" | |
+find "${pagesdir}" -name "*.sh" | while read -r page; do | |
+ page_metadata "${page}" # load page metadata. | |
+ printf "%s\t%s\n" "${timestamp}" "${page}" | |
+done | sort -rn | while read -r ts meta; do # process in order of time descend… | |
+ pagename=$(basename "${meta}" ".sh") | |
+ page_metadata "${meta}" | |
urlfull="${sitefullurl}/${url}" | |
#url="${siterelurl}/${url}" | |
- if [ -f "$pagesdir/$pagename.html" ]; then | |
- filename="$pagesdir/$pagename.html" | |
- content=$(cat "$filename") | |
- elif [ -f "$pagesdir/$pagename.md" ]; then | |
+ if [ -f "${pagesdir}/${pagename}.html" ]; then | |
+ filename="${pagesdir}/${pagename}.html" | |
+ content=$(cat "${filename}") | |
+ elif [ -f "${pagesdir}/${pagename}.md" ]; then | |
# TODO: test markdown | |
- filename="$pagesdir/$pagename.md" | |
- content=$("$markdown" "$filename") | |
+ filename="${pagesdir}/${pagename}.md" | |
+ content=$("${markdown}" "${filename}") | |
fi | |
- . "$layoutdir/page/page.sh" > "$outputdir/$pagename.html" | |
- . "$layoutdir/rss/rssitem.sh" >> "$outputdir/rss.xml" | |
- . "$layoutdir/atom/atomitem.sh" >> "$outputdir/atom.xml" | |
- . "$layoutdir/index/indexitem.sh" >> "$outputdir/index.html" | |
+ . "${layoutdir}/page/page.sh" > "${outputdir}/${pagename}.html" | |
+ . "${layoutdir}/index/indexitem.sh" >> "${outputdir}/index.html" | |
+ . "${layoutdir}/rss/rssitem.sh" >> "${outputdir}/rss.xml" | |
+ . "${layoutdir}/atom/atomitem.sh" >> "${outputdir}/atom.xml" | |
done | |
# Index page. | |
page_metadata "" | |
title="Posts" | |
-content=$(cat "$outputdir/index.html") | |
-. "$layoutdir/index/index.sh" > "$outputdir/index.html" | |
+content=$(cat "${outputdir}/index.html") | |
+. "${layoutdir}/index/index.sh" > "${outputdir}/index.html" | |
# RSS | |
page_metadata "" | |
-content=$(cat "$outputdir/rss.xml") | |
-. "$layoutdir/rss/rss.sh" > "$outputdir/rss.xml" | |
+content=$(cat "${outputdir}/rss.xml") | |
+. "${layoutdir}/rss/rss.sh" > "${outputdir}/rss.xml" | |
# Atom | |
page_metadata "" | |
-content=$(cat "$outputdir/atom.xml") | |
-. "$layoutdir/atom/atom.sh" > "$outputdir/atom.xml" | |
+content=$(cat "${outputdir}/atom.xml") | |
+. "${layoutdir}/atom/atom.sh" > "${outputdir}/atom.xml" | |
# Goto output dir to make relative urls. | |
-cd "$outputdir" | |
+cd "${outputdir}" | |
# Sitemap: urllist.txt | |
-find ./ -type f -name "*.html" | sort | sed 's@^./\(.*\)$@'$sitefullurl'/\1@' … | |
+find ./ -type f -name "*.html" | sort | sed 's@^./\(.*\)$@'${sitefullurl}'/\1@… | |
# Sitemap: sitemap.xml | |
(cat <<! | |
@@ -100,7 +108,7 @@ find ./ -type f -name "*.html" | sort | sed 's@^./\(.*\)$@'… | |
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> | |
! | |
-find ./ -type f -name "*.html" | sort | sed 's@^./\(.*\)$@<url><loc>'$sitefull… | |
+find ./ -type f -name "*.html" | sort | sed 's@^./\(.*\)$@<url><loc>'${siteful… | |
cat <<! | |
</urlset> | |
@@ -108,8 +116,4 @@ cat <<! | |
) > "sitemap.xml" | |
# Restore current dir. | |
-cd "$pwddir" | |
- | |
-# Copy stylesheets. | |
-cp "style.css" "$outputdir" | |
-cp "print.css" "$outputdir" | |
+cd "${basedir}" | |
diff --git a/layout/atom/atom.sh b/layout/atom/atom.sh | |
@@ -1,14 +0,0 @@ | |
-#!/bin/sh | |
- | |
-cat <<!__EOF__ | |
-<?xml version="1.0" encoding="UTF-8"?> | |
-<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"> | |
- <title type="text">${sitetitle}</title> | |
- <subtitle type="text">${sitedescription}</subtitle> | |
- <updated>$(date "+%Y-%m-%dT%H:%M:%SZ" -d "$builddate")</updated> | |
- <link rel="alternate" type="text/html" href="${sitefullurl}" /> | |
- <id>${sitefullurl}/atom.xml</id> | |
- <link rel="self" type="application/atom+xml" href="${sitefullurl}/atom… | |
- ${content} | |
-</feed> | |
-!__EOF__ | |
diff --git a/layout/atom/atomitem.sh b/layout/atom/atomitem.sh | |
@@ -1,16 +0,0 @@ | |
-#!/bin/sh | |
- | |
-cat <<!__EOF__ | |
-<entry> | |
- <author> | |
- <name>${author}</name> | |
- <uri>${sitefullurl}</uri> | |
- </author> | |
- <title type="html"><![CDATA[$title]]></title> | |
- <link rel="alternate" type="text/html" href="${urlfull}" /> | |
- <id>${urlfull}</id> | |
- <updated>$(date "+%Y-%m-%dT%H:%M:%SZ" -d "$timestamp")</updated> | |
- <published>$(date "+%Y-%m-%dT%H:%M:%SZ" -d "$timestamp")</published> | |
- <summary type="html"><![CDATA[$description]]></summary> | |
-</entry> | |
-!__EOF__ | |
diff --git a/layout/index/index.sh b/layout/index/index.sh | |
@@ -1,52 +0,0 @@ | |
-#!/bin/sh | |
- | |
-# prefix page title with site title, make sure its neatly formatted. | |
-if [ "$title" = "" ]; then | |
- pagetitle="$sitetitle" | |
-else | |
- pagetitle="$title - $sitetitle" | |
-fi | |
- | |
-cat <<!__EOF__ | |
-<!DOCTYPE HTML> | |
-<html dir="ltr" lang="en"> | |
- <head> | |
- <title>${pagetitle}</title> | |
- <link rel="stylesheet" href="style.css" type="text/css" media=… | |
- <link rel="stylesheet" href="print.css" type="text/css" media=… | |
- <link rel="alternate" type="application/rss+xml" title="${site… | |
- <link rel="alternate" type="application/atom+xml" title="${sit… | |
- <link rel="icon" type="image/png" href="/favicon.png" /> | |
- <meta http-equiv="Content-Type" content="text/html; charset=UT… | |
- <meta http-equiv="Content-Language" content="en" /> | |
- <meta content="width=device-width" name="viewport" /> | |
- <meta content="${keywords}" name="keywords" /> | |
- <meta content="${description}" name="description" /> | |
- </head> | |
- <body> | |
- <div id="menuwrap"> | |
- <div id="menu"> | |
- <span id="links"> | |
- <a href="${siterelurl}/" title="Blog">… | |
- <a href="/downloads/projects/" title="… | |
- </span> | |
- <span id="links-contact"> | |
- <span class="hidden"> | </span> | |
- <a href="rss.xml" title="Syndicate thi… | |
- <a href="atom.xml" title="Atom feed" c… | |
- <a href="mailto:${sitemail}" title="Ma… | |
- </span> | |
- </div> | |
- </div> | |
- <hr class="hidden" /> | |
- <div id="mainwrap"> | |
- <div id="main"> | |
-<h1>Posts</h1> | |
-<table> | |
- ${content} | |
-</table> | |
- </div> | |
- </div> | |
- </body> | |
-</html> | |
-!__EOF__ | |
diff --git a/layout/index/indexitem.sh b/layout/index/indexitem.sh | |
@@ -1,3 +0,0 @@ | |
-#!/bin/sh | |
-# row for index page. | |
-printf '<tr><td class="lm">%s</td><td><a href="%s" title="%s">%s</a></td></tr>… | |
diff --git a/layout/page/page.sh b/layout/page/page.sh | |
@@ -1,50 +0,0 @@ | |
-#!/bin/sh | |
- | |
-# prefix page title with site title, make sure its neatly formatted. | |
-if [ "$title" = "" ]; then | |
- pagetitle="$sitetitle" | |
-else | |
- pagetitle="$title - $sitetitle" | |
-fi | |
- | |
-cat <<!__EOF__ | |
-<!DOCTYPE HTML> | |
-<html dir="ltr" lang="en"> | |
- <head> | |
- <title>${pagetitle}</title> | |
- <link rel="stylesheet" href="style.css" type="text/css" media=… | |
- <link rel="stylesheet" href="print.css" type="text/css" media=… | |
- <link rel="alternate" type="application/rss+xml" title="${site… | |
- <link rel="alternate" type="application/atom+xml" title="${sit… | |
- <link rel="icon" type="image/png" href="/favicon.png" /> | |
- <meta http-equiv="Content-Type" content="text/html; charset=UT… | |
- <meta http-equiv="Content-Language" content="en" /> | |
- <meta content="width=device-width" name="viewport" /> | |
- <meta content="${keywords}" name="keywords" /> | |
- <meta content="${description}" name="description" /> | |
- </head> | |
- <body> | |
- <div id="menuwrap"> | |
- <div id="menu"> | |
- <span id="links"> | |
- <a href="${siterelurl}/" title="Blog">… | |
- <a href="/downloads/projects/" title="… | |
- </span> | |
- <span id="links-contact"> | |
- <span class="hidden"> | </span> | |
- <a href="rss.xml" title="Syndicate thi… | |
- <a href="atom.xml" title="Atom feed" c… | |
- <a href="mailto:${sitemail}" title="Ma… | |
- </span> | |
- </div> | |
- </div> | |
- <hr class="hidden" /> | |
- <div id="mainwrap"> | |
- <div id="main"> | |
- <h1><a href="${urlrel}" title="${title}">${tit… | |
- ${content} | |
- </div> | |
- </div> | |
- </body> | |
-</html> | |
-!__EOF__ | |
diff --git a/layout/rss/rssitem.sh b/layout/rss/rssitem.sh | |
@@ -1,12 +0,0 @@ | |
-#!/bin/sh | |
- | |
-cat <<!__EOF__ | |
-<item> | |
- <title>${title}</title> | |
- <link>${urlfull}</link> | |
- <pubDate>$(date -R -d "$timestamp")</pubDate> | |
- <author>${author}</author> | |
- <guid isPermaLink="false">${urlfull}</guid> | |
- <description><![CDATA[${description}]]></description> | |
-</item> | |
-!__EOF__ | |
diff --git a/site/layout/atom/atom.sh b/site/layout/atom/atom.sh | |
@@ -0,0 +1,14 @@ | |
+#!/bin/sh | |
+ | |
+cat <<!__EOF__ | |
+<?xml version="1.0" encoding="UTF-8"?> | |
+<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"> | |
+ <title type="text">${sitetitle}</title> | |
+ <subtitle type="text">${sitedescription}</subtitle> | |
+ <updated>$(date "+%Y-%m-%dT%H:%M:%SZ" -d "${builddate}")</updated> | |
+ <link rel="alternate" type="text/html" href="${sitefullurl}" /> | |
+ <id>${sitefullurl}/atom.xml</id> | |
+ <link rel="self" type="application/atom+xml" href="${sitefullurl}/atom… | |
+ ${content} | |
+</feed> | |
+!__EOF__ | |
diff --git a/site/layout/atom/atomitem.sh b/site/layout/atom/atomitem.sh | |
@@ -0,0 +1,16 @@ | |
+#!/bin/sh | |
+ | |
+cat <<!__EOF__ | |
+<entry> | |
+ <author> | |
+ <name>${author}</name> | |
+ <uri>${sitefullurl}</uri> | |
+ </author> | |
+ <title type="html"><![CDATA[${title}]]></title> | |
+ <link rel="alternate" type="text/html" href="${urlfull}" /> | |
+ <id>${urlfull}</id> | |
+ <updated>$(date "+%Y-%m-%dT%H:%M:%SZ" -d "${timestamp}")</updated> | |
+ <published>$(date "+%Y-%m-%dT%H:%M:%SZ" -d "${timestamp}")</published> | |
+ <summary type="html"><![CDATA[${description}]]></summary> | |
+</entry> | |
+!__EOF__ | |
diff --git a/site/layout/index/index.sh b/site/layout/index/index.sh | |
@@ -0,0 +1,52 @@ | |
+#!/bin/sh | |
+ | |
+# prefix page title with site title, make sure its neatly formatted. | |
+if [ "${title}" = "" ]; then | |
+ pagetitle="${sitetitle}" | |
+else | |
+ pagetitle="${title} - ${sitetitle}" | |
+fi | |
+ | |
+cat <<!__EOF__ | |
+<!DOCTYPE HTML> | |
+<html dir="ltr" lang="en"> | |
+ <head> | |
+ <title>${pagetitle}</title> | |
+ <link rel="stylesheet" href="style.css" type="text/css" media=… | |
+ <link rel="stylesheet" href="print.css" type="text/css" media=… | |
+ <link rel="alternate" type="application/rss+xml" title="${site… | |
+ <link rel="alternate" type="application/atom+xml" title="${sit… | |
+ <link rel="icon" type="image/png" href="/favicon.png" /> | |
+ <meta http-equiv="Content-Type" content="text/html; charset=UT… | |
+ <meta http-equiv="Content-Language" content="en" /> | |
+ <meta content="width=device-width" name="viewport" /> | |
+ <meta content="${keywords}" name="keywords" /> | |
+ <meta content="${description}" name="description" /> | |
+ </head> | |
+ <body> | |
+ <div id="menuwrap"> | |
+ <div id="menu"> | |
+ <span id="links"> | |
+ <a href="${siterelurl}/" title="Blog">… | |
+ <a href="/downloads/projects/" title="… | |
+ </span> | |
+ <span id="links-contact"> | |
+ <span class="hidden"> | </span> | |
+ <a href="rss.xml" title="Syndicate thi… | |
+ <a href="atom.xml" title="Atom feed" c… | |
+ <a href="mailto:${sitemail}" title="Ma… | |
+ </span> | |
+ </div> | |
+ </div> | |
+ <hr class="hidden" /> | |
+ <div id="mainwrap"> | |
+ <div id="main"> | |
+<h1>${title}</h1> | |
+<table> | |
+ ${content} | |
+</table> | |
+ </div> | |
+ </div> | |
+ </body> | |
+</html> | |
+!__EOF__ | |
diff --git a/site/layout/index/indexitem.sh b/site/layout/index/indexitem.sh | |
@@ -0,0 +1,3 @@ | |
+#!/bin/sh | |
+# row for index page. | |
+printf '<tr><td class="lm">%s</td><td><a href="%s" title="%s">%s</a></td></tr>… | |
diff --git a/site/layout/page/page.sh b/site/layout/page/page.sh | |
@@ -0,0 +1,50 @@ | |
+#!/bin/sh | |
+ | |
+# prefix page title with site title, make sure its neatly formatted. | |
+if [ "${title}" = "" ]; then | |
+ pagetitle="${sitetitle}" | |
+else | |
+ pagetitle="${title} - ${sitetitle}" | |
+fi | |
+ | |
+cat <<!__EOF__ | |
+<!DOCTYPE HTML> | |
+<html dir="ltr" lang="en"> | |
+ <head> | |
+ <title>${pagetitle}</title> | |
+ <link rel="stylesheet" href="style.css" type="text/css" media=… | |
+ <link rel="stylesheet" href="print.css" type="text/css" media=… | |
+ <link rel="alternate" type="application/rss+xml" title="${site… | |
+ <link rel="alternate" type="application/atom+xml" title="${sit… | |
+ <link rel="icon" type="image/png" href="/favicon.png" /> | |
+ <meta http-equiv="Content-Type" content="text/html; charset=UT… | |
+ <meta http-equiv="Content-Language" content="en" /> | |
+ <meta content="width=device-width" name="viewport" /> | |
+ <meta content="${keywords}" name="keywords" /> | |
+ <meta content="${description}" name="description" /> | |
+ </head> | |
+ <body> | |
+ <div id="menuwrap"> | |
+ <div id="menu"> | |
+ <span id="links"> | |
+ <a href="${siterelurl}/" title="Blog">… | |
+ <a href="/downloads/projects/" title="… | |
+ </span> | |
+ <span id="links-contact"> | |
+ <span class="hidden"> | </span> | |
+ <a href="rss.xml" title="Syndicate thi… | |
+ <a href="atom.xml" title="Atom feed" c… | |
+ <a href="mailto:${sitemail}" title="Ma… | |
+ </span> | |
+ </div> | |
+ </div> | |
+ <hr class="hidden" /> | |
+ <div id="mainwrap"> | |
+ <div id="main"> | |
+ <h1><a href="${urlrel}" title="${title}">${tit… | |
+ ${content} | |
+ </div> | |
+ </div> | |
+ </body> | |
+</html> | |
+!__EOF__ | |
diff --git a/layout/rss/rss.sh b/site/layout/rss/rss.sh | |
diff --git a/site/layout/rss/rssitem.sh b/site/layout/rss/rssitem.sh | |
@@ -0,0 +1,12 @@ | |
+#!/bin/sh | |
+ | |
+cat <<!__EOF__ | |
+<item> | |
+ <title>${title}</title> | |
+ <link>${urlfull}</link> | |
+ <pubDate>$(date -R -d "${timestamp}")</pubDate> | |
+ <author>${author}</author> | |
+ <guid isPermaLink="false">${urlfull}</guid> | |
+ <description><![CDATA[${description}]]></description> | |
+</item> | |
+!__EOF__ | |
diff --git a/pages/example-page-template.html b/site/pages/example-page-templat… | |
diff --git a/pages/example-page-template.sh b/site/pages/example-page-template.… |