#!/bin/sh # Deps: GNU Sed, sdcv (>=0.5.2), jq, xargs, uniq, tail export STARDICT_DATA_DIR="/srv/www/data/" export LANG="en_US.UTF-8" log_dir="/srv/www/logs/" script_dir="/srv/www/scripts/" urldecode() { sed 's/^+*//;s/+*$//;s/++*/ /g;s/%/\\x/g' | xargs -0 printf; } query=$(echo "$QUERY_WORD" | urldecode) [ -f "${script_dir}aylant-${QUERY_DICT}.sed" ] && query=$(echo "$query" | "${script_dir}aylant-${QUERY_DICT}.sed") set_selected() { [ "$QUERY_DICT" = "$1" ] && echo selected; } last_searches() { sed '/^.*\t.*\t\-\t.*$/d;s/^.*\t.*\t\(.*\)\t.*$/\1<\/a> /' \ "${log_dir}dict-searches.log" | uniq -u -i | tail -24 | urldecode } exec_sdcv() { if [ -z "$QUERY_DICT" ] then sdcv --utf8-input --utf8-output -j -n "$query" else sdcv --utf8-input --utf8-output -j -n -x \ --data-dir "${STARDICT_DATA_DIR}/dic/${QUERY_DICT}" "$query" fi } parse_result() { jq -j -M --arg query "$query" --arg dict "$QUERY_DICT" ' if length == 0 then "

«" + $query + "» sözüne benzer bir söz yok.

" elif map(select(.word == $query)) | .[0].word == $query then (map(select(.word == $query)) | .[] | "

" + .dict + "

" + (.definition | sub("^\n";"") | gsub("\n";"
") | gsub("\t";" "))+"

") , (map(select(.word != $query)) | unique_by(.word) | .[] | ("

Benzer sözler: " + .word + "

")) else "

«" + $query + "» sözünün aynı bir söz bulunamadı, " + "ama ona benzeyen şu sözler var: ", (unique_by(.word) | .[] | "" + .word + " "),"

" end , "
"' } [ -n "$QUERY_DICT" ] && [ -f "${script_dir}aylant-${QUERY_DICT}.sed" ] && query=$(echo "$query" | "${script_dir}aylant-${QUERY_DICT}.sed") case "$REQUEST_URI" in (/\?q=*) printf "Location: /%s/%s\r\n\r\n" "$query" "$QUERY_DICT" ; exit ;; (*) printf "Content-type: text/html\r\n\r\n" ;; esac #if exec_sdcv | grep -q -x -F '[]' #then # printf "Status: 404\r\n\r\n" #elif echo "$REQUEST_URI" | grep -q '^/\?q\=*' #then # printf "Location: /%s/%s\r\n\r\n" "$query" "$QUERY_DICT" ; exit #else # printf "Content-type: text/html\r\n\r\n" #fi cat < ADT - Türk Dilleri Sözlükleri

${query}

$(exec_sdcv | parse_result)

Son arananlar: $(last_searches)

!__EOF__