From 33ba8b19b6f23053e3e3a78bd5177a7dd09ba017 Mon Sep 17 00:00:00 2001 From: "N0\\A" Date: Fri, 3 Apr 2026 14:13:40 +0200 Subject: [PATCH] Priority systen --- awk/generate_sidebar.awk | 86 +++++++++++++++---- lib/builder.sh | 13 ++- lib/config.sh | 3 - lib/generator.sh | 4 +- .../the deepest depths/blobfish/blobfish.md | 3 + site/depths/index.md | 3 + site/docs/configuration.md | 3 +- site/docs/embeds.md | 1 + site/docs/frontmatter.md | 3 + site/docs/index.md | 1 + site/docs/installation.md | 1 + site/docs/markdown.md | 1 + site/docs/quickstart.md | 1 + site/docs/templates.md | 1 + site/docs/theming.md | 1 + site/docs/usage.md | 1 + site/heaven/index.md | 1 + site/index.md | 6 +- site/site.conf | 1 - 19 files changed, 105 insertions(+), 29 deletions(-) diff --git a/awk/generate_sidebar.awk b/awk/generate_sidebar.awk index 8088264..8a5be5a 100644 --- a/awk/generate_sidebar.awk +++ b/awk/generate_sidebar.awk @@ -43,8 +43,47 @@ function get_title(path, default_title, full_path, line, title, in_fm) { return default_title } +function get_priority(path, full_path, line, prio, in_fm) { + full_path = src "/" path + if (path !~ /\.md$/) { + full_path = full_path "/index.md" + } -function compare_paths(p1, p2, parts1, parts2, n1, n2, i, name1, name2, lname1, lname2, w1, w2) { + prio = "" + in_fm = 0 + while ((getline line < full_path) > 0) { + if (line ~ /^---[[:space:]]*$/) { + if (in_fm == 0) { + in_fm = 1 + continue + } else { + break + } + } + if (in_fm) { + if (line ~ /^[[:space:]]*priority[[:space:]]*=/) { + sub(/^[[:space:]]*priority[[:space:]]*=[[:space:]]*/, "", line) + if (line ~ /^".*"$/) { + prio = substr(line, 2, length(line) - 2) + } else if (line ~ /^'.*'$/) { + prio = substr(line, 2, length(line) - 2) + } else { + prio = line + } + break + } + } else { + break + } + } + close(full_path) + + if (prio != "" && prio + 0 == prio) return prio + 0 + return 0 +} + + +function compare_paths(p1, p2, parts1, parts2, n1, n2, i, k, name1, name2, lname1, lname2, pr1, pr2, dir1, dir2, ent1, ent2) { n1 = split(p1, parts1, "/") n2 = split(p2, parts2, "/") for (i = 1; i <= n1 && i <= n2; i++) { @@ -58,14 +97,36 @@ function compare_paths(p1, p2, parts1, parts2, n1, n2, i, name1, name2, lname if (lname1 == "index" && i == n1 && lname2 != "index") return -1 if (lname2 == "index" && i == n2 && lname1 != "index") return 1 - w1 = (lname1 in custom_order ? custom_order[lname1] : 999999) - w2 = (lname2 in custom_order ? custom_order[lname2] : 999999) + if (lname1 != lname2) { + dir1 = "" + dir2 = "" + for (k = 1; k < i; k++) { + dir1 = (dir1 == "" ? parts1[k] : dir1 "/" parts1[k]) + dir2 = (dir2 == "" ? parts2[k] : dir2 "/" parts2[k]) + } - if (w1 < w2) return -1 - if (w1 > w2) return 1 + if (i == n1) { + pr1 = get_priority(p1) + } else { + ent1 = (dir1 == "" ? name1 : dir1 "/" name1) + pr1 = get_priority(ent1) + } - if (lname1 < lname2) return -1 - if (lname1 > lname2) return 1 + if (i == n2) { + pr2 = get_priority(p2) + } else { + ent2 = (dir2 == "" ? name2 : dir2 "/" name2) + pr2 = get_priority(ent2) + } + + if (pr1 > 0 || pr2 > 0) { + if (pr1 < pr2) return -1 + if (pr1 > pr2) return 1 + } + + if (lname1 < lname2) return -1 + if (lname1 > lname2) return 1 + } } if (n1 < n2) return -1 if (n1 > n2) return 1 @@ -76,7 +137,6 @@ BEGIN { src = ENVIRON["AWK_SRC"] single_file_index = ENVIRON["AWK_SINGLE_FILE_INDEX"] flatten = ENVIRON["AWK_FLATTEN"] - order = ENVIRON["AWK_ORDER"] home_name = ENVIRON["AWK_HOME_NAME"] show_home_in_nav = ENVIRON["AWK_SHOW_HOME_IN_NAV"] dinfo = ENVIRON["AWK_DINFO"] @@ -87,16 +147,6 @@ BEGIN { d_dirs[dparts[1]] = dparts[3] } } - - n_order = split(order, oparts, ",") - for (i = 1; i <= n_order; i++) { - name = oparts[i] - sub(/^[[:space:]]*/, "", name) - sub(/[[:space:]]*$/, "", name) - if (name != "") { - custom_order[tolower(name)] = i - } - } } { diff --git a/lib/builder.sh b/lib/builder.sh index e200870..73cd4e6 100644 --- a/lib/builder.sh +++ b/lib/builder.sh @@ -170,10 +170,17 @@ eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type d -print" | sort | while label="$p_date $p_time" fi fi - if [ "$is_post_entry" = "true" ]; then - sort_key="${p_date} ${p_time}" + if [ -n "$fm_priority" ]; then + prio_val="$fm_priority" else - sort_key="$name" + prio_val="0" + fi + if [ "$is_post_entry" = "true" ]; then + prio_key=$(printf '%05d' "$prio_val") + sort_key="${prio_key} ${p_date} ${p_time}" + else + prio_key=$(printf '%05d' "$((99999 - prio_val))") + sort_key="${prio_key} $name" fi echo "${sort_key}|- [$label](${name%.md}.html)|$name|${name%.md}.html" >> "$temp_entries" else diff --git a/lib/config.sh b/lib/config.sh index a8a33db..edef9c8 100644 --- a/lib/config.sh +++ b/lib/config.sh @@ -5,7 +5,6 @@ draft_by_default = false dir_indexes = true single_file_index = true flatten = false -order = "" home_name = "Home" show_home_in_nav = true nav_links = "" @@ -67,7 +66,6 @@ footer="made with kewt" dir_indexes="true" single_file_index="true" flatten="false" -order="" home_name="Home" show_home_in_nav="true" nav_links="" @@ -127,7 +125,6 @@ load_config() { dir_indexes) dir_indexes="$val" ;; single_file_index) single_file_index="$val" ;; flatten) flatten="$val" ;; - order) order="$val" ;; home_name) home_name="$val" ;; show_home_in_nav) show_home_in_nav="$val" ;; nav_links) nav_links="$val" ;; diff --git a/lib/generator.sh b/lib/generator.sh index b521b4c..61bcde3 100644 --- a/lib/generator.sh +++ b/lib/generator.sh @@ -8,7 +8,7 @@ generate_nav() { 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 | AWK_SRC="$1" AWK_SINGLE_FILE_INDEX="$single_file_index" AWK_FLATTEN="$flatten" 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 \ @@ -34,6 +34,7 @@ parse_frontmatter() { fm_description="" fm_content_warning="" fm_tags="" + fm_priority="" while IFS='=' read -r _fk _fv; do case "$_fk" in title) fm_title="$_fv" ;; @@ -42,6 +43,7 @@ parse_frontmatter() { description) fm_description="$_fv" ;; content_warning) fm_content_warning="$_fv" ;; tags) fm_tags="$_fv" ;; + priority) fm_priority="$_fv" ;; esac done < "$_fm_out" rm -f "$_fm_out" diff --git a/site/depths/deeper depths/deeper deeper depths/the deepest depths/blobfish/blobfish.md b/site/depths/deeper depths/deeper deeper depths/the deepest depths/blobfish/blobfish.md index 5ab61b2..202f650 100644 --- a/site/depths/deeper depths/deeper deeper depths/the deepest depths/blobfish/blobfish.md +++ b/site/depths/deeper depths/deeper deeper depths/the deepest depths/blobfish/blobfish.md @@ -1,3 +1,6 @@ +--- +priority = 0 +--- # Hello! ![the greatest drawing of a blobfish in the world](blobfish.bmp) diff --git a/site/depths/index.md b/site/depths/index.md index 6468175..a2c9285 100644 --- a/site/depths/index.md +++ b/site/depths/index.md @@ -1,3 +1,6 @@ +--- +priority = 2 +--- # Depths This is a custom index for a directory diff --git a/site/docs/configuration.md b/site/docs/configuration.md index 38f8493..b9bae1d 100644 --- a/site/docs/configuration.md +++ b/site/docs/configuration.md @@ -1,5 +1,6 @@ --- title = "Configuration" +priority = 2 --- # Configuration @@ -13,7 +14,6 @@ draft_by_default = false dir_indexes = true single_file_index = true flatten = false -order = "" home_name = "Home" show_home_in_nav = true nav_links = "" @@ -49,7 +49,6 @@ include_cw_pages_in_search = false - `dir_indexes` - generate directory index pages when missing `index.md` - `single_file_index` - if a directory has one markdown file and no `index.md`, use that file as `index.html` - `flatten` - flatten sidebar directory levels -- `order` - comma separated file/directory name list to order the sidebar (alphabetical by default) - `home_name` - text for the home link in navigation (default: "Home") - `show_home_in_nav` - show home link in navigation (default: true) - `nav_links` - comma separated extra nav links, as bare URLs or Markdown links like `[Label](https://example.com)` diff --git a/site/docs/embeds.md b/site/docs/embeds.md index ec90b87..4da6d68 100644 --- a/site/docs/embeds.md +++ b/site/docs/embeds.md @@ -1,5 +1,6 @@ --- title = "Embeds" +priority = 5 --- # Embeds diff --git a/site/docs/frontmatter.md b/site/docs/frontmatter.md index 12d707f..7b47859 100644 --- a/site/docs/frontmatter.md +++ b/site/docs/frontmatter.md @@ -1,5 +1,6 @@ --- title = "Frontmatter" +priority = 4 --- # Frontmatter @@ -12,6 +13,7 @@ date = "2026-03-23 11:32" draft = false description = "A short page summary" tags = "example, tutorial" +priority = 10 --- ``` - `title` - overrides the page title, post name in index links, and RSS ``. @@ -20,3 +22,4 @@ tags = "example, tutorial" - `description` - page description, used for Open Graph `og:description` meta tag. - `tags` - comma separated list of tags. Used for tag index generation when `generate_tags` is enabled in `site.conf`. - `content_warning` - if set, creates an interstitial warning page that the user must click through. If set to `true` uses a generic warning, otherwise uses your string. +- `priority` - numeric value for ordering. Lower values sort first in the sidebar and directory indexes. Falls back to alphabetical/date ordering when not set or when items share the same priority. diff --git a/site/docs/index.md b/site/docs/index.md index 5e68b9f..753a448 100644 --- a/site/docs/index.md +++ b/site/docs/index.md @@ -1,5 +1,6 @@ --- title = "Documentation" +priority = 0 --- # Documentation diff --git a/site/docs/installation.md b/site/docs/installation.md index b419092..2ba6281 100644 --- a/site/docs/installation.md +++ b/site/docs/installation.md @@ -1,5 +1,6 @@ --- title = "Installation" +priority = 0 --- # Installation diff --git a/site/docs/markdown.md b/site/docs/markdown.md index 4a125d5..b7055b5 100644 --- a/site/docs/markdown.md +++ b/site/docs/markdown.md @@ -1,5 +1,6 @@ --- title = "Markdown Extensions" +priority = 7 --- # Markdown Extensions diff --git a/site/docs/quickstart.md b/site/docs/quickstart.md index 3962abb..922e035 100644 --- a/site/docs/quickstart.md +++ b/site/docs/quickstart.md @@ -1,5 +1,6 @@ --- title = "Quickstart" +priority = 1 --- # Quickstart diff --git a/site/docs/templates.md b/site/docs/templates.md index 55ff0e8..0a22280 100644 --- a/site/docs/templates.md +++ b/site/docs/templates.md @@ -1,5 +1,6 @@ --- title = "Templates" +priority = 8 --- # Templates diff --git a/site/docs/theming.md b/site/docs/theming.md index 4fa0372..423c26b 100644 --- a/site/docs/theming.md +++ b/site/docs/theming.md @@ -1,5 +1,6 @@ --- title = "Theming" +priority = 6 --- # Theming diff --git a/site/docs/usage.md b/site/docs/usage.md index 3774e80..05e3114 100644 --- a/site/docs/usage.md +++ b/site/docs/usage.md @@ -1,5 +1,6 @@ --- title = "Usage" +priority = 3 --- # Usage diff --git a/site/heaven/index.md b/site/heaven/index.md index 00054b5..eef62d2 100644 --- a/site/heaven/index.md +++ b/site/heaven/index.md @@ -1,5 +1,6 @@ --- title = "Heaven" +priority = 3 content_warning = "This page may contain CSS" --- # Heaven diff --git a/site/index.md b/site/index.md index d5a3078..819d263 100644 --- a/site/index.md +++ b/site/index.md @@ -1,3 +1,7 @@ +--- +title = "Home" +priority = 0 +--- # _kewt_ ### Pronounced "cute" @@ -14,7 +18,7 @@ It's meant to be a static site generator, like _[kew](https://github.com/uint23/ ## Features - No dependencies -- Frontmatter support (title, date, draft, description) +- Frontmatter support (title, date, draft, description, priority) - Supports many embed types - Automatic css variable replacement for older browsers - Automatic inlining and embedding of many filetypes with `\![link]` or `\![alt](link)` diff --git a/site/site.conf b/site/site.conf index 1a2aa84..c304eee 100644 --- a/site/site.conf +++ b/site/site.conf @@ -9,7 +9,6 @@ display_logo = false display_title = true logo_as_favicon = false favicon = "favicon.ico" -order = "Home, docs, depths, heaven" home_name = "Home" show_home_in_nav = true nav_links = ""