From f3f1f5e7a7cb23230d623b02773b75ea997ea241 Mon Sep 17 00:00:00 2001 From: Viktor Kleen Date: Fri, 2 Jan 2015 14:50:48 +0000 Subject: Implement previews of lists in the index --- lists/default.md.do | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'lists') diff --git a/lists/default.md.do b/lists/default.md.do index 94636df..daf7453 100644 --- a/lists/default.md.do +++ b/lists/default.md.do @@ -5,7 +5,7 @@ POSTS=() while read -r -d $'\0'; do post=$(realpath --relative-to=. "$REPLY") POSTS+=("$post") -done < <(find "$2" -maxdepth 1 -mindepth 1 -not -name 'title' -print0 | sort -z) +done < <(find "$2" -maxdepth 1 -mindepth 1 -not -name 'title' -not -name 'preview' -print0 | sort -z) for x in "${POSTS[@]}"; do printf "%s\0%s\0" "$x" "${x%.md}.html" @@ -18,7 +18,23 @@ cat <&1 >/dev/null) - printf "* [%s](%s)\n" "$title" "${x%.md}.html" + POST_TITLES+=("$title") +done + +for n in $(seq 0 $((${#POSTS[@]}-1))); do + printf "* [%s](%s)\n" "${POST_TITLES[$n]}" "${POSTS[$n]%.md}.html" +done + +prev_no=3 +if [[ ${#POSTS[@]} -gt $prev_no ]]; then + printf "* …\n" > "$2/preview" +else + prev_no=${#POSTS[@]} +fi + +for n in $(seq $prev_no -1 1); do + printf "* [%s](%s)\n" "${POST_TITLES[-$n]}" "${POSTS[-$n]%.md}.html" >"$2/preview" done -- cgit v1.2.3