morpheus-site

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

commit dee3000de975dabe546a8fc9ab5700cda891063a
parent 20caaadb4840307b4601a4ff4019c2efd93bdb53
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Mon, 24 Mar 2014 22:06:03 +0100

consistency, cleanup, pagecontent is a function now

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

Diffstat:
Mgenerate.sh | 114+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
1 file changed, 65 insertions(+), 49 deletions(-)

diff --git a/generate.sh b/generate.sh @@ -27,8 +27,14 @@ outputdir="output" # Markdown processor: default: is "smu". markdown="smu" +#makeid(title), format "Some title" to "some-title". +makeid() { + printf '%s\n' "$1" | tr '[:upper:]' '[:lower:]' | sed -e 's@[^a-zA-Z0-9]\+@-@g' \ + -e 's@[-]*$@@g' -e 's@^[-]*@@g' +} + # initial values for page variables, use some site vars as global defaults. -page_reset() { +pagereset() { id="" title="" url="" @@ -44,10 +50,41 @@ page_reset() { dateupdated="" } -#makeid(title), format "Some title" to "some-title". -makeid() { - printf '%s\n' "$1" | tr '[:upper:]' '[:lower:]' | sed -e 's@[^a-zA-Z0-9]\+@-@g' \ - -e 's@[-]*$@@g' -e 's@^[-]*@@g' +pageread() { + meta="$1" + . "$meta" # source page metadata. + basename=$(basename "${meta}" ".sh") + datecreated=$(printf '%s' "${timecreated}" | cut -b 1-10) + dateupdated=$(printf '%s' "${timeupdated}" | cut -b 1-10) + + # if ${id} is empty and title is set: create id based on title. + if [ "${id}" = "" ] && [ ! "${title}" = "" ]; then + id=$(makeid "${title}") + fi + if [ "${id}" = "" ]; then + printf '%s\n' "Warning: \$id or \$title not set in \"${meta}\", skipping..." >&2 + continue + fi + if [ "${url}" = "" ]; then + url="${id}.html" + fi + outfile="${id}.html" + urlfull="${siteurlfull}/${outfile}" + filename="" + # ${content} not set; try data from filetypes. + if [ "${content}" = "" ]; then + if [ -f "${pagesdir}/${basename}.html" ]; then + filename="${pagesdir}/${basename}.html" + content=$(cat "${filename}") + elif [ -f "${pagesdir}/${basename}.md" ]; then + filename="${pagesdir}/${basename}.md" + content=$("${markdown}" "${filename}") + fi + fi + created="<strong>Created on:</strong> ${datecreated}<br/>" + if [ ! "${datecreated}" = "${dateupdated}" ]; then + created="${created}<strong>Last update on:</strong> ${dateupdated}<br/>" + fi } pageheader() { @@ -96,6 +133,16 @@ pageheader() { !__EOF__ } +pagecontent() { + pageheader + cat <<!__EOF__ + <h1><a href="">${title}</a></h1> + <em>${created}</em> + ${content} +!__EOF__ + pagefooter +} + pagefooter() { cat <<!__EOF__ </div> @@ -110,57 +157,26 @@ if [ ! -d "${pagesdir}" ]; then exit 1 fi +# process single page as argument (handy for testing a single page). +if [ ! "$1" = "" ]; then + pagereset + pageread "$1" + pagecontent + exit 0 +fi + # try to make output dir. mkdir -p "${outputdir}" -> "${outputdir}/urllist.txt" # truncate urllist.txt +> "${outputdir}/urllist.txt" # truncate urllist.txt (sitemap). contentindex="" contentrss="" contentatom="" contentsitemap="" while read -r meta; do - page_reset - basename=$(basename "${meta}" ".sh") - - . "$meta" # source page metadata. - datecreated=$(printf '%s' "${timecreated}" | cut -b 1-10) - dateupdated=$(printf '%s' "${timeupdated}" | cut -b 1-10) - - # if ${id} is empty and title is set: create id based on title. - if [ "${id}" = "" ] && [ ! "${title}" = "" ]; then - id=$(makeid "${title}") - fi - if [ "${id}" = "" ]; then - printf '%s\n' "Warning: \$id or \$title not set in \"${meta}\", skipping..." >&2 - continue - fi - if [ "${url}" = "" ]; then - url="${id}.html" - fi - outfile="${id}.html" - urlfull="${siteurlfull}/${outfile}" - filename="" - # ${content} not set; try data from filetypes. - if [ "${content}" = "" ]; then - if [ -f "${pagesdir}/${basename}.html" ]; then - filename="${pagesdir}/${basename}.html" - content=$(cat "${filename}") - elif [ -f "${pagesdir}/${basename}.md" ]; then - filename="${pagesdir}/${basename}.md" - content=$("${markdown}" "${filename}") - fi - fi - created="<strong>Created on:</strong> ${datecreated}<br/>" - if [ ! "${datecreated}" = "${dateupdated}" ]; then - created="${created}<strong>Last update on:</strong> ${dateupdated}<br/>" - fi - (pageheader - cat <<!__EOF__ - <h1><a href="">${title}</a></h1> - <em>${created}</em> - ${content} -!__EOF__ - pagefooter) > "${outputdir}/${outfile}" + pagereset + pageread "$meta" + pagecontent > "${outputdir}/${outfile}" # index / posts item: append. contentindex="${contentindex}$(cat <<!__EOF__ @@ -219,7 +235,7 @@ $(find "${pagesdir}" -type f -name "*.sh" | sort -rn) # standard manner). # index page. -page_reset +pagereset title="Posts" (pageheader cat <<!__EOF__