morpheus-site

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

commit 928dd12f6c8ce14c883773f26eca4cc69a59848e
parent 3d19254a303d415ca128ce07605f336f76e394b1
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun,  2 Mar 2014 12:00:58 +0100

various fixes

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

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

diff --git a/generate.sh b/generate.sh @@ -3,15 +3,13 @@ sitetitle="Codemadness" # main site domain. sitedomain="http://www.codemadness.nl" -# short site domain. -sitedomainshort="codemadness.nl" -# relative site url. +# relative site url, can be "/blog" or something. siteurlrel="" # full site url. siteurlfull="${sitedomain}${siteurlrel}" -# site keywords (default). +# site keywords (global default), don't use too many. sitekeywords="blog, suckless, dwm-hiltjo" -# site description (default). +# site description (global default). sitedescription="blog with various projects and articles about computer-related things" # sitem mail used for contact "mail link". sitemail="hiltjo@AT@codemadness.DOT.org" @@ -19,7 +17,6 @@ sitemail="hiltjo@AT@codemadness.DOT.org" siteauthor="hiltjo" # site last updated (default use date when script was run). siteupdated=$(date "+%Y-%m-%dT%H:%M:%SZ") - # Directories containing content and metadata. # NOTE: it's recommended to use absolute paths here. pagesdir="pages" @@ -28,25 +25,24 @@ outputdir="output" # Markdown processor: default: is "smu". markdown="smu" -# initial values for page variables. -#page_reset() +# initial values for page variables, use some site vars as global defaults. page_reset() { id="" - tags="" title="" url="" description="${sitedescription}" keywords="${sitekeywords}" + author="${siteauthor}" content="" + tags="" categories="" timecreated="" datecreated="" timeupdated="" dateupdated="" - author="${siteauthor}" } -#makeid(title) +#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' @@ -81,6 +77,7 @@ pageheader() { <meta content="width=device-width" name="viewport" /> <meta content="${keywords}" name="keywords" /> <meta content="${description}" name="description" /> + <meta content="${author}" name="author" /> </head> <body> <div id="menuwrap"> @@ -114,7 +111,7 @@ pagefooter() { } if [ ! -d "${pagesdir}" ]; then - echo "Error: pages directory \"${pagesdir}\" not found." >&2 + printf '%s\n' "Error: pages directory \"${pagesdir}\" not found." >&2 exit 1 fi @@ -134,16 +131,21 @@ while read -r meta; do datecreated=$(printf '%s' "${timecreated}" | cut -b 1-10) dateupdated=$(printf '%s' "${timeupdated}" | cut -b 1-10) - # set unset variables. + # if ${id} is empty and title is set generate id. 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 - urlfull="${siteurlfull}/${url}" + outfile="${id}.html" + urlfull="${siteurlfull}/${outfile}" filename="" - # content not set; try data from filetypes. + # ${content} not set; try data from filetypes. if [ "${content}" = "" ]; then if [ -f "${pagesdir}/${basename}.html" ]; then filename="${pagesdir}/${basename}.html" @@ -151,13 +153,8 @@ while read -r meta; do elif [ -f "${pagesdir}/${basename}.md" ]; then filename="${pagesdir}/${basename}.md" content=$("${markdown}" "${filename}") -# elif [ -f "${pagesdir}/${basename}.txt" ]; then -# filename="${pagesdir}/${basename}.txt" -# content=$(cat "${filename}") -# content="<pre>${content}</pre>" fi fi - # page if [ "${datecreated}" = "${dateupdated}" ]; then created="<strong>Created on:</strong> ${dateupdated}<br/>" else @@ -166,17 +163,21 @@ while read -r meta; do fi (pageheader cat <<!__EOF__ - <h1><a href="${siteurlrel}/${url}" title="${title}">${title}</a></h1> + <h1><a href="">${title}</a></h1> <em>${created}</em> ${content} !__EOF__ - pagefooter) > "${outputdir}/${url}" + pagefooter) > "${outputdir}/${outfile}" - # index: append item on index page. - contentindex="${contentindex}<tr><td class=\"lm\">${dateupdated}</td> - <td><a href=\"${url}\" title=\"${description}\">${title}</a></td></tr>" + # index / posts item: append. + contentindex="${contentindex}$(cat <<!__EOF__ + <tr><td class="lm">${dateupdated}</td> + <td><a href="${url}" title="${description}">${title}</a></td></tr> +!__EOF__ +)" - # RSS item: append + # RSS item: append. + # NOTE: GMT is hard-coded since %z is not consistent, change accordingly. contentrsspubdate=$(date "+%a, %d %b %Y %H:%M:%S GMT" -d "${timeupdated}") contentrss="${contentrss}$( cat <<!__EOF__ @@ -185,20 +186,20 @@ while read -r meta; do <link>${urlfull}</link> <pubDate>${contentrsspubdate}</pubDate> <author>${author}</author> - <guid isPermaLink=\"false\">${urlfull}</guid> + <guid isPermaLink="false">${urlfull}</guid> <description><![CDATA[${description}]]></description> </item> !__EOF__ )" - # Atom item: append + # Atom item: append. contentatomupdated=$(date "+%Y-%m-%dT%H:%M:%SZ" -d "${timeupdated}") contentatompublished=$(date "+%Y-%m-%dT%H:%M:%SZ" -d "${timecreated}") contentatom="${contentatom}$( cat <<!__EOF__ <entry> - <title type=\"html\"><![CDATA[${title}]]></title> - <link rel=\"alternate\" type=\"text/html\" href=\"${urlfull}\" /> + <title type="html"><![CDATA[${title}]]></title> + <link rel="alternate" type="text/html" href="${urlfull}" /> <id>${urlfull}</id> <updated>${contentatomupdated}</updated> <published>${contentatompublished}</published> @@ -206,7 +207,7 @@ while read -r meta; do <name>${author}</name> <uri>${siteurlfull}</uri> </author> - <summary type=\"html\"><![CDATA[${description}]]></summary> + <summary type="html"><![CDATA[${description}]]></summary> </entry> !__EOF__ )" @@ -214,7 +215,7 @@ while read -r meta; do # sitemap: sitemap.xml, append item. contentsitemap="${contentsitemap}<url><loc>${urlfull}</loc></url>" - # sitemap: urllist.txt, just write directly. + # sitemap: urllist.txt, append item write directly to file. printf '%s\n' "${urlfull}" >> "${outputdir}/urllist.txt" done <<!FILELIST $(find "${pagesdir}" -type f -name "*.sh" | sort -rn)