Simplify favicon filename generation in workflow

Removed the use of associative arrays and second-level domain logic for favicon filename generation. Filenames now use the full domain directly, simplifying the code and reducing complexity.
This commit is contained in:
xixu-me committed 2025-06-10 15:54:18 +08:00
1 parent b8f6b82874
commit 2e9639457d
1 file changed
+3 -29
+3 -29
View File
@@ -103,10 +103,6 @@ jobs:
success_count=0
error_count=0
# Use associative arrays to track used filenames and next available index
declare -A filename_next_index
declare -A filename_used
# Read domains file line by line
while IFS= read -r domain; do
counter=$((counter + 1))
@@ -121,14 +117,6 @@ jobs:
echo "Progress: $counter/$total_domains domains processed (Success: $success_count, Errors: $error_count)"
fi
# Extract second-level domain (remove top-level domain)
second_level_domain=$(echo "$domain" | sed 's/\.[^.]*$//')
# Initialize next index for this domain if not yet set
if [[ -z "${filename_next_index[$second_level_domain]}" ]]; then
filename_next_index[$second_level_domain]=0
fi
# Construct favicon URL
favicon_url="https://t1.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://${domain}&size=256"
@@ -149,27 +137,13 @@ jobs:
error_count=$((error_count + 1))
echo "Warning: Generic favicon detected for domain: $domain (SHA-256: $file_hash)"
else
# Valid favicon downloaded - now assign the proper filename
current_index=${filename_next_index[$second_level_domain]}
# Determine the final filename
if [ $current_index -eq 0 ]; then
final_filename="$second_level_domain"
else
final_filename="${second_level_domain}_${current_index}"
fi
# Move the temp file to the final destination
favicon_file="favicons/${final_filename}.png"
# Valid favicon downloaded - use full domain as filename
favicon_file="favicons/${domain}.png"
mv "$temp_favicon_file" "$favicon_file"
# Mark this filename as used and increment the next index
filename_used["$final_filename"]=1
filename_next_index[$second_level_domain]=$((current_index + 1))
# Valid favicon downloaded
success_count=$((success_count + 1))
echo "Success: Downloaded favicon for $domain -> $final_filename.png"
echo "Success: Downloaded favicon for $domain -> ${domain}.png"
fi
else
# Remove empty file