-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml_builder.sh
More file actions
executable file
·41 lines (31 loc) · 1.12 KB
/
html_builder.sh
File metadata and controls
executable file
·41 lines (31 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env bash
source "$(dirname "$0")/core.sh"
SNIPPET_DIR="$HOME/.ai/snippets"
STATE_DIR="$HOME/.ai/state"
HASH_FILE="$STATE_DIR/hashes.json"
BUILD_FILE="$HOME/.ai/index.html"
build_html() {
log_info "Building HTML from snippets..."
# Konkateniere Teile in definierter Reihenfolge
{
[[ -f "$SNIPPET_DIR/__header.html" ]] && cat "$SNIPPET_DIR/__header.html"
find "$SNIPPET_DIR" -type f -name '*.html' ! -name "__header.html" ! -name "__footer.html" | sort | while read -r f; do
cat "$f"
done
[[ -f "$SNIPPET_DIR/__footer.html" ]] && cat "$SNIPPET_DIR/__footer.html"
} > "$BUILD_FILE"
log_info "HTML built at $BUILD_FILE"
# Neuen Root-Hash berechnen
local root_hash
root_hash=$(new_root_hash)
log_info "Generated new root hash: $root_hash"
# Gesamten Snippet-Ordner hashen
local dir_hash
dir_hash=$(sha256sum_dir "$SNIPPET_DIR")
log_info "Directory content hash: $dir_hash"
# In state speichern
jq -n --arg root "$root_hash" --arg content "$dir_hash" '{root: $root, content: $content}' > "$HASH_FILE"
log_success "State written to $HASH_FILE"
echo "$root_hash"
}
build_html