|
1 | 1 | #!/bin/bash |
2 | | -# Script to list presentations for index.html |
3 | | -# This generates a JSON array that can be copied into index.html |
| 2 | +# Script to automatically update presentations array in index.html |
4 | 3 |
|
5 | | -echo "// Copy this array into index.html:" |
6 | | -echo "const presentations = [" |
7 | | - |
8 | | -first=true |
9 | | -for dir in presentations/*/; do |
10 | | - if [ -d "$dir" ]; then |
11 | | - name=$(basename "$dir") |
12 | | - |
13 | | - if [ "$first" = true ]; then |
14 | | - first=false |
15 | | - else |
16 | | - echo "," |
17 | | - fi |
18 | | - |
19 | | - # Extract title from the presentation's index.html if possible |
20 | | - title_file="$dir/index.html" |
21 | | - if [ -f "$title_file" ]; then |
22 | | - # Try to extract the first h1 tag |
23 | | - title=$(grep -m 1 "<h1>" "$title_file" | sed 's/.*<h1>\(.*\)<\/h1>.*/\1/' | sed 's/^[[:space:]]*//') |
24 | | - if [ -z "$title" ]; then |
25 | | - # Fallback to name if no h1 found |
26 | | - title="$name" |
| 4 | +# Generate presentations array |
| 5 | +generate_presentations_array() { |
| 6 | + echo "[" |
| 7 | + |
| 8 | + first=true |
| 9 | + for dir in */; do |
| 10 | + if [ -d "$dir" ] && [ -f "${dir}index.html" ] && [ -f "${dir}slides.md" ]; then |
| 11 | + name=$(basename "$dir") |
| 12 | + # Skip known system directories |
| 13 | + if [[ "$name" != "lib" && "$name" != "node_modules" && "$name" != ".git" && "$name" != "templates" && "$name" != "scripts" && "$name" != "presentations" ]]; then |
| 14 | + if [ "$first" = true ]; then |
| 15 | + first=false |
| 16 | + else |
| 17 | + echo "," |
| 18 | + fi |
| 19 | + |
| 20 | + # Extract title from slides.md first line or use formatted name |
| 21 | + title_file="$dir/slides.md" |
| 22 | + if [ -f "$title_file" ]; then |
| 23 | + # Try to extract title from first line (assuming it's # Title) |
| 24 | + title=$(head -n 1 "$title_file" | sed 's/^#\+[[:space:]]*//') |
| 25 | + if [ -z "$title" ] || [ "$title" = "$(head -n 1 "$title_file")" ]; then |
| 26 | + # Format the slug as title if no markdown title found |
| 27 | + title=$(echo "$name" | sed 's/-/ /g' | sed 's/\b\w/\U&/g') |
| 28 | + fi |
| 29 | + else |
| 30 | + # Format the slug as title |
| 31 | + title=$(echo "$name" | sed 's/-/ /g' | sed 's/\b\w/\U&/g') |
| 32 | + fi |
| 33 | + |
| 34 | + echo -n " { " |
| 35 | + echo -n "slug: '$name', " |
| 36 | + echo -n "title: '$title', " |
| 37 | + echo -n "description: 'Click to view presentation' " |
| 38 | + echo -n "}" |
27 | 39 | fi |
28 | | - else |
29 | | - title="$name" |
30 | 40 | fi |
31 | | - |
32 | | - echo -n " { slug: '$name', title: '$title', description: 'Add description here' }" |
| 41 | + done |
| 42 | + |
| 43 | + echo "" |
| 44 | + echo " ]" |
| 45 | +} |
| 46 | + |
| 47 | +# Update index.html with new presentations array |
| 48 | +temp_file=$(mktemp) |
| 49 | +in_presentations_array=false |
| 50 | + |
| 51 | +while IFS= read -r line; do |
| 52 | + if [[ $line =~ ^[[:space:]]*const[[:space:]]+presentations[[:space:]]*=[[:space:]]*\[ ]]; then |
| 53 | + echo " const presentations = $(generate_presentations_array);" |
| 54 | + in_presentations_array=true |
| 55 | + elif [[ $in_presentations_array == true && $line =~ "];" ]]; then |
| 56 | + in_presentations_array=false |
| 57 | + # Skip this line as it's already included in our generated array |
| 58 | + elif [[ $in_presentations_array == false ]]; then |
| 59 | + echo "$line" |
33 | 60 | fi |
34 | | -done |
| 61 | +done < index.html > "$temp_file" |
35 | 62 |
|
36 | | -echo "" |
37 | | -echo "];" |
38 | | -echo "" |
39 | | -echo "Update index.html with the above array!" |
| 63 | +mv "$temp_file" index.html |
| 64 | +echo "✅ Updated index.html with current presentations" |
0 commit comments