Update generate-db.yml

This commit is contained in:
FoxStorm1 2023-09-24 19:01:00 +01:00 committed by GitHub
parent 190c0463cd
commit a351e43fef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,4 @@
name: Update dist.css name: Update dist.css and Avatars
on: on:
push: push:
@ -8,7 +8,7 @@ on:
- ".github/workflows/generate-db.yml" - ".github/workflows/generate-db.yml"
- ".github/scripts/generate/**/*.*" - ".github/scripts/generate/**/*.*"
- "db/template.css" - "db/template.css"
- "db/data.json" # Add the path to your JSON file here - "db/datadesktop.json" # Add the path to your JSON file here
pull_request: pull_request:
branches: branches:
- main - main
@ -35,7 +35,7 @@ jobs:
run: | run: |
cp db/data.json db/datadesktop.json cp db/data.json db/datadesktop.json
- name: Update dist.css - name: Update dist.css and Avatars
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
@ -45,15 +45,18 @@ jobs:
# Read the JSON data into a variable # Read the JSON data into a variable
JSON_DATA=$(cat "$JSON_FILE") JSON_DATA=$(cat "$JSON_FILE")
# Initialize an empty CSS content variable # Initialize an empty CSS content variable for badges
CSS_CONTENT="" BADGES_CSS_CONTENT=""
# Initialize an empty CSS content variable for avatars (pfps)
AVATARS_CSS_CONTENT=""
# Loop through each badge entry in the JSON data # Loop through each badge entry in the JSON data
for DISCORD_ID in $(echo "$JSON_DATA" | jq -r '.badges | keys[]'); do for DISCORD_ID in $(echo "$JSON_DATA" | jq -r '.badges | keys[]'); do
BADGE_URL=$(echo "$JSON_DATA" | jq -r ".badges[\"$DISCORD_ID\"]") BADGE_URL=$(echo "$JSON_DATA" | jq -r ".badges[\"$DISCORD_ID\"]")
# Create CSS snippet for the badge # Create CSS snippet for the badge
CSS_SNIPPET=".userProfileInner-1ngKnf:has(.avatar-31d8He[src^=\"https://cdn.discordapp.com/avatars/$DISCORD_ID\"]) > .topSection-13QKHs > header > .header-S26rhB > .headerTop-1PNKck > .container-1gYwHN:before, BADGES_CSS_SNIPPET=".userProfileInner-1ngKnf:has(.avatar-31d8He[src^=\"https://cdn.discordapp.com/avatars/$DISCORD_ID\"]) > .topSection-13QKHs > header > .header-S26rhB > .headerTop-1PNKck > .container-1gYwHN:before,
.userPopoutInner-nv9Y92:has(.avatar-31d8He[src^=\"https://cdn.discordapp.com/avatars/$DISCORD_ID\"]) > .container-1gYwHN:before, .userPopoutInner-nv9Y92:has(.avatar-31d8He[src^=\"https://cdn.discordapp.com/avatars/$DISCORD_ID\"]) > .container-1gYwHN:before,
.userInfo-regn9W:has([src^=\"https://cdn.discordapp.com/avatars/$DISCORD_ID\"]) > .wrapper-3Un6-K + div > .container-1gYwHN:before, .userInfo-regn9W:has([src^=\"https://cdn.discordapp.com/avatars/$DISCORD_ID\"]) > .wrapper-3Un6-K + div > .container-1gYwHN:before,
.userPopoutInner-nv9Y92:has(.imageUploaderInner-IIRaFr[style*=\"$DISCORD_ID\"]) > .container-1gYwHN:before { .userPopoutInner-nv9Y92:has(.imageUploaderInner-IIRaFr[style*=\"$DISCORD_ID\"]) > .container-1gYwHN:before {
@ -63,28 +66,25 @@ jobs:
background: url($BADGE_URL) center / 100% 100%; background: url($BADGE_URL) center / 100% 100%;
}" }"
# Append the CSS snippet to the CSS content # Append the badge CSS snippet to the badge CSS content
CSS_CONTENT="${CSS_CONTENT}\n\n$CSS_SNIPPET" BADGES_CSS_CONTENT="${BADGES_CSS_CONTENT}\n\n$BADGES_CSS_SNIPPET"
done done
# Loop through each avatar entry in the JSON data # Loop through each avatar (pfp) entry in the JSON data
for DISCORD_ID in $(echo "$JSON_DATA" | jq -r '.avatars | keys[]'); do for DISCORD_ID in $(echo "$JSON_DATA" | jq -r '.avatars | keys[]'); do
AVATAR_URL=$(echo "$JSON_DATA" | jq -r ".avatars[\"$DISCORD_ID\"]") AVATAR_URL=$(echo "$JSON_DATA" | jq -r ".avatars[\"$DISCORD_ID\"]")
# Create CSS snippet for the avatar # Create CSS snippet for the avatar (pfp)
CSS_SNIPPET="[style^=\"https://cdn.discordapp.com/avatars/$DISCORD_ID\"],[src^=\"https://cdn.discordapp.com/avatars/$DISCORD_ID\"],.userAvatar-3Hwf1F:is([style*=\"$DISCORD_ID\"]) { AVATARS_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;}"
content: url($AVATAR_URL);
background-image: url($AVATAR_URL) !important;
}"
# Append the CSS snippet to the CSS content # Append the avatar (pfp) CSS snippet to the avatar (pfp) CSS content
CSS_CONTENT="${CSS_CONTENT}\n\n$CSS_SNIPPET" AVATARS_CSS_CONTENT="${AVATARS_CSS_CONTENT}\n\n$AVATARS_CSS_SNIPPET"
done done
# Update the existing CSS content with new/updated badges and avatars # Use awk to replace the existing badge and avatar (pfp) sections in the CSS file
sed -i '/\/\* Discord Badges and Avatars \*\// {n; /\/\* End of Discord Badges and Avatars \*\// {i\ awk -v badges_content="$BADGES_CSS_CONTENT" -v avatars_content="$AVATARS_CSS_CONTENT" '/\/\* Discord Badges \*\// {print; print badges_content; f=1; next} /\/\* End of Discord Badges \*\// {if (f) f=0; else print} !f' "$CSS_FILE" > tmpfile && mv tmpfile "$CSS_FILE"
'"$CSS_CONTENT"'
; :a;n;ba}}' "$CSS_FILE" awk -v avatars_content="$AVATARS_CSS_CONTENT" '/\/\* Discord Avatars \*\// {print; print avatars_content; f=1; next} /\/\* End of Discord Avatars \*\// {if (f) f=0; else print} !f' "$CSS_FILE" > tmpfile && mv tmpfile "$CSS_FILE"
- name: Push changes - name: Push changes
continue-on-error: ${{ success() }} continue-on-error: ${{ success() }}