Actions
Some checks failed
Lint / shellcheck (push) Has been cancelled

This commit is contained in:
2026-03-11 07:42:45 +01:00
parent f407b1c4af
commit 9ced2af562
8 changed files with 124 additions and 13 deletions

16
.gitea/workflows/lint.yml Normal file
View File

@@ -0,0 +1,16 @@
name: Lint
on:
push:
branches: [ main, master ]
pull_request:
jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Shellcheck
run: sudo apt-get update && sudo apt-get install -y shellcheck
- name: Run Shellcheck
run: shellcheck kewt.sh markdown.sh tools/build-standalone.sh || true

View File

@@ -0,0 +1,24 @@
name: Release Standalone Builder
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Build standalone executable
run: |
chmod +x tools/build-standalone.sh
./tools/build-standalone.sh
- name: Upload Release Asset
uses: https://gitea.com/actions/release-action@main
with:
files: |-
kewt
api_key: '${{secrets.GITEA_TOKEN}}'

16
.github/workflows/lint.yml vendored Normal file
View File

@@ -0,0 +1,16 @@
name: Lint
on:
push:
branches: [ main, master ]
pull_request:
jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Shellcheck
run: sudo apt-get update && sudo apt-get install -y shellcheck
- name: Run Shellcheck
run: shellcheck kewt.sh markdown.sh tools/build-standalone.sh || true

22
.github/workflows/release.yml vendored Normal file
View File

@@ -0,0 +1,22 @@
name: Release Standalone Builder
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Build standalone executable
run: |
chmod +x tools/build-standalone.sh
./tools/build-standalone.sh
- name: Upload Release Asset
uses: softprops/action-gh-release@v2
with:
files: kewt

1
.gitignore vendored
View File

@@ -1 +1,2 @@
out/ out/
kewt

18
kewt.sh
View File

@@ -20,7 +20,7 @@ Options:
EOF EOF
} }
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) script_dir=$(CDPATH="" cd -- "$(dirname -- "$0")" && pwd)
awk_dir="$script_dir/awk" awk_dir="$script_dir/awk"
ensure_root_defaults() { ensure_root_defaults() {
@@ -93,10 +93,7 @@ create_new_site() {
exit 0 exit 0
} }
generate_nav() {
dinfo=$(find "$1" \( -name ".*" ! -name "." ! -name ".." -prune \) -o -print | sort | awk -v src="$1" -f "$awk_dir/collect_dir_info.awk")
find "$1" \( -name ".*" ! -name "." ! -name ".." -prune \) -o -name "*.md" -print | sort | awk -v src="$1" -v single_file_index="$single_file_index" -v flatten="$flatten" -v order="$order" -v dinfo="$dinfo" -f "$awk_dir/generate_sidebar.awk"
}
src="" src=""
out="" out=""
@@ -133,9 +130,9 @@ while [ $# -gt 0 ]; do
*) *)
positional_count=$((positional_count + 1)) positional_count=$((positional_count + 1))
if [ "$positional_count" -eq 1 ]; then if [ "$positional_count" -eq 1 ]; then
[ -z "$src" ] && src="$1" || die "Source already set (use either positional or --from)." if [ -z "$src" ]; then src="$1"; else die "Source already set (use either positional or --from)."; fi
elif [ "$positional_count" -eq 2 ]; then elif [ "$positional_count" -eq 2 ]; then
[ -z "$out" ] && out="$1" || die "Output already set (use either positional or --to)." if [ -z "$out" ]; then out="$1"; else die "Output already set (use either positional or --to)."; fi
else else
die "Too many positional arguments." die "Too many positional arguments."
fi fi
@@ -333,6 +330,7 @@ nav_links_html() {
old_ifs=$IFS old_ifs=$IFS
set -f set -f
IFS=',' IFS=','
# shellcheck disable=SC2086
set -- $nav_links set -- $nav_links
IFS=$old_ifs IFS=$old_ifs
set +f set +f
@@ -418,7 +416,7 @@ render_markdown() {
closest_style_src=$(find_closest "styles.css" "$(dirname "$file")") closest_style_src=$(find_closest "styles.css" "$(dirname "$file")")
[ -z "$closest_style_src" ] && closest_style_src=$(find_closest "style.css" "$(dirname "$file")") [ -z "$closest_style_src" ] && closest_style_src=$(find_closest "style.css" "$(dirname "$file")")
if [ -n "$closest_style_src" ]; then if [ -n "$closest_style_src" ]; then
style_rel_to_src="${closest_style_src#$src/}" style_rel_to_src="${closest_style_src#"$src"/}"
case "$closest_style_src" in case "$closest_style_src" in
"$src/styles.css") style_rel_to_src="styles.css" ;; "$src/styles.css") style_rel_to_src="styles.css" ;;
"$src/style.css") style_rel_to_src="style.css" ;; "$src/style.css") style_rel_to_src="style.css" ;;
@@ -466,7 +464,7 @@ render_markdown() {
echo "Building site from '$src' to '$out'..." echo "Building site from '$src' to '$out'..."
eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type d -print" | sort | while read -r dir; do eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type d -print" | sort | while read -r dir; do
rel_dir="${dir#$src}" rel_dir="${dir#"$src"}"
rel_dir="${rel_dir#/}" rel_dir="${rel_dir#/}"
[ -z "$rel_dir" ] && rel_dir="." [ -z "$rel_dir" ] && rel_dir="."
out_dir="$out/$rel_dir" out_dir="$out/$rel_dir"
@@ -518,7 +516,7 @@ if [ ! -f "$out/styles.css" ] && [ -f "$script_dir/styles/$style.css" ]; then
fi fi
eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type f -print" | sort | while IFS= read -r file; do eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type f -print" | sort | while IFS= read -r file; do
rel_path="${file#$src}" rel_path="${file#"$src"}"
rel_path="${rel_path#/}" rel_path="${rel_path#/}"
dir_rel=$(dirname "$rel_path") dir_rel=$(dirname "$rel_path")
out_dir="$out/$dir_rel" out_dir="$out/$dir_rel"

View File

@@ -1,16 +1,18 @@
#!/bin/sh #!/bin/sh
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) script_dir=$(CDPATH="" cd -- "$(dirname -- "$0")" && pwd)
awk_dir="$script_dir/awk" awk_dir="$script_dir/awk"
sed_inplace() { sed_inplace() {
script="$1" script="$1"
file="$2" file="$2"
tmp="${file}.tmp.$$" tmp="${file}.tmp.$$"
sed "$script" "$file" > "$tmp" && mv "$tmp" "$file" || { if sed "$script" "$file" > "$tmp" && mv "$tmp" "$file"; then
return 0
else
rm -f "$tmp" rm -f "$tmp"
return 1 return 1
} fi
} }
temp_file="/tmp/markdown.$$.md" temp_file="/tmp/markdown.$$.md"

32
tools/build-standalone.sh Normal file
View File

@@ -0,0 +1,32 @@
#!/bin/sh
set -e
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
if [ ! -f "$REPO_ROOT/kewt.sh" ]; then
echo "kewt.sh not found. Run from the repository root or tools/."
exit 1
fi
OUT_FILE="$REPO_ROOT/kewt"
cat << 'EOF' > "$OUT_FILE"
#!/bin/sh
tmpdir=$(mktemp -d "/tmp/kewt.XXXXXX")
trap 'rm -rf "$tmpdir"' EXIT HUP INT TERM
# Extract payload
sed '1,/^#==PAYLOAD==$/d' "$0" | tar -xz -C "$tmpdir"
# Pass control to the extracted script
exec "$tmpdir/kewt.sh" "$@"
#==PAYLOAD==
EOF
tar -cz -C "$REPO_ROOT" kewt.sh markdown.sh awk styles >> "$OUT_FILE"
chmod +x "$OUT_FILE"
echo "Generated standalone executable at $OUT_FILE"