#!/bin/bash
# static_pages_generator.sh - Erzeugt alle einfachen, statischen Seiten

generate_homepage() {
    local p="${WEB_ROOT_PATH}/index.html"
    local c="${WEB_CONTENT_STATIC_PATH}/startseite_content.html"
    {
        generate_html_header "Willkommen" "." "home"
        if [ -f "$c" ]; then cat "$c"; else echo "<h2>Willkommen!</h2>"; fi
        generate_html_footer
    } > "$p"
}

generate_impressum() {
    local p="${WEB_ROOT_PATH}/impressum.html"
    local c="${WEB_CONTENT_STATIC_PATH}/impressum_content.html"
    {
        generate_html_header "Impressum" "."
        if [ -f "$c" ]; then cat "$c"; else echo "<h2>Impressum</h2><p>Betreiber: ${SITE_OWNER_NAME}<br>Kontakt: <a href='mailto:${SITE_OWNER_EMAIL}'>${SITE_OWNER_EMAIL}</a></p>"; fi
        generate_html_footer
    } > "$p"
}

generate_downloads_page() {
    local p="${WEB_ROOT_PATH}/downloads.html"
    local c="${WEB_CONTENT_STATIC_PATH}/downloads_content.html"
    {
        generate_html_header "Downloads" "." "downloads"
        if [ -f "$c" ]; then cat "$c"; else cat >&1 <<EOF
<h2>Downloads</h2><p>Offizielle Seite: <a href="https://www.luanti.org/downloads/" target="_blank">luanti.org</a></p>
EOF
        fi
        generate_html_footer
    } > "$p"
}

generate_datenschutz_page() {
    local p="${WEB_ROOT_PATH}/datenschutz.html"
    local c="${WEB_CONTENT_STATIC_PATH}/datenschutz_content.html"
    {
        generate_html_header "Datenschutz" "."
        if [ -f "$c" ]; then cat "$c"; else echo "<h2>Datenschutzerklärung</h2><p>Platzhalter.</p>"; fi
        generate_html_footer
    } > "$p"
}

generate_static_pages() {
    log_message "Generiere statische Seiten (Homepage, Impressum etc.)..."
    generate_homepage
    generate_impressum
    generate_downloads_page
    generate_datenschutz_page
}
