tAllow purely arguments control of the search output. - recipes - various cooking recipes HTML git clone git://src.adamsgaard.dk/recipes DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 1d6448b2fe5caab14f9afcf88d97635be94b447e DIR parent e0edbfac7024dc6f6ca06752839ef819120db3d3 HTML Author: Christoph Lohmann <20h@r-36.net> Date: Fri, 27 Aug 2021 14:49:13 +0200 Allow purely arguments control of the search output. * Format the source to a congruent if style. * allow '+' as space replacement for complex scripted search index.dcgi?vegetarian+milk+cabbage index.dcgi?milk+cabbage Diffstat: M index.dcgi | 42 ++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 12 deletions(-) --- DIR diff --git a/index.dcgi b/index.dcgi t@@ -8,14 +8,15 @@ port="$4" recipedir="recipes/" printf '\n# EMPTY-THE-FRIDGE COOKING RECIPE SEARCH\n\n' -printf 'Search for one or more items which must appear in the recipe -ingredient list (space separated, case insensitive).\n' +printf 'Search for one or more items which must appear in the\nrecipe ingredient list (space separated, case insensitive).\n' gphfmt() { while read -r l; do - if test -f "$l"; then + if [ -f "$l" ]; + then printf '[0|%s|/%s%s|server|port]\n' "$l" "$recipedir" "$l" - elif test -f "$l"; then + elif [ -f "$l" ]; + then printf '[1|%s|/%s%s|server|port]\n' "$l" "$recipedir" "$l" else printf '%s\n' "$l" t@@ -23,19 +24,35 @@ gphfmt() { done } -if test -n "${search}"; then - if test "${arguments}" = "vegetarian"; then - results="$(./cookwhatveg $search | gphfmt)" +searchvegetarian=0 +case "${arguments}" in +vegetarian*) + arguments="$(printf "%s\n" "${arguments}" | cut -c 11-)" + searchvegetarian=1 + ;; +esac +[ -n "${search}" ] && arguments="${arguments}+${search}" + +if [ -n "${arguments}" ]; +then + normalarguments="$(printf "${arguments}\n" | tr '+' ' ')" + if [ $searchvegetarian -eq 1 ]; + then + results="$(./cookwhatveg "$normalarguments" | gphfmt)" else - results="$(./cookwhat $search | gphfmt)" + results="$(./cookwhat "$normalarguments" | gphfmt)" fi n="$(printf '%s' "$results" | wc -l)" - if test "$n" -gt 0; then - if test "$n" -gt 1; then - printf '\n## Results (%d recipes): "%s" \n' "$n" "$search" + if [ $n -gt 0 ]; + then + if [ $n -gt 1 ]; + then + printf '\n## Results (%d recipes): "%s" \n' \ + "$n" "$normalarguments" else - printf '\n## Just one result: "%s" \n' "$search" + printf '\n## Just one result: "%s" \n' \ + "$normalarguments" fi printf '\n%s\n' "$results" else t@@ -53,3 +70,4 @@ printf '[h|git://src.adamsgaard.dk/recipes|URL:git://src.adamsgaard.dk/recipes|s printf '[1|Source code view|/src/recipes|server|port]\n' printf '\n[1|<< back|/|server|port]\n' +