Introduction
Introduction Statistics Contact Development Disclaimer Help
improve code-style: test, return error code in pageread and use it - static-sit…
git clone git://git.codemadness.org/static-site-scripts
Log
Files
Refs
README
LICENSE
---
commit d6b165007856597822d71ceaffa3d1f2e20e670a
parent 86117ef5bceb1de3cb6b394de263a422bc48fbd3
Author: Hiltjo Posthuma <[email protected]>
Date: Wed, 9 Mar 2016 22:01:41 +0100
improve code-style: test, return error code in pageread and use it
Diffstat:
M generate.sh | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
---
diff --git a/generate.sh b/generate.sh
@@ -74,38 +74,38 @@ pageread() {
dateupdated=$(printf '%s' "${timeupdated}" | cut -b 1-10)
# if ${id} is empty and title is set: create id based on title.
- if [ x"${id}" = x"" ] && [ ! x"${title}" = x"" ]; then
+ if test -z "${id}" && test -n "${title}"; then
id=$(makeid "${title}")
fi
- if [ x"${id}" = x"" ]; then
+ if test -z "${id}"; then
printf 'Warning: $id or $title not set in "%s", skipping...\n'…
- return
+ return 1
fi
- if [ x"${url}" = x"" ]; then
+ if test -z "${url}"; then
url="${id}.html"
fi
outfile="${id}.html"
urlfull="${siteurlfull}/${outfile}"
filename=""
# ${content} not set; try data from filetypes.
- if [ x"${content}" = x"" ]; then
- if [ -f "${pagesdir}/${basename}.html" ]; then
+ if test -z "${content}"; then
+ if test -f "${pagesdir}/${basename}.html"; then
filename="${pagesdir}/${basename}.html"
content=$(cat "${filename}")
- elif [ -f "${pagesdir}/${basename}.md" ]; then
+ elif test -f "${pagesdir}/${basename}.md"; then
filename="${pagesdir}/${basename}.md"
content=$("${markdown}" "${filename}")
fi
fi
created="<strong>Created on:</strong> ${datecreated}<br/>"
- if [ ! x"${datecreated}" = x"${dateupdated}" ]; then
+ if test "${datecreated}" != "${dateupdated}"; then
created="${created}<strong>Last update on:</strong> ${dateupda…
fi
}
pageheader() {
# prefix page title with site title, make sure its neatly formatted.
- if [ x"${title}" = x"" ]; then
+ if test -z "${title}"; then
pagetitle="${sitetitle}"
else
pagetitle="${title} - ${sitetitle}"
@@ -168,15 +168,15 @@ pagefooter() {
!__EOF__
}
-if [ ! -d "${pagesdir}" ]; then
+if ! test -d "${pagesdir}"; then
printf 'Error: pages directory "%s" not found.\n' "${pagesdir}" >&2
exit 1
fi
# process single page as argument (handy for testing a single page).
-if [ ! x"$1" = x"" ]; then
+if test -n "$1"; then
pagereset
- pageread "$1"
+ pageread "$1" || exit 1
pagecontent
exit 0
fi
@@ -193,7 +193,7 @@ contentatom=""
contentsitemap=""
while read -r meta; do
pagereset
- pageread "${meta}"
+ pageread "${meta}" || continue
pagecontent > "${outputdir}/${outfile}"
# index / posts item: append.
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.