|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Script to find orphaned pages - .md files not linked in Sidebar.md |
| 4 | +# These pages exist but are not accessible through the main navigation |
| 5 | + |
| 6 | +set -e |
| 7 | + |
| 8 | +# Colors for output |
| 9 | +RED='\033[0;31m' |
| 10 | +GREEN='\033[0;32m' |
| 11 | +YELLOW='\033[1;33m' |
| 12 | +BLUE='\033[0;34m' |
| 13 | +NC='\033[0m' # No Color |
| 14 | + |
| 15 | +SIDEBAR_FILE="wiki-default/Sidebar.md" |
| 16 | + |
| 17 | +# Check if Sidebar.md exists |
| 18 | +if [[ ! -f "$SIDEBAR_FILE" ]]; then |
| 19 | + echo -e "${RED}Error: $SIDEBAR_FILE not found${NC}" |
| 20 | + exit 1 |
| 21 | +fi |
| 22 | + |
| 23 | +echo "Checking for orphaned pages in wiki-default/..." |
| 24 | +echo "" |
| 25 | + |
| 26 | +# Extract all .md file links from Sidebar.md (normalize paths) |
| 27 | +linked_pages=() |
| 28 | +while IFS= read -r link; do |
| 29 | + # Skip empty lines |
| 30 | + [[ -z "$link" ]] && continue |
| 31 | + |
| 32 | + # Remove leading/trailing whitespace |
| 33 | + link=$(echo "$link" | xargs) |
| 34 | + |
| 35 | + # Normalize path - remove leading ./ and wiki-default/ |
| 36 | + link="${link#./}" |
| 37 | + link="${link#wiki-default/}" |
| 38 | + |
| 39 | + linked_pages+=("$link") |
| 40 | +done < <(perl -nle 'while (/\]\(([^)]+(?:\([^)]*\)[^)]*)*)\)/g) { print $1 }' "$SIDEBAR_FILE" 2>/dev/null | grep '\.md$') |
| 41 | + |
| 42 | +# Find all .md files in wiki-default (excluding Sidebar.md, Footer.md, _* files) |
| 43 | +orphaned_pages=() |
| 44 | +total_pages=0 |
| 45 | + |
| 46 | +while IFS= read -r -d '' md_file; do |
| 47 | + # Get relative path from wiki-default/ |
| 48 | + rel_path="${md_file#wiki-default/}" |
| 49 | + |
| 50 | + # Skip special files |
| 51 | + if [[ "$rel_path" == "Sidebar.md" ]] || \ |
| 52 | + [[ "$rel_path" == "Footer.md" ]] || \ |
| 53 | + [[ "$rel_path" == _* ]] || \ |
| 54 | + [[ "$rel_path" == */_* ]]; then |
| 55 | + continue |
| 56 | + fi |
| 57 | + |
| 58 | + total_pages=$((total_pages + 1)) |
| 59 | + |
| 60 | + # Check if this page is linked in Sidebar |
| 61 | + found=false |
| 62 | + for linked in "${linked_pages[@]}"; do |
| 63 | + if [[ "$linked" == "$rel_path" ]]; then |
| 64 | + found=true |
| 65 | + break |
| 66 | + fi |
| 67 | + done |
| 68 | + |
| 69 | + if [[ "$found" == false ]]; then |
| 70 | + orphaned_pages+=("$rel_path") |
| 71 | + fi |
| 72 | +done < <(find wiki-default -name "*.md" -type f -print0) |
| 73 | + |
| 74 | +echo "====================" |
| 75 | +echo "Summary:" |
| 76 | +echo "====================" |
| 77 | +echo -e "Total pages (excluding special files): ${total_pages}" |
| 78 | +echo -e "Pages linked in Sidebar: ${#linked_pages[@]}" |
| 79 | +echo -e "Orphaned pages: ${#orphaned_pages[@]}" |
| 80 | +echo "" |
| 81 | + |
| 82 | +if [[ ${#orphaned_pages[@]} -eq 0 ]]; then |
| 83 | + echo -e "${GREEN}✓ No orphaned pages found - all pages are linked in Sidebar.md${NC}" |
| 84 | + exit 0 |
| 85 | +else |
| 86 | + echo -e "${YELLOW}⚠ Found ${#orphaned_pages[@]} orphaned page(s):${NC}" |
| 87 | + echo "" |
| 88 | + for page in "${orphaned_pages[@]}"; do |
| 89 | + echo -e " ${BLUE}•${NC} $page" |
| 90 | + done |
| 91 | + echo "" |
| 92 | + echo -e "${YELLOW}Note: These pages exist but are not accessible through the sidebar navigation.${NC}" |
| 93 | + echo -e "${YELLOW}Consider adding them to Sidebar.md or moving them to the Orphans/ directory.${NC}" |
| 94 | + exit 0 |
| 95 | +fi |
0 commit comments