From c8df9a3da9e8c90165eb5975363e4781acfa3ad9 Mon Sep 17 00:00:00 2001 From: "N0\\A" Date: Tue, 5 May 2026 20:39:55 +0200 Subject: [PATCH] fix: navbar draft --- lib/builder.sh | 3 +++ lib/generator.sh | 33 +++++++++++++++++++++++++++++---- lib/manifest.sh | 29 ++++++++++++++++++++++++++++- lib/runtime.sh | 1 - site/docs/configuration.md | 4 ++-- site/docs/markdown.md | 2 +- site/docs/templates.md | 3 +++ site/docs/usage.md | 2 +- 8 files changed, 67 insertions(+), 10 deletions(-) diff --git a/lib/builder.sh b/lib/builder.sh index 16236ba..4b28a4c 100644 --- a/lib/builder.sh +++ b/lib/builder.sh @@ -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 diff --git a/lib/generator.sh b/lib/generator.sh index a0675bd..588563c 100644 --- a/lib/generator.sh +++ b/lib/generator.sh @@ -6,11 +6,36 @@ SEARCH_FORM_NAV='
"$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 \ diff --git a/lib/manifest.sh b/lib/manifest.sh index d6f3a28..b7f3b01 100644 --- a/lib/manifest.sh +++ b/lib/manifest.sh @@ -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 } diff --git a/lib/runtime.sh b/lib/runtime.sh index aeaa0f1..f2af137 100644 --- a/lib/runtime.sh +++ b/lib/runtime.sh @@ -173,7 +173,6 @@ refresh_build_context() { fi resolve_template_path - build_full_nav } watch_for_changes() { diff --git a/site/docs/configuration.md b/site/docs/configuration.md index 38f8493..fe21a68 100644 --- a/site/docs/configuration.md +++ b/site/docs/configuration.md @@ -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 diff --git a/site/docs/markdown.md b/site/docs/markdown.md index 4a125d5..c07efc3 100644 --- a/site/docs/markdown.md +++ b/site/docs/markdown.md @@ -38,7 +38,7 @@ This renders as `
Term
Definition
`. Multiple definition ## Emoji Shortcodes -Standard GitHub/MkDocs emoji shortcodes like `:smile:`, `:fire:`, `:rocket:` are automatically replaced with their Unicode emoji equivalents. Shortcodes inside code blocks are left as-is. +Standard GitHub/MkDocs emoji shortcodes like `:smile:`, `:fire:`, `:rocket:` are automatically replaced with their Unicode emoji equivalents. Shortcodes inside codeblocks are left as-is. ## Pipe Tables diff --git a/site/docs/templates.md b/site/docs/templates.md index 55ff0e8..ee2ef2a 100644 --- a/site/docs/templates.md +++ b/site/docs/templates.md @@ -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 `
`. diff --git a/site/docs/usage.md b/site/docs/usage.md index 3774e80..efa3456 100644 --- a/site/docs/usage.md +++ b/site/docs/usage.md @@ -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`.