#!/bin/bash # Documentation Enhancement Script for Rustelo # This script adds logos and branding to cargo doc output exit # TODO: Requir fix positioning in pages and ensure proper alignment set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Configuration LOGO_DIR="logos" DOC_DIR="target/doc" LOGO_FILE="rustelo-imag.svg" LOGO_HORIZONTAL="rustelo_dev-logo-h.svg" # Function to print colored output print_status() { echo -e "${GREEN}[INFO]${NC} $1" } print_warning() { echo -e "${YELLOW}[WARN]${NC} $1" } print_error() { echo -e "${RED}[ERROR]${NC} $1" } # Check if cargo doc has been run check_doc_exists() { if [ ! -d "$DOC_DIR" ]; then print_error "Documentation directory not found. Run 'cargo doc' first." exit 1 fi } # Check if logos exist check_logos_exist() { if [ ! -f "$LOGO_DIR/$LOGO_FILE" ]; then print_error "Logo file not found: $LOGO_DIR/$LOGO_FILE" exit 1 fi if [ ! -f "$LOGO_DIR/$LOGO_HORIZONTAL" ]; then print_error "Horizontal logo file not found: $LOGO_DIR/$LOGO_HORIZONTAL" exit 1 fi } # Copy logos to doc directory copy_logos_to_doc() { print_status "Copying logos to documentation directory..." # Create logos directory in doc mkdir -p "$DOC_DIR/logos" # Copy all logo files cp "$LOGO_DIR"/*.svg "$DOC_DIR/logos/" print_status "Logos copied successfully" } # Add logo to main crate page enhance_main_page() { local crate_name="$1" local index_file="$DOC_DIR/$crate_name/index.html" if [ ! -f "$index_file" ]; then print_warning "Index file not found for crate: $crate_name" return fi print_status "Enhancing main page for crate: $crate_name" # Create a backup cp "$index_file" "$index_file.backup" # Add logo to the main heading sed -i.tmp 's|

Crate '"$crate_name"'|
RUSTELO

Crate '"$crate_name"'

|g' "$index_file" # Create temporary CSS file cat > "/tmp/rustelo-css.tmp" << 'EOF' EOF # Add custom CSS for logo styling sed -i.tmp -e '/^[[:space:]]*<\/head>/{ r /tmp/rustelo-css.tmp d }' "$index_file" # Create temporary footer file cat > "/tmp/rustelo-footer.tmp" << 'EOF' EOF # Add footer with branding sed -i.tmp -e '/^[[:space:]]*<\/main>/{ r /tmp/rustelo-footer.tmp d }' "$index_file" # Clean up temporary files rm -f "/tmp/rustelo-css.tmp" "/tmp/rustelo-footer.tmp" # Clean up temporary files rm -f "$index_file.tmp" print_status "Enhanced main page for: $crate_name" } # Add logo to all module pages enhance_module_pages() { local crate_name="$1" local crate_dir="$DOC_DIR/$crate_name" if [ ! -d "$crate_dir" ]; then print_warning "Crate directory not found: $crate_name" return fi print_status "Enhancing module pages for crate: $crate_name" # Find all HTML files in the crate directory find "$crate_dir" -name "*.html" -type f | while read -r html_file; do # Skip if it's the main index file (already processed) if [[ "$html_file" == "$crate_dir/index.html" ]]; then continue fi # Create backup cp "$html_file" "$html_file.backup" # Add logo to sidebar sed -i.tmp 's|