morpheus-site

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

commit 0da97548a31e9d61b1ff571ac5ada8ba0e4aff57
parent 7545fb3e22b322e60b84d22f2f1f44ceb26f9667
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Mon Dec 16 20:54:55 +0100

cleanup code a bit

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

Diffstat:
generate.sh | 40+++++++++++++++++++++++-----------------
1 file changed, 23 insertions(+), 17 deletions(-)
diff --git a/generate.sh b/generate.sh @@ -36,20 +36,28 @@ loadconfig() { fi # load config: config is loaded here to be able to override above variables # (sfeedpath, sfeedfile, etc). - if [ -r "$config" ]; then - . "$config" + if [ -r "${config}" ]; then + . "${config}" else echo "$0 [configfile]" >&2 echo "" >&2 - echo "Configuration file \"$config\" does not exist or is not readable." >&2 + echo "Error: configuration file \"${config}\" does not exist or is not readable." >&2 exit 1 fi } +# Default config options. +markdown="smu" # default markdown processor. + # Read config file. loadconfig "$1" config="$1" +if [ ! -d "${pagesdir}" ]; then + echo "Error: pages directory \"${pagesdir}\" not found." >&2 + exit 1 +fi + # Try to make output dir. mkdir -p "${outputdir}" @@ -64,15 +72,16 @@ find "${pagesdir}" -name "*.sh" | while read -r page; do done | sort -rn | while read -r 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}") + urlfull="${siteurlfull}/${url}" + filename="" + if [ "$content" = "" ]; then # content not set: try data from file. + if [ -f "${pagesdir}/${pagename}.html" ]; then + filename="${pagesdir}/${pagename}.html" + content=$(cat "${filename}") + elif [ -f "${pagesdir}/${pagename}.md" ]; then + filename="${pagesdir}/${pagename}.md" + content=$("${markdown}" "${filename}") + fi fi . "${layoutdir}/page/page.sh" > "${outputdir}/${pagename}.html" . "${layoutdir}/index/indexitem.sh" >> "${outputdir}/index.html" @@ -100,7 +109,7 @@ content=$(cat "${outputdir}/atom.xml") cd "${outputdir}" # Sitemap: urllist.txt -find ./ -type f -name "*.html" | sort | sed 's@^./\(.*\)$@'${sitefullurl}'/\1@' > "urllist.txt" +find ./ -type f -name "*.html" | sort | sed 's@^./\(.*\)$@'${siteurlfull}'/\1@' > "urllist.txt" # Sitemap: sitemap.xml (cat <<! @@ -108,12 +117,9 @@ find ./ -type f -name "*.html" | sort | sed 's@^./\(.*\)$@'${sitefullurl}'/\1@' <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> ! -find ./ -type f -name "*.html" | sort | sed 's@^./\(.*\)$@<url><loc>'${sitefullurl}'/\1</loc></url>@' +find ./ -type f -name "*.html" | sort | sed 's@^./\(.*\)$@<url><loc>'${siteurlfull}'/\1</loc></url>@' cat <<! </urlset> ! ) > "sitemap.xml" - -# Restore current dir. -cd "${basedir}"