feat: custom directory indexes
This commit is contained in:
52
kewt.sh
52
kewt.sh
@@ -811,12 +811,21 @@ eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type d -print" | sort | while
|
|||||||
|
|
||||||
[ "$dir_indexes" != "true" ] && continue
|
[ "$dir_indexes" != "true" ] && continue
|
||||||
|
|
||||||
if [ ! -f "$dir/index.md" ]; then
|
has_custom_index="false"
|
||||||
|
has_list="false"
|
||||||
|
if [ -f "$dir/index.md" ]; then
|
||||||
|
has_custom_index="true"
|
||||||
|
if grep -q '{{LIST}}' "$dir/index.md" 2>/dev/null; then
|
||||||
|
has_list="true"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$has_custom_index" = "false" ] || [ "$has_list" = "true" ]; then
|
||||||
is_posts_dir="false"
|
is_posts_dir="false"
|
||||||
if [ -n "$posts_dir" ] && { [ "$rel_dir" = "$posts_dir" ] || [ "./$rel_dir" = "$posts_dir" ]; }; then
|
if [ -n "$posts_dir" ] && { [ "$rel_dir" = "$posts_dir" ] || [ "./$rel_dir" = "$posts_dir" ]; }; then
|
||||||
is_posts_dir="true"
|
is_posts_dir="true"
|
||||||
fi
|
fi
|
||||||
if [ "$single_file_index" = "true" ] && [ "$is_posts_dir" = "false" ]; then
|
if [ "$single_file_index" = "true" ] && [ "$is_posts_dir" = "false" ] && [ "$has_list" = "false" ]; then
|
||||||
md_count=$(find "$dir" ! -name "$(basename "$dir")" -prune -name "*.md" | wc -l)
|
md_count=$(find "$dir" ! -name "$(basename "$dir")" -prune -name "*.md" | wc -l)
|
||||||
if [ "$md_count" -eq 1 ]; then
|
if [ "$md_count" -eq 1 ]; then
|
||||||
md_file=$(find "$dir" ! -name "$(basename "$dir")" -prune -name "*.md")
|
md_file=$(find "$dir" ! -name "$(basename "$dir")" -prune -name "*.md")
|
||||||
@@ -831,10 +840,16 @@ eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type d -print" | sort | while
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
temp_index="$KEWT_TMPDIR/index.md"
|
temp_index="$KEWT_TMPDIR/index.md"
|
||||||
|
temp_list="$KEWT_TMPDIR/list.md"
|
||||||
|
: > "$temp_list"
|
||||||
|
|
||||||
|
if [ "$has_custom_index" = "false" ]; then
|
||||||
display_dir="${rel_dir#.}"
|
display_dir="${rel_dir#.}"
|
||||||
[ -z "$display_dir" ] && display_dir="/"
|
[ -z "$display_dir" ] && display_dir="/"
|
||||||
echo "# Index of $display_dir" > "$temp_index"
|
echo "# Index of $display_dir" > "$temp_index"
|
||||||
echo "" >> "$temp_index"
|
echo "" >> "$temp_index"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
sort_args=""
|
sort_args=""
|
||||||
# If this is the posts dir reverse
|
# If this is the posts dir reverse
|
||||||
@@ -848,7 +863,7 @@ eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type d -print" | sort | while
|
|||||||
template.html|site.conf|style.css|index.md) continue ;;
|
template.html|site.conf|style.css|index.md) continue ;;
|
||||||
esac
|
esac
|
||||||
if [ -d "$entry" ]; then
|
if [ -d "$entry" ]; then
|
||||||
echo "- [${name}/](${name}/index.html)" >> "$temp_index"
|
echo "- [${name}/](${name}/index.html)" >> "$temp_list"
|
||||||
elif [ "${entry%.md}" != "$entry" ]; then
|
elif [ "${entry%.md}" != "$entry" ]; then
|
||||||
label="${name%.md}"
|
label="${name%.md}"
|
||||||
|
|
||||||
@@ -916,18 +931,37 @@ eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type d -print" | sort | while
|
|||||||
label="$p_date $p_time"
|
label="$p_date $p_time"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
echo "- [$label](${name%.md}.html)" >> "$temp_index"
|
echo "- [$label](${name%.md}.html)" >> "$temp_list"
|
||||||
else
|
else
|
||||||
echo "- [$name]($name)" >> "$temp_index"
|
echo "- [$name]($name)" >> "$temp_list"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ "$has_custom_index" = "true" ]; then
|
||||||
|
awk '
|
||||||
|
/\{\{LIST\}\}/ {
|
||||||
|
while((getline line < "'"$temp_list"'") > 0) print line
|
||||||
|
close("'"$temp_list"'")
|
||||||
|
next
|
||||||
|
}
|
||||||
|
{ print }
|
||||||
|
' "$dir/index.md" > "$temp_index"
|
||||||
|
else
|
||||||
|
cat "$temp_list" >> "$temp_index"
|
||||||
|
fi
|
||||||
|
|
||||||
is_home="false"; [ "$dir" = "$src" ] && is_home="true"
|
is_home="false"; [ "$dir" = "$src" ] && is_home="true"
|
||||||
target_url="/$rel_dir/index.html"
|
target_url="/$rel_dir/index.html"
|
||||||
[ "$rel_dir" = "." ] && target_url="/index.html"
|
[ "$rel_dir" = "." ] && target_url="/index.html"
|
||||||
if needs_rebuild "$dir" "$out_dir/index.html"; then
|
|
||||||
|
do_rebuild="false"
|
||||||
|
needs_rebuild "$dir" "$out_dir/index.html" && do_rebuild="true"
|
||||||
|
[ "$has_custom_index" = "true" ] && needs_rebuild "$dir/index.md" "$out_dir/index.html" && do_rebuild="true"
|
||||||
|
|
||||||
|
if [ "$do_rebuild" = "true" ]; then
|
||||||
render_markdown "$temp_index" "$is_home" "$target_url" > "$out_dir/index.html"
|
render_markdown "$temp_index" "$is_home" "$target_url" > "$out_dir/index.html"
|
||||||
fi
|
fi
|
||||||
rm "$temp_index"
|
rm -f "$temp_index" "$temp_list"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -945,6 +979,10 @@ eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type f -print" | sort | while
|
|||||||
template.html|site.conf|style.css|styles.css) continue ;;
|
template.html|site.conf|style.css|styles.css) continue ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
if [ "${file##*/}" = "index.md" ] && grep -q '{{LIST}}' "$file" 2>/dev/null; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
is_preserved=0
|
is_preserved=0
|
||||||
if [ -n "$(eval "find \"$file\" \( $PRESERVE_ARGS \) -print")" ]; then
|
if [ -n "$(eval "find \"$file\" \( $PRESERVE_ARGS \) -print")" ]; then
|
||||||
is_preserved=1
|
is_preserved=1
|
||||||
|
|||||||
5
site/depths/index.md
Normal file
5
site/depths/index.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Depths
|
||||||
|
|
||||||
|
This is a custom index for a directory
|
||||||
|
|
||||||
|
{{LIST}}
|
||||||
Reference in New Issue
Block a user