From: Paul Hänsch Date: Mon, 16 Jul 2018 22:07:55 +0000 (+0200) Subject: speed and code optimisations X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=bbf0a951d1ff6106d1d2dd8032333b1b1ccd67f2;p=serve0 speed and code optimisations --- diff --git a/index.cgi b/index.cgi index f5880c9..a8ddaa8 100755 --- a/index.cgi +++ b/index.cgi @@ -8,7 +8,6 @@ file_pattern='^.*\.(mov|ts|mpg|mpeg|mp4|m4v|avi|mkv|flv|sfv|wmv|ogm|ogv|webm|iso|rmvb)$' . "$_EXEC/cgilite/cgilite.sh" -. "$_EXEC/widgets.sh" FILTER="$(GET f)" SEARCH="$(GET s)" diff --git a/style.css b/style.css index d735b8b..0eba517 100644 --- a/style.css +++ b/style.css @@ -132,7 +132,7 @@ a[href="#advsearch"]:before { } #advsearch .help { display: block; - margin: -1em 1em 1em 1em; + margin: -1em .625em 1em .625em; padding: .5em 1em; background-color: #444; line-height: 1.5em; @@ -148,7 +148,7 @@ a[href="#advsearch"]:before { display: inline-block; vertical-align: top; margin: 0 .5% 1em .5%; - width: 4%; + width: 4%; min-width: 4em; padding: .5em 0; text-align: center; font-weight: bold; @@ -159,6 +159,7 @@ a[href="#advsearch"]:before { #advsearch input.and:checked + label:nth-of-type(2), #advsearch input.and:checked + label { display: none; } +#advsearch .submit, #advsearch input.and + label + .select:first-of-type, #advsearch input.and:checked + label + .select { display: inline-block; @@ -169,8 +170,12 @@ a[href="#advsearch"]:before { min-height: 12em; overflow: hidden; text-align: left; + vertical-align: top; } +#advsearch .submit { min-height: 0; } +#advsearch .submit * { width: 50%; } + #advsearch .select input.pol { margin: .5em .25em 0 .5em; } diff --git a/widgets.sh b/widgets.sh index 158df4b..3142b44 100644 --- a/widgets.sh +++ b/widgets.sh @@ -6,10 +6,12 @@ include_widgets="$0" . "$_EXEC/cgilite/storage.sh" w_refuri="$(HTML "$REQUEST_URI")" + w_tags="$(find "$_DATA/" -path '*/.index/meta' -print0 \ | xargs -r0 cut -f4 \ | cut -d= -f2- |tr , '\n' | sort -u)" w_tags="$(UNSTRING "$w_tags")" +w_tagcategories="$(printf %s "$w_tags" |cut -sd: -f1 |sort -u)" w_search(){ printf ' @@ -78,45 +80,41 @@ w_advsearch(){ ][fieldset .select [input .pol type="radio" name=pol_%i %s id="pol_pos_%i"][label for=pol_pos_%i Any] [input .pol type="radio" name=pol_%i %s id="pol_neg_%i"][label for=pol_neg_%i None] - [label .head Category:] - [input .cat type=radio name="cat_%i" %s id="%s" ][label for="%s" %s] - [select name=tag_%s size=10 multiple="multiple"' \ + [label .head Category:]' \ $n "$([ "$f" ] && printf 'checked="checked"')" $n \ - $n "$([ "$f" -a \! "${f%%~*}" ] || printf 'checked="checked"')" $n $n \ - $n "$([ "$f" -a \! "${f%%~*}" ] && printf 'checked="checked"')" $n $n \ - $n "$([ "$f" = "${f%:*}" ] && printf 'checked="checked"')" "$lbid" "$lbid" "(none)" \ - $n - + $n "$([ "$f" -a ! "${f%%~*}" ] || printf 'checked="checked"')" $n $n \ + $n "$([ "$f" -a ! "${f%%~*}" ] && printf 'checked="checked"')" $n $n f="|${f#~}|" - printf %s "$w_tags" |grep -vF ":" \ - | while read -r tag; do - [ ! "$tag" ] && continue - tg="$(HTML "$tag")" - printf '[option %s value="%s" %s]' \ - "$([ "$f" != "${f%|${tag}|*}" ] && printf 'selected="selected"')" \ - "$tg" "$tg" - done - printf ']' - printf %s "$w_tags" |cut -sd: -f1 |sort -u \ + + printf '*\n%s\n' "$w_tagcategories" \ | while read -r category; do lbid="$(HTML "cat_${n}_${category}")" - printf '[input .cat type=radio name="cat_%i" %s id="%s"][label for="%s" %s] + printf '[input .cat type=radio %s name="cat_%i" id="%s"][label for="%s" %s] [select name=tag_%s size=10 multiple="multiple"' \ - $n "$([ "$f" != "${f%|${category}:*}" ] && printf 'checked="checked"')" \ - "$lbid" "$lbid" "$(HTML "$category")" $n - printf %s "$w_tags" |grep -wF "${category}" \ + "$([ ! "${f%%*|${category}:*}" -o ! "${category%\*}" ] && printf 'checked="checked"')" \ + $n "$lbid" "$lbid" "$(HTML "$category")" $n + + printf %s "$w_tags" \ + | { [ "$category" = '*' ] && grep -vF ':' || grep -wF "${category}"; } \ | while read -r tag; do + [ ! "$tag" ] && continue tg="$(HTML "$tag")"; tn="${tg#*:}" printf '[option %s value="%s" %s]' \ - "$([ "$f" != "${f%|${tag}|*}" ] && printf 'selected="selected"')" \ + "$([ ! "${f%%*|${tag}|*}" ] && printf 'selected="selected"')" \ "$tg" "$tn" done - printf ']' + printf '\n]' done printf ']' done - printf ']' + printf '[fieldset .submit [select name=order + [option disabled=disabled Order By] + [option value=Name Name] + [option value=Date Date] + [option value=Length Length] + ][button type=submit Apply Filter]] + ]' } w_tagging(){ @@ -124,19 +122,13 @@ w_tagging(){ printf '[div #multitag [input type="hidden" name="ref" value="%s"]' "$w_refuri" printf '[a href="#" Hide][br]' - printf '[fieldset [legend %s:][select name=tag size=4 multiple' "Tags" - printf %s "$w_tags" |grep -vF ":" \ - | while read -r tag; do - [ ! "$tag" ] && continue - printf '[option value="%s" %s]' "$(HTML "$tag")" "$(HTML "$tag")" - done - printf ']]' - - printf %s "$w_tags" |cut -sd: -f1 |sort -u \ + printf 'Tags\n%s\n' "$w_tagcategories" \ | while read -r category; do printf '[fieldset [legend %s:][select name=tag size=4 multiple' "$(HTML "$category")" - printf %s "$w_tags" |grep -wF "${category}" \ + printf %s "$w_tags" \ + | { [ "$category" = 'Tags' ] && grep -vF ':' || grep -wF "${category}"; } \ | while read -r tag; do + [ ! "$tag" ] && continue tag="$(HTML "$tag")"; tn="${tag#*:}" printf '[option value="%s" %s]' "$tag" "$tn" done