tindex.dcgi - recipes - various cooking recipes HTML git clone git://src.adamsgaard.dk/recipes DIR Log DIR Files DIR Refs DIR Submodules --- tindex.dcgi (1818B) --- 1 #!/bin/sh 2 3 search="$1" 4 arguments="$2" 5 host="$3" 6 port="$4" 7 8 recipedir="recipes/" 9 10 printf '\n# EMPTY-THE-FRIDGE COOKING RECIPE SEARCH\n\n' 11 printf 'Search for one or more items which must appear in the\nrecipe ingredient list (space separated, case insensitive).\n' 12 13 gphfmt() { 14 while read -r l; do 15 if [ -f "$l" ]; 16 then 17 printf '[0|%s|/%s%s|server|port]\n' "$l" "$recipedir" "$l" 18 elif [ -f "$l" ]; 19 then 20 printf '[1|%s|/%s%s|server|port]\n' "$l" "$recipedir" "$l" 21 else 22 printf '%s\n' "$l" 23 fi 24 done 25 } 26 27 searchvegetarian=0 28 case "${arguments}" in 29 vegetarian*) 30 arguments="$(printf "%s\n" "${arguments}" | cut -c 11-)" 31 searchvegetarian=1 32 ;; 33 esac 34 [ -n "${search}" ] && arguments="${arguments}+${search}" 35 36 if [ -n "${arguments}" ]; 37 then 38 normalarguments="$(printf '%s\n' "${arguments}" | tr '+' ' ')" 39 if [ $searchvegetarian -eq 1 ]; 40 then 41 results="$(./cookwhatveg $normalarguments | gphfmt)" 42 else 43 results="$(./cookwhat $normalarguments | gphfmt)" 44 fi 45 46 n="$(printf '%s\n' "$results" | wc -l)" 47 if [ $n -gt 0 ] && [ -n "$results" ]; 48 then 49 if [ $n -gt 1 ]; 50 then 51 printf '\n## Results (%d recipes): %s\n' \ 52 "$n" "$normalarguments" 53 else 54 printf '\n## Just one result: %s\n' \ 55 "$normalarguments" 56 fi 57 printf '\n%s\n' "$results" 58 else 59 printf '\nNo recipes found for: %s\n' "$search" 60 fi 61 fi 62 63 printf '\n' 64 printf '[7|Find a recipe: _____________________________________________|/%s|server|port]\n' "$recipedir" 65 printf '[7|Find a vegetarian recipe: __________________________________|/%s?vegetarian|server|port]\n' "$recipedir" 66 67 printf '\n## Want to add a recipe?\n' 68 printf 'Please send a patch:\n' 69 printf '[h|git://src.adamsgaard.dk/recipes|URL:git://src.adamsgaard.dk/recipes|server|port]\n' 70 printf '[1|Source code view|/src/recipes|server|port]\n' 71 72 printf '\n[1|<< back|/|server|port]\n'