|
| 1 | +#!/bin/bash |
| 2 | +# Generate a spell check configuration that only includes non-draft files |
| 3 | +# This script finds all markdown files EXCEPT those in draft Learning Paths |
| 4 | + |
| 5 | +cd "$(dirname "$(dirname "${BASH_SOURCE[0]}")")" || exit 1 |
| 6 | + |
| 7 | +output_config=".spellcheck-non-draft.yml" |
| 8 | + |
| 9 | +# Arrays to collect draft files |
| 10 | +draft_lp_dirs=() |
| 11 | +draft_install_guides=() |
| 12 | +draft_lp_files=() |
| 13 | + |
| 14 | +# Find draft Learning Path directories (those with cascade directive) |
| 15 | +echo "Finding draft Learning Paths with cascade directive..." |
| 16 | +draft_file_list=$(find content/learning-paths -type f -name "_index.md" -exec grep -l "^draft: true" {} \; 2>/dev/null) |
| 17 | +while IFS= read -r file; do |
| 18 | + [ -z "$file" ] && continue |
| 19 | + # Only mark entire directory as draft if it has cascade directive |
| 20 | + if grep -q "^cascade:" "$file" 2>/dev/null; then |
| 21 | + dir=$(dirname "$file") |
| 22 | + draft_lp_dirs+=("$dir") |
| 23 | + echo " - $dir/" |
| 24 | + fi |
| 25 | +done <<< "$draft_file_list" |
| 26 | +echo "Found ${#draft_lp_dirs[@]} draft Learning Path director(ies) with cascade" |
| 27 | +echo "" |
| 28 | + |
| 29 | +# Find draft install guides |
| 30 | +echo "Finding draft install guides..." |
| 31 | +while IFS= read -r file; do |
| 32 | + [ -z "$file" ] && continue |
| 33 | + if grep -q "^draft: true[[:space:]]*$" "$file" 2>/dev/null; then |
| 34 | + draft_install_guides+=("$file") |
| 35 | + echo " - $file" |
| 36 | + fi |
| 37 | +done < <(find content/install-guides -name "*.md" -type f | sort) |
| 38 | +echo "Found ${#draft_install_guides[@]} draft install guide(s)" |
| 39 | +echo "" |
| 40 | + |
| 41 | +# Find individual draft Learning Path files (not in cascade directories) |
| 42 | +echo "Finding individual draft Learning Path files..." |
| 43 | +while IFS= read -r file; do |
| 44 | + [ -z "$file" ] && continue |
| 45 | + |
| 46 | + # Check if this file is in a cascade-draft directory |
| 47 | + in_draft_dir=0 |
| 48 | + for draft_dir in "${draft_lp_dirs[@]}"; do |
| 49 | + if [[ "$file" == "$draft_dir"* ]]; then |
| 50 | + in_draft_dir=1 |
| 51 | + break |
| 52 | + fi |
| 53 | + done |
| 54 | + |
| 55 | + # If not in draft directory, check if individually marked as draft |
| 56 | + if [ $in_draft_dir -eq 0 ] && grep -q "^draft: true[[:space:]]*$" "$file" 2>/dev/null; then |
| 57 | + draft_lp_files+=("$file") |
| 58 | + echo " - $file" |
| 59 | + fi |
| 60 | +done < <(find content/learning-paths -name "*.md" -type f | sort) |
| 61 | +echo "Found ${#draft_lp_files[@]} individual draft Learning Path file(s)" |
| 62 | +echo "" |
| 63 | + |
| 64 | +# Write base config template |
| 65 | +cat > "$output_config" << 'EOF' |
| 66 | +matrix: |
| 67 | +- name: Markdown |
| 68 | + expect_match: false |
| 69 | + apsell: |
| 70 | + mode: en |
| 71 | + dictionary: |
| 72 | + wordlists: |
| 73 | + - .wordlist.txt |
| 74 | + output: wordlist.dic |
| 75 | + encoding: utf-8 |
| 76 | + pipeline: |
| 77 | + - pyspelling.filters.markdown: |
| 78 | + markdown_extensions: |
| 79 | + - markdown.extensions.extra: |
| 80 | + - pyspelling.filters.html: |
| 81 | + comments: false |
| 82 | + attributes: |
| 83 | + - alt |
| 84 | + ignores: |
| 85 | + - ':matches(code, pre)' |
| 86 | + - 'code' |
| 87 | + - 'pre' |
| 88 | + - 'blockquote' |
| 89 | + sources: |
| 90 | +EOF |
| 91 | + |
| 92 | +echo "Building sources list (excluding drafts)..." |
| 93 | + |
| 94 | +# Collect and add install guide files (excluding drafts) |
| 95 | +install_count=0 |
| 96 | +while IFS= read -r file; do |
| 97 | + [ -z "$file" ] && continue |
| 98 | + # Check if this install guide is marked as draft (allowing trailing whitespace) |
| 99 | + if ! grep -q "^draft: true[[:space:]]*$" "$file" 2>/dev/null; then |
| 100 | + echo " - '$file'" >> "$output_config" |
| 101 | + ((install_count++)) |
| 102 | + fi |
| 103 | +done < <(find content/install-guides -name "*.md" -type f | sort) |
| 104 | +echo "Found $install_count non-draft install guide(s)" |
| 105 | + |
| 106 | +# Collect and add non-draft learning path files |
| 107 | +lp_count=0 |
| 108 | +while IFS= read -r file; do |
| 109 | + [ -z "$file" ] && continue |
| 110 | + # Check if this file is in a cascade-draft directory |
| 111 | + is_draft=0 |
| 112 | + for draft_dir in "${draft_lp_dirs[@]}"; do |
| 113 | + if [[ "$file" == "$draft_dir"* ]]; then |
| 114 | + is_draft=1 |
| 115 | + break |
| 116 | + fi |
| 117 | + done |
| 118 | + |
| 119 | + # Also check if this individual file is marked as draft (allowing trailing whitespace) |
| 120 | + if [ $is_draft -eq 0 ] && grep -q "^draft: true[[:space:]]*$" "$file" 2>/dev/null; then |
| 121 | + is_draft=1 |
| 122 | + fi |
| 123 | + |
| 124 | + if [ $is_draft -eq 0 ]; then |
| 125 | + echo " - '$file'" >> "$output_config" |
| 126 | + ((lp_count++)) |
| 127 | + fi |
| 128 | +done < <(find content/learning-paths -name "*.md" -type f | sort) |
| 129 | +echo "Found $lp_count non-draft Learning Path source file(s)" |
| 130 | + |
| 131 | +if [ ! -f "$output_config" ]; then |
| 132 | + echo "Error: Failed to create $output_config" >&2 |
| 133 | + exit 1 |
| 134 | +fi |
| 135 | + |
| 136 | +echo "" |
| 137 | +echo "Generated spell check configuration: $output_config" |
| 138 | +echo " Install guides: $install_count" |
| 139 | +echo " Learning Path source files: $lp_count" |
| 140 | +echo " File size: $(wc -c < "$output_config") bytes" |
0 commit comments