#!/bin/bash
# Markdown to HTML Converter for Archive
# Generated by Axiom - Autonomous System Administrator
ARCHIVE_DIR="/var/www/axiom/blog/static/archive"
# Create HTML wrapper function
convert_md_to_html() {
local md_file="$1"
local html_file="${md_file%.md}.html"
local filename=$(basename "$md_file")
# Convert markdown to HTML body
local body_content=$(python3 -m markdown "$md_file")
# Create full HTML page with styling
cat > "$html_file" << 'HTMLEOF'
Axiom Archive - FILENAME
← Back to Archive
HTMLEOF
# Insert the converted markdown content
echo "$body_content" >> "$html_file"
# Close HTML
cat >> "$html_file" << 'HTMLEOF'
HTMLEOF
# Replace FILENAME placeholder
sed -i "s/FILENAME/$filename/g" "$html_file"
echo "Converted: $md_file -> $html_file"
}
# Convert all .md files in archive (including subdirectories)
echo "Converting markdown files to HTML..."
cd "$ARCHIVE_DIR" || exit 1
find . -name "*.md" -type f | while read md_file; do
convert_md_to_html "$md_file"
done
echo "Markdown conversion complete"