1
0
forked from N0VA/kewt

fix: navbar draft

This commit is contained in:
2026-05-05 20:39:55 +02:00
parent b8e6c3afa8
commit c8df9a3da9
8 changed files with 67 additions and 10 deletions

View File

@@ -33,6 +33,7 @@ build_site() {
echo "Building site from '$src' to '$out'..."
build_markdown_manifest
build_full_nav
eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type d -print" | sort | while read -r dir; do
rel_dir="${dir#"$src"}"
@@ -117,6 +118,8 @@ eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type d -print" | sort | while
template.html|site.conf|style.css|styles.root.css|index.md) continue ;;
esac
if [ -d "$entry" ]; then
entry_rel_dir="${entry#"$src"/}"
manifest_dir_hidden_by_draft_index "$entry_rel_dir" && continue
dir_url="$(encode_url_path "$name")/index.html"
echo "${name}|- [${name}/](${dir_url})" >> "$temp_entries"
elif [ "${entry%.md}" != "$entry" ]; then

View File

@@ -6,11 +6,36 @@ SEARCH_FORM_NAV='<div class="kewt-search-nav"><form action="/search.html" method
generate_nav() {
dinfo=$(eval "find \"$1\" \( $IGNORE_ARGS -o $HIDE_ARGS -o $PRESERVE_ARGS \) -prune -o -print" | sort | AWK_SRC="$1" awk -f "$awk_dir/collect_dir_info.awk")
find_cmd="find \"$1\" \( $IGNORE_ARGS -o $HIDE_ARGS -o $PRESERVE_ARGS \) -prune -o -name \"*.md\" -print"
if [ -n "$posts_dir" ] && [ -d "$1/$posts_dir" ]; then
find_cmd="$find_cmd && echo \"$1/$posts_dir/index.md\""
nav_input="$KEWT_TMPDIR/nav_input.lst"
: > "$nav_input"
if [ -f "$manifest_visible_list" ]; then
while IFS= read -r nav_rel_path; do
printf '%s/%s\n' "$1" "$nav_rel_path" >> "$nav_input"
done < "$manifest_visible_list"
if [ -n "$posts_dir" ] && [ -d "$1/$posts_dir" ] && ! manifest_dir_hidden_by_draft_index "$posts_dir"; then
has_posts_nav_entry="false"
has_posts_index_entry="false"
while IFS= read -r nav_rel_path; do
case "$nav_rel_path" in
"$posts_dir"/index.md) has_posts_index_entry="true" ;;
"$posts_dir"/*) has_posts_nav_entry="true" ;;
esac
done < "$manifest_visible_list"
if [ "$has_posts_nav_entry" = "true" ] && [ "$has_posts_index_entry" = "false" ]; then
printf '%s/%s/index.md\n' "$1" "$posts_dir" >> "$nav_input"
fi
fi
else
find_cmd="find \"$1\" \( $IGNORE_ARGS -o $HIDE_ARGS -o $PRESERVE_ARGS \) -prune -o -name \"*.md\" -print"
if [ -n "$posts_dir" ] && [ -d "$1/$posts_dir" ]; then
find_cmd="$find_cmd && echo \"$1/$posts_dir/index.md\""
fi
eval "$find_cmd" | sort -u > "$nav_input"
fi
eval "$find_cmd" | sort -u | AWK_SRC="$1" AWK_SINGLE_FILE_INDEX="$single_file_index" AWK_FLATTEN="$flatten" AWK_ORDER="$order" AWK_HOME_NAME="$home_name" AWK_SHOW_HOME_IN_NAV="$show_home_in_nav" AWK_DINFO="$dinfo" awk -f "$awk_dir/generate_sidebar.awk"
sort -u "$nav_input" | AWK_SRC="$1" AWK_SINGLE_FILE_INDEX="$single_file_index" AWK_FLATTEN="$flatten" AWK_ORDER="$order" AWK_HOME_NAME="$home_name" AWK_SHOW_HOME_IN_NAV="$show_home_in_nav" AWK_DINFO="$dinfo" awk -f "$awk_dir/generate_sidebar.awk"
}
escape_html_text() {
printf '%s' "$1" | sed \

View File

@@ -12,6 +12,19 @@ manifest_dir_meta_path() {
printf '%s/manifest/dir-meta/%s.meta\n' "$KEWT_TMPDIR" "$1"
}
manifest_dir_hidden_by_draft_index() {
_manifest_hidden_dir="${1:-.}"
[ -f "$manifest_hidden_dirs_list" ] || return 1
while :; do
awk -v dir="$_manifest_hidden_dir" '$0 == dir { found = 1 } END { exit(found ? 0 : 1) }' "$manifest_hidden_dirs_list" >/dev/null 2>&1 && return 0
[ "$_manifest_hidden_dir" = "." ] && return 1
_manifest_hidden_parent=$(dirname "$_manifest_hidden_dir")
[ "$_manifest_hidden_parent" = "$_manifest_hidden_dir" ] && return 1
_manifest_hidden_dir="$_manifest_hidden_parent"
done
}
write_manifest_dir_meta() {
_dir_meta_rel="$1"
_dir_meta_count="$2"
@@ -79,12 +92,14 @@ build_markdown_manifest() {
manifest_dir_meta_root="$manifest_root/dir-meta"
manifest_all_list="$manifest_root/all.lst"
manifest_visible_list="$manifest_root/visible.lst"
manifest_hidden_dirs_list="$manifest_root/hidden-dirs.lst"
rm -rf "$manifest_root"
mkdir -p "$manifest_meta_root"
mkdir -p "$manifest_dir_meta_root"
: > "$manifest_all_list"
: > "$manifest_visible_list"
: > "$manifest_hidden_dirs_list"
eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -name \"*.md\" -print" | sort | while IFS= read -r manifest_file; do
manifest_rel_path="${manifest_file#"$src"/}"
@@ -94,6 +109,9 @@ build_markdown_manifest() {
[ "$manifest_filename" = "index.md" ] && manifest_is_index="true"
parse_frontmatter "$manifest_file"
if [ "$manifest_filename" = "index.md" ] && [ "$fm_draft" = "true" ]; then
printf '%s\n' "$manifest_dir_rel" >> "$manifest_hidden_dirs_list"
fi
markdown_title_from_loaded_file "$manifest_file" "$title - Page"
manifest_title="$markdown_title"
set_post_datetime "$fm_date" "$(basename "$manifest_file" .md)"
@@ -160,7 +178,16 @@ build_markdown_manifest() {
printf '%s\n' "$manifest_rel_path" >> "$manifest_all_list"
done
if [ -s "$manifest_hidden_dirs_list" ]; then
LC_ALL=C sort -u "$manifest_hidden_dirs_list" > "$manifest_hidden_dirs_list.sorted"
mv "$manifest_hidden_dirs_list.sorted" "$manifest_hidden_dirs_list"
fi
eval "find \"$src\" \( $IGNORE_ARGS -o $HIDE_ARGS -o $PRESERVE_ARGS \) -prune -o -name \"*.md\" -print" | sort | while IFS= read -r visible_file; do
printf '%s\n' "${visible_file#"$src"/}" >> "$manifest_visible_list"
visible_rel_path="${visible_file#"$src"/}"
load_manifest_entry "$visible_rel_path" || continue
[ "$manifest_draft" = "true" ] && continue
manifest_dir_hidden_by_draft_index "$manifest_dir_rel" && continue
printf '%s\n' "$visible_rel_path" >> "$manifest_visible_list"
done
}

View File

@@ -173,7 +173,6 @@ refresh_build_context() {
fi
resolve_template_path
build_full_nav
}
watch_for_changes() {