morpheus-site

morpheus.2f30.org website
git clone git://git.2f30.org/morpheus-site
Log | Files | Refs | README | LICENSE

commit acdd7813ab6db1ee9b83e7f224966b37b968ccc1
parent 9051ca6cbee74f640b22bebaeda165b043eee7e3
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun, 15 Dec 2013 16:41:42 +0100

initial repo

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>

Diffstat:
A.gitignore | 1+
MREADME.md | 20++++++++++++++++----
Aconfig.sh | 33+++++++++++++++++++++++++++++++++
Agenerate.sh | 115+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Alayout/atom/atom.sh | 14++++++++++++++
Alayout/atom/atomitem.sh | 16++++++++++++++++
Alayout/index/index.sh | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Alayout/index/indexitem.sh | 3+++
Alayout/page/page.sh | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Alayout/rss/rss.sh | 14++++++++++++++
Alayout/rss/rssitem.sh | 12++++++++++++
Apages/example-page-template.html | 1+
Apages/example-page-template.sh | 10++++++++++
Aprint.css | 12++++++++++++
Astyle.css | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15 files changed, 419 insertions(+), 4 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1 @@ +output/ diff --git a/README.md b/README.md @@ -1,4 +1,16 @@ -static-site-scripts -=================== - -Generate a simple static site with an index page +Usage +===== + +sh generate.sh [configfile] + +the default config file is ./config.sh + + +Pages +===== + +Pages are defined as shellscripts containing metadata (see pages/example-page-template.sh). + +The page content is the basename of the shellscript + .html (see pages/example-page-template.html). Markdown should be supported, but is untested for now. + +<insert you favorite template language> can easily be added to generate.sh. diff --git a/config.sh b/config.sh @@ -0,0 +1,33 @@ +# Fix for running on Cygwin =/ +export PATH="/bin:/usr/bin" + +# Site title (part of $pagetitle probably). +sitetitle="Codemadness" +# Main site domain. +sitedomain="http://www.codemadness.nl" +# Short site domain. +sitedomainshort="codemadness.nl" +# Relative site url. +siterelurl="" +# Full site url. +sitefullurl="${sitedomain}${siterelurl}" +# Site keywords (default). +sitekeywords="blog, suckless, dwm-hiltjo" +# Site description (default). +sitedescription="blog with various projects and articles about computer-related things" +# Admin mail, handy to use on site. +# TODO: remove adminmail? +adminmail="hiltjo@AT@codemadness.DOT.org" +# used for "mail link" +sitemail="hiltjo@AT@codemadness.DOT.org" + +# Directories containing content and metadata. +pagesdir="pages" +# Output dir. +outputdir="output" + +# Layout file. +layoutdir="layout" + +# TODO: markdown program: http://freecode.com/projects/smu +markdown="smu" diff --git a/generate.sh b/generate.sh @@ -0,0 +1,115 @@ +#!/bin/sh +# Generate a simple static site with an index page. +# Author: Hiltjo Posthuma <hiltjo@codemadness.org> +# License: WTFPL + +# Syntax highlight code. +code_highlight() { + echo '<pre>' + # escape some HTML entities, prefix code with linenumbers. + sed -e 's@&@\&amp;@g' -e 's@>@\&gt;@g' -e 's@<@\&lt;@g' | nl -w 4 -s ' ' + echo '</pre>' +} + +# page_metadata(filename) +page_metadata() { + id="" + tags="" + title="" + url="" + pagetitle="" + description="${sitedescription}" + keywords="${sitekeywords}" + filename="" + content="" + categories="" + timestamp="" + [ -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 + +# Remember current dir. +pwddir="$(pwd)" + +# 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" +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" + 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 + # TODO: test markdown + 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" +done + +# Index page. +page_metadata "" +title="Posts" +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" + +# Atom +page_metadata "" +content=$(cat "$outputdir/atom.xml") +. "$layoutdir/atom/atom.sh" > "$outputdir/atom.xml" + +# Goto output dir to make relative urls. +cd "$outputdir" + +# Sitemap: urllist.txt +find ./ -type f -name "*.html" | sort | sed 's@^./\(.*\)$@'$sitefullurl'/\1@' > "urllist.txt" + +# Sitemap: sitemap.xml +(cat <<! +<?xml version="1.0" encoding="UTF-8"?> +<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> +! + +find ./ -type f -name "*.html" | sort | sed 's@^./\(.*\)$@<url><loc>'$sitefullurl'/\1</loc></url>@' + +cat <<! +</urlset> +! +) > "sitemap.xml" + +# Restore current dir. +cd "$pwddir" + +# Copy stylesheets. +cp "style.css" "$outputdir" +cp "print.css" "$outputdir" diff --git a/layout/atom/atom.sh b/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.xml" /> + ${content} +</feed> +!__EOF__ diff --git a/layout/atom/atomitem.sh b/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/layout/index/index.sh b/layout/index/index.sh @@ -0,0 +1,51 @@ +#!/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="screen" /> + <link rel="stylesheet" href="print.css" type="text/css" media="print" /> + <link rel="alternate" type="application/rss+xml" title="Codemadness RSS Feed" href="rss.xml" /> + <link rel="alternate" type="application/atom+xml" title="Codemadness Atom Feed" href="atom.xml" /> + <link rel="icon" type="image/png" href="/favicon.png" /> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta http-equiv="Content-Language" content="en" /> + <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">Blog</a> | + <a href="/downloads/projects/" title="Software I've written">Software</a> + </span> + <span id="links-contact"> + <span class="hidden"> | </span> + <a href="rss.xml" title="Syndicate this site using RSS 2.0" class="rss">RSS</a> | + <a href="atom.xml" title="Atom feed" class="atom">Atom</a> | + <a href="mailto:${sitemail}" title="Mail me" class="mail">Mail</a> + </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 @@ -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>\n' "$timestamp" "${url}" "$description" "$title" diff --git a/layout/page/page.sh b/layout/page/page.sh @@ -0,0 +1,49 @@ +#!/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="screen" /> + <link rel="stylesheet" href="print.css" type="text/css" media="print" /> + <link rel="alternate" type="application/rss+xml" title="Codemadness RSS Feed" href="rss.xml" /> + <link rel="alternate" type="application/atom+xml" title="Codemadness Atom Feed" href="atom.xml" /> + <link rel="icon" type="image/png" href="/favicon.png" /> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta http-equiv="Content-Language" content="en" /> + <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">Blog</a> | + <a href="/downloads/projects/" title="Software I've written">Software</a> + </span> + <span id="links-contact"> + <span class="hidden"> | </span> + <a href="rss.xml" title="Syndicate this site using RSS 2.0" class="rss">RSS</a> | + <a href="atom.xml" title="Atom feed" class="atom">Atom</a> | + <a href="mailto:${sitemail}" title="Mail me" class="mail">Mail</a> + </span> + </div> + </div> + <hr class="hidden" /> + <div id="mainwrap"> + <div id="main"> + <h1><a href="${urlrel}" title="${title}">${title}</a></h1> + ${content} + </div> + </div> + </body> +</html> +!__EOF__ diff --git a/layout/rss/rss.sh b/layout/rss/rss.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +cat <<!__EOF__ +<?xml version="1.0" encoding="UTF-8"?> +<rss version="2.0"> + <channel> + <title>${sitetitle}</title> + <link>${sitefullurl}</link> + <description></description> + <language>en</language> + ${content} + </channel> +</rss> +!__EOF__ diff --git a/layout/rss/rssitem.sh b/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/pages/example-page-template.html @@ -0,0 +1 @@ +Hai there diff --git a/pages/example-page-template.sh b/pages/example-page-template.sh @@ -0,0 +1,10 @@ +#!/bin/sh +title="title" +description="description" +id="example-page-template" +url="${id}.html" +tags="tags, comma, separated" +keywords="keywords, comma, separated" +categories="Category name" +timestamp="now" +author="author" diff --git a/print.css b/print.css @@ -0,0 +1,12 @@ +body { + text-align: left; +} +#menuwrap { + display: none; +} +#menu, #main { + margin: 0; +} +pre, code { + white-space: pre-wrap; +} diff --git a/style.css b/style.css @@ -0,0 +1,72 @@ +body { + font-family: sans-serif, monospace; + text-align: center; + overflow-y: scroll; + color: #333; + background-color: #fff; + margin: 0; + padding: 0; +} +table { + border: 0; +} +hr { + height: 1px; + color: #ccc; + background-color: #ccc; + border: 0; +} +h1 { + font-size: 140%; +} +h2 { + font-size: 120%; +} +h3 { + font-size: 100%; +} +h1, h1 a, h1 a:visited, +h2, h2 a, h2 a:visited, +h3, h3 a, h3 a:visited, +h1 a:hover, h2 a:hover, h3 a:hover { + color: inherit; + text-decoration: none; +} +table tr td { + padding: 2px 10px 2px 0px; +} +pre, code { + border: 1px dashed #777; + background-color: #eee; + padding: 5px; + display: block; + overflow-x: auto; +} +code { + white-space: nowrap; + word-wrap: normal; +} +#menuwrap { + background-color: #eee; + padding: 1ex; + border-bottom: 1px solid #ccc; +} +#main { + padding: 1ex; +} +#menu, +#main { + margin: 0px auto; + text-align: left; + max-width: 80ex; +} +#menu a { + font-weight: bold; + vertical-align: middle; +} +#links-contact { + float: right; +} +.hidden { + display: none; +}