From 1cd4a538ca3b1c53a865977dc532187302716f90 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Mon, 25 Oct 2021 14:20:30 +0200 Subject: [PATCH] list_videos function including sorting --- db_video.sh | 23 +++++++++++++++++++++++ page_channel.sh | 4 +--- rawnet.css | 1 + widgets.sh | 9 ++------- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/db_video.sh b/db_video.sh index 05fe1e2..16bf434 100755 --- a/db_video.sh +++ b/db_video.sh @@ -161,3 +161,26 @@ delete_video() { return 1 fi } + +list_videos(){ + local order="${1:-newest}" vid_db="$_DATA/$CHANNEL_ID/videos.db" + [ "$CHANNEL_ID" ] || return 1 + + [ -f "$vid_db" -a -r "$vid_db" ] && case "$order" in + name) + sort -k2 "$vid_db" + ;; + shortest) + sort -n -k6 "$vid_db" + ;; + longest) + sort -rn -k6 "$vid_db" + ;; + oldest) + cat "$vid_db" + ;; + newest|*) + tac "$vid_db" + ;; + esac +} diff --git a/page_channel.sh b/page_channel.sh index f2d0738..36d9dcd 100755 --- a/page_channel.sh +++ b/page_channel.sh @@ -71,7 +71,6 @@ if [ "$CHANNEL_ID" -a "$action" = edit ]; then ] EOF elif [ "$CHANNEL_ID" ]; then - vid_db="$_DATA/$CHANNEL_ID/videos.db" yield_page "$CHANNEL_NAME" "channel" <<-EOF [nav [a href="../" Channels] - [span $(HTML "${CHANNEL_NAME:-(Unnamed Channel)}")]] [h1 .name $(HTML "$CHANNEL_NAME")] @@ -84,8 +83,7 @@ elif [ "$CHANNEL_ID" ]; then [hidden "video" "%s"] [submit "action" "newvideo" New Video] ]' "$(timeid)" - [ -f "$vid_db" -a -r "$vid_db" ] \ - && while w_video; do :; done <"$vid_db" + list_videos |while w_video; do :; done )] EOF else diff --git a/rawnet.css b/rawnet.css index 5fa017b..650da60 100644 --- a/rawnet.css +++ b/rawnet.css @@ -122,6 +122,7 @@ body.channels main .channel { body.channels main .channel > .description { overflow: hidden; + margin-right: -.5%; } body.channels main .channel > .description h2 { margin: 0; diff --git a/widgets.sh b/widgets.sh index f844ba4..b951216 100755 --- a/widgets.sh +++ b/widgets.sh @@ -34,21 +34,16 @@ w_video(){ } w_channel(){ - local vid_db eval "$LOCAL_CHANNEL" if read_channel; then - vid_db="${_DATA}/${CHANNEL_ID}/videos.db" - cat <<-EOF [div .channel [div .description [h2 [a href="${_BASE}/channel/${CHANNEL_ID}/" $(HTML "${CHANNEL_NAME:-(Unnamed Channel)}")]] ${CHANNEL_DESCR_CACHE} - ]$( - [ -f "$vid_db" -a -r "$vid_db" ] \ - && while w_video; do :; done <"$vid_db" - ) + ] + $( list_videos |while w_video; do :; done; ) ] EOF else -- 2.39.2