fix: navbar draft
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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")
|
||||
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 | 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"
|
||||
eval "$find_cmd" | sort -u > "$nav_input"
|
||||
fi
|
||||
|
||||
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 \
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -173,7 +173,6 @@ refresh_build_context() {
|
||||
fi
|
||||
|
||||
resolve_template_path
|
||||
build_full_nav
|
||||
}
|
||||
|
||||
watch_for_changes() {
|
||||
|
||||
@@ -62,7 +62,7 @@ include_cw_pages_in_search = false
|
||||
- `favicon` - explicit favicon path (used when `logo_as_favicon` is false or no logo is set)
|
||||
- `generate_page_title` - automatically generate title text from the first markdown heading or filename (default: true)
|
||||
- `error_page` - filename for the generated 404 error page (default: "not_found.html", empty to disable)
|
||||
- `versioning` - append a version query parameter (`?v=timestamp`) to css asset urls to bypass cache (default: false)
|
||||
- `versioning` - append a build-time version query parameter (for example `?v=20260505193210`) to css asset urls to bypass cache (default: false)
|
||||
- `enable_header_links` - turns markdown section headings into clickable anchor links (default: true)
|
||||
- `base_url` - absolute URL of the site, used for sitemap and RSS feed generation
|
||||
- `generate_feed` - enable RSS feed generation (requires `base_url`)
|
||||
@@ -75,7 +75,7 @@ include_cw_pages_in_search = false
|
||||
- `tags_dir` - directory name for generated tag pages (default: "tags")
|
||||
- `generate_search` - generate a `search.json` index for client-side search
|
||||
- `search_in_footer` - include a search box in the page footer (requires `generate_search`)
|
||||
- `search_in_header` - include a search box in the page header (requires `generate_search`)
|
||||
- `search_in_header` - include a search box in the page header (requires `generate_search` and a template that includes `{{HEADER_SEARCH}}`)
|
||||
- `include_cw_pages_in_search` - include content warning pages in the search index (default: false)
|
||||
|
||||
## Dot Files
|
||||
|
||||
@@ -13,7 +13,10 @@ When customizing `template.html`, the placeholders available are:
|
||||
- `{{LANG}}` - the configured document language
|
||||
- `{{HEAD_EXTRA}}` - meta-tags
|
||||
- `{{HEADER_BRAND}}` - header rendering the name and/or logo
|
||||
- `{{HEADER_SEARCH}}` - header search form when `search_in_header = true`
|
||||
|
||||
## Search
|
||||
|
||||
When `generate_search` is enabled, kewt embeds a search bar into pages based on the `search_in_header` and `search_in_footer` config options. The search uses a `search.json` index generated at build time and a client-side JS script. No external dependencies are required.
|
||||
|
||||
If you use a custom template and want header search enabled, make sure your `template.html` includes `{{HEADER_SEARCH}}` somewhere inside `<header>`.
|
||||
|
||||
@@ -22,4 +22,4 @@ kewt --serve [port]
|
||||
- `--watch` (`-w`) watches for file changes in the source directory and rebuilds automatically.
|
||||
- `--clean` cleans the output directory before building (default behavior).
|
||||
- `--no-clean` does not clean the output directory before building. Useful with `--watch` to avoid clearing output on every rebuild.
|
||||
- `--serve` (`-s`) starts a local HTTP server (python3 or busybox) in the output directory after building. Use with the port number to specify the port. Composable with `--watch`.
|
||||
- `--serve` (`-s`) starts a local HTTP server (python3 or busybox) in the output directory after building. Use with the port number to specify the port. The default port is `8000`. Composable with `--watch`.
|
||||
|
||||
Reference in New Issue
Block a user