Update generate-db.yml

This commit is contained in:
FoxStorm1 2023-09-24 18:45:07 +01:00 committed by GitHub
parent e56a26c58e
commit 9f62942052
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -39,7 +39,7 @@ jobs:
id: update-dist-css id: update-dist-css
run: | run: |
# Define the paths to your JSON and CSS files # Define the paths to your JSON and CSS files
JSON_FILE="db/data.json" JSON_FILE="db/datadesktop.json"
CSS_FILE="db/dist.css" CSS_FILE="db/dist.css"
# Read the JSON data into a variable # Read the JSON data into a variable
@ -67,16 +67,24 @@ jobs:
CSS_CONTENT="${CSS_CONTENT}\n\n$CSS_SNIPPET" CSS_CONTENT="${CSS_CONTENT}\n\n$CSS_SNIPPET"
done done
# Append or update the CSS content in the CSS file # Loop through each avatar entry in the JSON data
if grep -q '/* Discord Badges */' "$CSS_FILE"; then for DISCORD_ID in $(echo "$JSON_DATA" | jq -r '.avatars | keys[]'); do
# Update existing badge styles AVATAR_URL=$(echo "$JSON_DATA" | jq -r ".avatars[\"$DISCORD_ID\"]")
sed -i '/\/\* Discord Badges \*\// {n; /\/\* End of Discord Badges \*\// {i\
# Create CSS snippet for the avatar
CSS_SNIPPET="[style^=\"https://cdn.discordapp.com/avatars/$DISCORD_ID\"],[src^=\"https://cdn.discordapp.com/avatars/$DISCORD_ID\"],.userAvatar-3Hwf1F:is([style*=\"$DISCORD_ID\"]) {
content: url($AVATAR_URL);
background-image: url($AVATAR_URL) !important;
}"
# Append the CSS snippet to the CSS content
CSS_CONTENT="${CSS_CONTENT}\n\n$CSS_SNIPPET"
done
# Update the existing CSS content with new/updated badges and avatars
sed -i '/\/\* Discord Badges and Avatars \*\// {n; /\/\* End of Discord Badges and Avatars \*\// {i\
'"$CSS_CONTENT"' '"$CSS_CONTENT"'
; :a;n;ba}}' "$CSS_FILE" ; :a;n;ba}}' "$CSS_FILE"
else
# Append badge styles to the end of the file
echo -e "\n/* Discord Badges */\n$CSS_CONTENT\n/* End of Discord Badges */" >> "$CSS_FILE"
fi
- name: Push changes - name: Push changes
continue-on-error: ${{ success() }} continue-on-error: ${{ success() }}