feat: config updating
All checks were successful
Lint / shellcheck (push) Successful in 17s

This commit is contained in:
2026-03-17 11:53:15 +01:00
parent e7d90d18e8
commit 1a7525a857
2 changed files with 120 additions and 4 deletions

107
kewt.sh
View File

@@ -11,11 +11,13 @@ usage() {
Usage: $invoked_as [--from <src>] [--to <out>] Usage: $invoked_as [--from <src>] [--to <out>]
$invoked_as [src] [out] $invoked_as [src] [out]
$invoked_as --new [title] $invoked_as --new [title]
$invoked_as --update [dir]
$invoked_as --help $invoked_as --help
Options: Options:
--help Show this help message. --help Show this help message.
--new [title] Create a new site directory (default: site) --new [title] Create a new site directory (default: site)
--update [dir] Update site.conf and template.html with latest defaults (defaults to current directory)
--from <src> Source directory (default: site) --from <src> Source directory (default: site)
--to <out> Output directory (default: out) --to <out> Output directory (default: out)
EOF EOF
@@ -102,6 +104,103 @@ create_new_site() {
exit 0 exit 0
} }
update_site() {
update_dir="${1:-.}"
[ -d "$update_dir" ] || die "Directory '$update_dir' does not exist."
target_conf="$update_dir/site.conf"
target_tmpl="$update_dir/template.html"
# Generate default site.conf
default_conf="$KEWT_TMPDIR/default_site.conf"
cat > "$default_conf" <<'CONFEOF'
title = "kewt"
style = "kewt"
dir_indexes = true
single_file_index = true
flatten = false
order = ""
home_name = "Home"
show_home_in_nav = true
nav_links = ""
nav_extra = ""
footer = "made with <a href="https://kewt.krzak.org">kewt</a>"
logo = ""
display_logo = false
display_title = true
logo_as_favicon = true
favicon = ""
generate_page_title = true
error_page = "not_found.html"
versioning = false
enable_header_links = true
base_url = ""
CONFEOF
# Update site.conf: add missing keys
if [ ! -f "$target_conf" ]; then
echo "No site.conf found in '$update_dir'; nothing to update."
else
added=0
while IFS= read -r line; do
case "$line" in
''|'#'*) continue ;;
*=*) ;;
*) continue ;;
esac
key=$(printf '%s' "${line%%=*}" | sed 's/^[[:space:]]*//; s/[[:space:]]*$//')
if ! grep -q "^[[:space:]]*${key}[[:space:]]*=" "$target_conf"; then
printf '%s\n' "$line" >> "$target_conf"
echo " Added: $key"
added=$((added + 1))
fi
done < "$default_conf"
if [ "$added" -eq 0 ]; then
echo "site.conf is already up to date."
else
echo "Added $added new key(s) to '$target_conf'."
fi
fi
# Update template.html
if [ -f "$target_tmpl" ]; then
default_tmpl="$KEWT_TMPDIR/default_template.html"
cat > "$default_tmpl" <<'TMPLEOF'
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>{{TITLE}}</title>
<link rel="stylesheet" href="{{CSS}}" type="text/css" />
{{HEAD_EXTRA}}
</head>
<body>
<header>
<h1>{{HEADER_BRAND}}</h1>
</header>
<nav id="side-bar">{{NAV}}</nav>
<article>{{CONTENT}}</article>
<footer>{{FOOTER}}</footer>
</body>
</html>
TMPLEOF
if cmp -s "$default_tmpl" "$target_tmpl" 2>/dev/null; then
echo "template.html is already up to date."
else
cp "$default_tmpl" "${target_tmpl}.default"
echo "template.html has local changes; saved latest default as '${target_tmpl}.default'."
echo ""
diff "$target_tmpl" "${target_tmpl}.default" || true
fi
fi
exit 0
}
src="" src=""
@@ -123,6 +222,14 @@ while [ $# -gt 0 ]; do
shift shift
fi fi
;; ;;
--update)
update_dir="."
if [ $# -gt 1 ] && [ "${2#-}" = "$2" ]; then
update_dir="$2"
shift
fi
update_site "$update_dir"
;;
--from) --from)
[ $# -lt 2 ] && die "--from requires a value." [ $# -lt 2 ] && die "--from requires a value."
src="$2" src="$2"

View File

@@ -10,3 +10,12 @@ display_title = true
logo_as_favicon = true logo_as_favicon = true
favicon = "" favicon = ""
order = "" order = ""
home_name = "Home"
show_home_in_nav = true
nav_links = ""
nav_extra = ""
generate_page_title = true
error_page = "not_found.html"
versioning = false
enable_header_links = true
base_url = "https://kewt.krzak.org"