#!/bin/bash source includes/icons.sh search_query="" if [[ -n "$QUERY_STRING" ]]; then search_query=$(echo "$QUERY_STRING" | sed -n 's/.*search=\([^&]*\).*/\1/p' | sed 's/%20/ /g' | sed 's/+/ /g') fi get_category_icon() { case "$1" in "Web") echo "$ICON_WEB" ;; "Pwn") echo "$ICON_PWN" ;; "Crypto") echo "$ICON_CRYPTO" ;; "Reverse") echo "$ICON_REVERSE" ;; "Forensics") echo "$ICON_FORENSICS" ;; "Misc") echo "$ICON_MISC" ;; *) echo "$ICON_DEFAULT" ;; esac } get_status_info() { case "$1" in "solved") echo "$ICON_CHECK|status-solved|Solved" ;; "in-progress") echo "$ICON_CLOCK|status-in-progress|In Progress" ;; "not-started") echo "$ICON_CIRCLE|status-not-started|Not Started" ;; *) echo "$ICON_CIRCLE|status-not-started|Not Started" ;; esac } cat << EOF
EOF challenge_count=0 while IFS='|' read -r id name category difficulty points description flag assignee files tags status; do [ -z "$id" ] && continue [[ "$id" =~ ^#.* ]] && continue challenge_count=$((challenge_count + 1)) if [ -n "$search_query" ]; then if ! echo "${name}|${category}|${tags}" | grep -qi "$search_query"; then continue fi fi category_icon=$(get_category_icon "$category") status_info=$(get_status_info "$status") status_icon=$(echo "$status_info" | cut -d'|' -f1) status_class=$(echo "$status_info" | cut -d'|' -f2) status_text=$(echo "$status_info" | cut -d'|' -f3) if [ -z "$assignee" ]; then assignee_display="Unassigned" else assignee_display="$assignee" fi case "$difficulty" in "Easy") difficulty_class="difficulty-easy" ;; "Medium") difficulty_class="difficulty-medium" ;; "Hard") difficulty_class="difficulty-hard" ;; *) difficulty_class="difficulty-easy" ;; esac tag_elements="" if [ -n "$tags" ]; then IFS=',' read -ra tag_array <<< "$tags" for tag in "${tag_array[@]}"; do tag_elements="${tag_elements}#${tag}" done fi cat << EOF
${category_icon} ${category}
${status_icon} ${status_text}

${name}

${TROPHY_ICON} ${points} pts
${USER_ICON} ${assignee_display}
${difficulty}
${tag_elements}
EOF done < data/challenges.txt if [ "$challenge_count" -eq 0 ]; then cat << EOF

No Challenges Yet

Get started by adding your first challenge!

EOF fi echo "
"