feat: incremental rebuilds
This commit is contained in:
26
kewt.sh
26
kewt.sh
@@ -734,7 +734,19 @@ render_markdown() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ENABLE_HEADER_LINKS="$enable_header_links" MARKDOWN_SITE_ROOT="$src" MARKDOWN_FALLBACK_FILE="$script_dir/styles/$style.css" sh "$script_dir/markdown.sh" "$content_file" | AWK_CURRENT_URL="$current_url" AWK_TITLE="$page_title" AWK_NAV="$nav" AWK_FOOTER="$footer" AWK_STYLE_PATH="${style_path}${asset_version}" AWK_HEADER_BRAND="$header_brand" AWK_HEAD_EXTRA="$head_extra" awk -f "$awk_dir/render_template.awk" "$local_template"
|
ENABLE_HEADER_LINKS="$enable_header_links" CUSTOM_ADMONITIONS="$custom_admonitions" MARKDOWN_SITE_ROOT="$src" MARKDOWN_FALLBACK_FILE="$script_dir/styles/$style.css" sh "$script_dir/markdown.sh" "$content_file" | AWK_CURRENT_URL="$current_url" AWK_TITLE="$page_title" AWK_NAV="$nav" AWK_FOOTER="$footer" AWK_STYLE_PATH="${style_path}${asset_version}" AWK_HEADER_BRAND="$header_brand" AWK_HEAD_EXTRA="$head_extra" awk -f "$awk_dir/render_template.awk" "$local_template"
|
||||||
|
}
|
||||||
|
|
||||||
|
needs_rebuild() {
|
||||||
|
src_file="$1"
|
||||||
|
out_file="$2"
|
||||||
|
[ ! -f "$out_file" ] && return 0
|
||||||
|
[ "$src_file" -nt "$out_file" ] && return 0
|
||||||
|
[ -f "./site.conf" ] && [ "./site.conf" -nt "$out_file" ] && return 0
|
||||||
|
[ -f "$src/site.conf" ] && [ "$src/site.conf" -nt "$out_file" ] && return 0
|
||||||
|
[ -f "$template" ] && [ "$template" -nt "$out_file" ] && return 0
|
||||||
|
[ -f "$script_dir/styles/$style.css" ] && [ "$script_dir/styles/$style.css" -nt "$out_file" ] && return 0
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Building site from '$src' to '$out'..."
|
echo "Building site from '$src' to '$out'..."
|
||||||
@@ -747,9 +759,13 @@ eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type d -print" | sort | while
|
|||||||
mkdir -p "$out_dir"
|
mkdir -p "$out_dir"
|
||||||
|
|
||||||
if [ -f "$dir/styles.css" ]; then
|
if [ -f "$dir/styles.css" ]; then
|
||||||
|
if needs_rebuild "$dir/styles.css" "$out_dir/styles.css"; then
|
||||||
copy_style_with_resolved_vars "$dir/styles.css" "$out_dir/styles.css"
|
copy_style_with_resolved_vars "$dir/styles.css" "$out_dir/styles.css"
|
||||||
|
fi
|
||||||
elif [ -f "$dir/style.css" ]; then
|
elif [ -f "$dir/style.css" ]; then
|
||||||
|
if needs_rebuild "$dir/style.css" "$out_dir/styles.css"; then
|
||||||
copy_style_with_resolved_vars "$dir/style.css" "$out_dir/styles.css"
|
copy_style_with_resolved_vars "$dir/style.css" "$out_dir/styles.css"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ "$dir_indexes" != "true" ] && continue
|
[ "$dir_indexes" != "true" ] && continue
|
||||||
@@ -766,7 +782,9 @@ eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type d -print" | sort | while
|
|||||||
is_home="false"; [ "$dir" = "$src" ] && is_home="true"
|
is_home="false"; [ "$dir" = "$src" ] && is_home="true"
|
||||||
target_url="/$rel_dir/index.html"
|
target_url="/$rel_dir/index.html"
|
||||||
[ "$rel_dir" = "." ] && target_url="/index.html"
|
[ "$rel_dir" = "." ] && target_url="/index.html"
|
||||||
|
if needs_rebuild "$md_file" "$out_dir/index.html"; then
|
||||||
render_markdown "$md_file" "$is_home" "$target_url" > "$out_dir/index.html"
|
render_markdown "$md_file" "$is_home" "$target_url" > "$out_dir/index.html"
|
||||||
|
fi
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -826,7 +844,9 @@ eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type d -print" | sort | while
|
|||||||
is_home="false"; [ "$dir" = "$src" ] && is_home="true"
|
is_home="false"; [ "$dir" = "$src" ] && is_home="true"
|
||||||
target_url="/$rel_dir/index.html"
|
target_url="/$rel_dir/index.html"
|
||||||
[ "$rel_dir" = "." ] && target_url="/index.html"
|
[ "$rel_dir" = "." ] && target_url="/index.html"
|
||||||
|
if needs_rebuild "$dir" "$out_dir/index.html"; then
|
||||||
render_markdown "$temp_index" "$is_home" "$target_url" > "$out_dir/index.html"
|
render_markdown "$temp_index" "$is_home" "$target_url" > "$out_dir/index.html"
|
||||||
|
fi
|
||||||
rm "$temp_index"
|
rm "$temp_index"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@@ -863,9 +883,13 @@ eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type f -print" | sort | while
|
|||||||
if [ "${file%.md}" != "$file" ] && [ "$is_preserved" -eq 0 ]; then
|
if [ "${file%.md}" != "$file" ] && [ "$is_preserved" -eq 0 ]; then
|
||||||
is_home="false"; [ "$file" = "$src/index.md" ] && is_home="true"
|
is_home="false"; [ "$file" = "$src/index.md" ] && is_home="true"
|
||||||
out_file="$out/${rel_path%.md}.html"
|
out_file="$out/${rel_path%.md}.html"
|
||||||
|
if needs_rebuild "$file" "$out_file"; then
|
||||||
render_markdown "$file" "$is_home" > "$out_file"
|
render_markdown "$file" "$is_home" > "$out_file"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
|
if needs_rebuild "$file" "$out/$rel_path"; then
|
||||||
cp "$file" "$out/$rel_path"
|
cp "$file" "$out/$rel_path"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
11
markdown.sh
11
markdown.sh
@@ -15,7 +15,7 @@ sed_inplace() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
temp_file="/tmp/markdown.$$.md"
|
temp_file="${KEWT_TMPDIR:-/tmp}/markdown.$$.md"
|
||||||
cat "$@" > "$temp_file"
|
cat "$@" > "$temp_file"
|
||||||
|
|
||||||
trap 'rm -f "$temp_file" "$temp_file.tmp"' EXIT INT TERM
|
trap 'rm -f "$temp_file" "$temp_file.tmp"' EXIT INT TERM
|
||||||
@@ -40,11 +40,16 @@ done
|
|||||||
sed_inplace "/^\[[^\]]*\]: */d" "$temp_file"
|
sed_inplace "/^\[[^\]]*\]: */d" "$temp_file"
|
||||||
|
|
||||||
# Blocks
|
# Blocks
|
||||||
sed_inplace "s/^>!\[/> [!/g" "$temp_file"
|
|
||||||
sed_inplace "s/^>\[!/> [!/g" "$temp_file"
|
|
||||||
|
|
||||||
|
loop_count=0
|
||||||
|
max_iterations=100
|
||||||
while grep '^>' "$temp_file" >/dev/null; do
|
while grep '^>' "$temp_file" >/dev/null; do
|
||||||
awk -f "$awk_dir/blockquote.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file"
|
awk -f "$awk_dir/blockquote.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file"
|
||||||
|
loop_count=$((loop_count + 1))
|
||||||
|
if [ "$loop_count" -gt "$max_iterations" ]; then
|
||||||
|
echo "Warning: Blockquote processing exceeded $max_iterations iterations on $1. Breaking to prevent infinite loop." >&2
|
||||||
|
break
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
awk -f "$awk_dir/blockquote_to_admonition.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file"
|
awk -f "$awk_dir/blockquote_to_admonition.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file"
|
||||||
|
|||||||
Reference in New Issue
Block a user