~cadence/bliz

d7a1829f359ca24577655514d03977697f6575bf — Cadence Ember 11 months ago 4537e40
Add directory index preference
3 files changed, 40 insertions(+), 26 deletions(-)

M src/cgi.fish
M src/config.fish
M src/script-includes.fish
M src/cgi.fish => src/cgi.fish +38 -25
@@ 51,6 51,44 @@ if contains .. (string split -- / $req_path)
    exit
end

# directory listing
if test -d "$file_path"
    # ensure directory has trailing /
    if string match -q -- '*/' $req_path
        set -l default_index true
        for index in $serve_index
            if test -f "$file_path$index"
                set default_index false
                set req_path $req_path$index
                set file_path $file_path$index
                server_echo "Used index to rewrite to: $req_path"
            end
        end
        if $default_index
            gem_header 20 text/gemini
            echo "# Directory listing for $req_path"
            echo
            pushd $file_path
            if test $req_path != /
                echo '=> ..'
            end
            for file in (ls -pB)
                # ignore dotfiles, tildefiles, etc
                if string match -q -- '.*' $file; or string match -q -- '*~' $file
                    continue
                end
                echo "=> $file"
            end
            popd
            exit
        end
    else
        # add trailing / to directory
        gem_header 31 $req_path/
        exit
    end
end

# route request to file
if test -f "$file_path"
    if string match -q -- '*.bliz' $file_path


@@ 69,31 107,6 @@ if test -f "$file_path"
    exit
end

# directory listing
if test -d "$file_path"
    if string match -q -- '*/' $req_path
        gem_header 20 text/gemini
        echo "# Directory listing for $req_path"
        echo
        pushd $file_path
        if test $req_path != /
            echo '=> ..'
        end
        for file in (ls -pB)
            # ignore dotfiles, tildefiles, etc
            if string match -q -- '.*' $file; or string match -q -- '*~' $file
                continue
            end
            echo "=> $file"
        end
        popd
        exit
    else
        gem_header 31 $req_path/
        exit
    end
end

# not found
gem_header 50 "Bliz server: Not found: $req_path"
exit

M src/config.fish => src/config.fish +1 -0
@@ 4,6 4,7 @@ set ssl_cert_path certs/cert.pem
set ssl_key_path certs/key.pem

set serve_root serve
set serve_index # add arguments here for default index preference

set debug_server_echo false


M src/script-includes.fish => src/script-includes.fish +1 -1
@@ 1,4 1,4 @@
test -f ../personal/script-includes.fish; and source ../personal/script-includes.fish
test -f personal/script-includes.fish; and source personal/script-includes.fish

function bliz_word_count
    sed -n '/^%%%/,/^%%%/d;/^% /d;p' $blizfile | wc -w