#!/bin/bash # Build script for OrcaSlicer WIKI using mkdocs # Outputs HTML to the wiki/ folder set -e # Exit on error # Parse command-line arguments DOWNLOAD_SVG=false for arg in "$@"; do case $arg in --download-svg|-d) DOWNLOAD_SVG=true shift ;; *) # Unknown option ;; esac done # Check for required dependencies command -v mkdocs >/dev/null 2>&1 || { echo "Error: mkdocs is required but not installed."; exit 1; } command -v python3 >/dev/null 2>&1 || { echo "Error: python3 is required but not installed."; exit 1; } python3 generate_nav.py --update echo "Building documentation with mkdocs..." # Clean previous build and prepare docs directory rm -rf wiki mkdir -p docs # Copy all markdown files and directories to docs, excluding wiki and docs itself # This creates a structure mkdocs can work with echo "Preparing documentation structure..." # Copy all directories and markdown files, excluding wiki, docs, and .git rsync -av \ --exclude='wiki' \ --exclude='docs' \ --exclude='.git' \ --exclude='*.sh' \ --exclude='*.py' \ --exclude='*.yml' \ --exclude='*.yaml' \ --exclude='README.md' \ --exclude='home.md' \ --exclude='.gitignore' \ --exclude='infill-analysis' \ . docs/ 2>/dev/null || { # Fallback: manually copy directories and markdown files echo "Using fallback copy method..." # Copy root level markdown files, excluding home.md and README.md find . -maxdepth 1 -name "*.md" ! -name "README.md" ! -name "home.md" -exec cp {} docs/ \; # Copy all directories with markdown files [ -d "images" ] && cp -r images docs/ 2>/dev/null || true [ -d "calibration" ] && cp -r calibration docs/ 2>/dev/null || true [ -d "developer_reference" ] && cp -r developer_reference docs/ 2>/dev/null || true [ -d "general_settings" ] && cp -r general_settings docs/ 2>/dev/null || true [ -d "material_settings" ] && cp -r material_settings docs/ 2>/dev/null || true [ -d "print_prepare" ] && cp -r print_prepare docs/ 2>/dev/null || true [ -d "print_settings" ] && cp -r print_settings docs/ 2>/dev/null || true [ -d "printer_settings" ] && cp -r printer_settings docs/ 2>/dev/null || true } # Copy home.md as index.md so mkdocs generates index.html at root level # (home.md was excluded from rsync, so copy it directly from source) if [ -f "home.md" ]; then cp home.md docs/index.md fi # Convert GitHub image URLs to relative local paths in all markdown files echo "Converting GitHub image URLs to local paths..." # Download SVG icons if option is enabled if [ "$DOWNLOAD_SVG" = true ]; then # Create directory for OrcaSlicer main repo icons mkdir -p docs/images/orcaslicer-icons # Extract and download unique SVG icons from OrcaSlicer main repo echo "Downloading SVG icons from OrcaSlicer main repo..." grep -roh "https://github.com/OrcaSlicer/OrcaSlicer/blob/main/resources/images/[^?)]*" docs/ 2>/dev/null | \ sort -u | while read url; do # Extract filename from URL filename=$(basename "$url") local_path="docs/images/orcaslicer-icons/$filename" # Download if not already cached if [ ! -f "$local_path" ]; then # Convert blob URL to raw URL raw_url=$(echo "$url" | sed 's|github.com/OrcaSlicer/OrcaSlicer/blob/main|raw.githubusercontent.com/OrcaSlicer/OrcaSlicer/main|') echo " Downloading: $filename" curl -sL "$raw_url" -o "$local_path" 2>/dev/null || true fi # If this is a *_dark.svg icon, also fetch the light variant so theme swapping works offline if echo "$filename" | grep -q "_dark\\.svg"; then light_filename=$(echo "$filename" | sed 's/_dark\\(\\.svg.*\\)/\\1/') light_local_path="docs/images/orcaslicer-icons/$light_filename" if [ ! -f "$light_local_path" ]; then light_url=$(echo "$url" | sed 's/_dark\\(\\.svg.*\\)/\\1/') light_raw_url=$(echo "$light_url" | sed 's|github.com/OrcaSlicer/OrcaSlicer/blob/main|raw.githubusercontent.com/OrcaSlicer/OrcaSlicer/main|') echo " Downloading: $light_filename" curl -sL "$light_raw_url" -o "$light_local_path" 2>/dev/null || true fi fi done else echo "Skipping SVG icon download (use --download-svg or -d to enable)" fi # Create a map of filename to path relative to docs for Wiki-style link resolution MD_MAP_FILE=$(mktemp) find docs -name "*.md" -type f | while read f; do name=$(basename "$f" .md) # Get path relative to docs/ rel="${f#docs/}" echo "$name|$rel" >> "$MD_MAP_FILE" done find docs -name "*.md" -type f | while read md_file; do # Calculate relative path to root based on file depth depth=$(echo "$md_file" | tr -cd '/' | wc -c) depth=$((depth - 1)) # Subtract 1 for "docs/" prefix="" for ((i=0; i/dev/null || echo "${relative_url}" | sed 's/ /%20/g') # Create redirect HTML content cat > "$redirect_file" <

Redirecting to ${filename}...

EOF done } create_redirects # Clean up docs directory after build rm -rf docs echo "Copying extra web assets to wiki folder..." mkdir -p wiki/assets/stylesheets mkdir -p wiki/assets/images mkdir -p wiki/assets/javascripts # Copy shared assets that complement MkDocs' static site output if [ -f "web_extras/extra.css" ]; then cp "web_extras/extra.css" wiki/assets/stylesheets/extra.css else echo "Warning: web_extras/extra.css not found - skipping" fi if [ -f "web_extras/OrcaSlicer.ico" ]; then cp "web_extras/OrcaSlicer.ico" wiki/assets/images/OrcaSlicer.ico else echo "Warning: web_extras/OrcaSlicer.ico not found - skipping" fi if [ -f "web_extras/OrcaSlicer.png" ]; then cp "web_extras/OrcaSlicer.png" wiki/assets/images/OrcaSlicer.png else echo "Warning: web_extras/OrcaSlicer.png not found - skipping" fi if [ -f "web_extras/icon-theme.js" ]; then cp "web_extras/icon-theme.js" wiki/assets/javascripts/icon-theme.js else echo "Warning: web_extras/icon-theme.js not found - skipping" fi if [ -f "web_extras/katex.js" ]; then cp "web_extras/katex.js" wiki/assets/javascripts/katex.js else echo "Warning: web_extras/katex.js not found - skipping" fi if [ -d "web_extras" ]; then mkdir -p wiki/web_extras cp -r web_extras/* wiki/web_extras/ 2>/dev/null || true else echo "Warning: web_extras directory not found - skipping" fi echo "Build complete! HTML files are in the wiki/ folder."