-
Notifications
You must be signed in to change notification settings - Fork 484
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1152 from blockscout/tom2drum/issue-972
Add support for custom favicon
- Loading branch information
Showing
29 changed files
with
256 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
|
||
master_url="${NEXT_PUBLIC_FAVICON_MASTER_URL:-$NEXT_PUBLIC_NETWORK_ICON}" | ||
export MASTER_URL="$master_url" | ||
|
||
cd ./deploy/tools/favicon-generator | ||
./script.sh | ||
if [ $? -ne 0 ]; then | ||
cd ../../../ | ||
exit 1 | ||
else | ||
cd ../../../ | ||
favicon_folder="./public/favicon/" | ||
|
||
echo "⏳ Replacing default favicons with freshly generated pack..." | ||
if [ -d "$favicon_folder" ]; then | ||
rm -r "$favicon_folder" | ||
fi | ||
mkdir -p "$favicon_folder" | ||
cp -r ./deploy/tools/favicon-generator/output/* "$favicon_folder" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/output | ||
config.json | ||
response.json | ||
favicon_package** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"favicon_generation": { | ||
"api_key": "<api_key>", | ||
"master_picture": { | ||
"type": "url", | ||
"url": "<master_url>" | ||
}, | ||
"files_location": { | ||
"type": "path", | ||
"path": "/favicons" | ||
}, | ||
"favicon_design": { | ||
"desktop_browser": {}, | ||
"ios": { | ||
"picture_aspect": "no_change", | ||
"assets": { | ||
"ios6_and_prior_icons": false, | ||
"ios7_and_later_icons": true, | ||
"precomposed_icons": false, | ||
"declare_only_default_icon": true | ||
} | ||
}, | ||
"safari_pinned_tab": { | ||
"picture_aspect": "black_and_white", | ||
"threshold": 60 | ||
} | ||
}, | ||
"settings": { | ||
"compression": "3", | ||
"scaling_algorithm": "Mitchell", | ||
"error_on_image_too_small": true, | ||
"readme_file": false, | ||
"html_code_file": false, | ||
"use_path_as_is": false | ||
}, | ||
"versioning": { | ||
"param_name": "ver", | ||
"param_value": "15Zd8" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#!/bin/bash | ||
|
||
echo "🌀 Generating favicons bundle..." | ||
|
||
# Check if MASTER_URL is provided | ||
if [ -z "$MASTER_URL" ]; then | ||
echo "🛑 Error: MASTER_URL variable is not provided." | ||
exit 1 | ||
fi | ||
|
||
# Check if NEXT_PUBLIC_FAVICON_GENERATOR_API_KEY is provided | ||
if [ -z "$NEXT_PUBLIC_FAVICON_GENERATOR_API_KEY" ]; then | ||
echo "🛑 Error: NEXT_PUBLIC_FAVICON_GENERATOR_API_KEY variable is not provided." | ||
exit 1 | ||
fi | ||
|
||
# Mask the NEXT_PUBLIC_FAVICON_GENERATOR_API_KEY to display only the first 8 characters | ||
API_KEY_MASKED="${NEXT_PUBLIC_FAVICON_GENERATOR_API_KEY:0:8}***" | ||
echo "🆗 The following variables are provided:" | ||
echo " MASTER_URL: $MASTER_URL" | ||
echo " NEXT_PUBLIC_FAVICON_GENERATOR_API_KEY: $API_KEY_MASKED" | ||
echo | ||
|
||
# RealFaviconGenerator API endpoint URL | ||
API_URL="https://realfavicongenerator.net/api/favicon" | ||
|
||
# Target folder for the downloaded assets | ||
TARGET_FOLDER="./output" | ||
|
||
# Path to the config JSON template file | ||
CONFIG_TEMPLATE_FILE="config.template.json" | ||
|
||
# Path to the generated config JSON file | ||
CONFIG_FILE="config.json" | ||
|
||
# Replace <api_key> and <master_url> placeholders in the JSON template file | ||
API_KEY_VALUE="$NEXT_PUBLIC_FAVICON_GENERATOR_API_KEY" | ||
sed -e "s|<api_key>|$API_KEY_VALUE|" -e "s|<master_url>|$MASTER_URL|" "$CONFIG_TEMPLATE_FILE" > "$CONFIG_FILE" | ||
|
||
# Make the API POST request with JSON data from the config file | ||
echo "⏳ Making request to API..." | ||
API_RESPONSE=$(curl -s -X POST -H "Content-Type: application/json" -d @"$CONFIG_FILE" "$API_URL") | ||
|
||
# Create the response.json file with the API response | ||
echo "$API_RESPONSE" > response.json | ||
|
||
# Check if the API response is valid JSON and contains success status | ||
if ! jq -e '.favicon_generation_result.result.status == "success"' <<< "$API_RESPONSE" >/dev/null; then | ||
echo "🛑 Error: API response does not contain the expected structure or has an error status." | ||
ERROR_MESSAGE=$(echo "$API_RESPONSE" | jq -r '.favicon_generation_result.result.error_message' | tr -d '\\') | ||
if [ -n "$ERROR_MESSAGE" ]; then | ||
echo "🛑 $ERROR_MESSAGE" | ||
fi | ||
exit 1 | ||
fi | ||
echo "🆗 API responded with success status." | ||
|
||
# Parse the JSON response to extract the file URL and remove backslashes | ||
FILE_URL=$(echo "$API_RESPONSE" | jq -r '.favicon_generation_result.favicon.package_url' | tr -d '\\') | ||
PREVIEW_URL=$(echo "$API_RESPONSE" | jq -r '.favicon_generation_result.preview_picture_url' | tr -d '\\') | ||
|
||
# Check if FILE_URL is empty | ||
if [ -z "$FILE_URL" ]; then | ||
echo "🛑 File URL not found in JSON response." | ||
exit 1 | ||
fi | ||
|
||
echo "🆗 Found following file URL in the response: $FILE_URL" | ||
echo "🆗 Favicon preview URL: $PREVIEW_URL" | ||
echo | ||
|
||
# Generate a filename based on the URL | ||
FILE_NAME=$(basename "$FILE_URL") | ||
|
||
# Check if the target folder exists and clear its contents if it does | ||
if [ -d "$TARGET_FOLDER" ]; then | ||
rm -r "$TARGET_FOLDER" | ||
fi | ||
mkdir -p "$TARGET_FOLDER" | ||
|
||
# Download the file | ||
echo "⏳ Trying to download the file..." | ||
curl -s -L "$FILE_URL" -o "$FILE_NAME" | ||
|
||
# Check if the download was successful | ||
if [ $? -eq 0 ]; then | ||
echo "🆗 File downloaded successfully." | ||
echo | ||
else | ||
echo "🛑 Error: Failed to download the file." | ||
exit 1 | ||
fi | ||
|
||
# Unzip the downloaded file to the target folder | ||
echo "⏳ Unzipping the file..." | ||
unzip -q "$FILE_NAME" -d "$TARGET_FOLDER" | ||
|
||
# Check if the unzip operation was successful | ||
if [ $? -eq 0 ]; then | ||
echo "🆗 File unzipped successfully." | ||
echo | ||
else | ||
echo "🛑 Failed to unzip the file." | ||
exit 1 | ||
fi | ||
|
||
# Clean up - remove the JSON response file and temporary JSON config file | ||
rm response.json "$CONFIG_FILE" | ||
|
||
echo "✅ Done." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
secrets_file="./configs/envs/.env.secrets" | ||
favicon_folder="./public/favicon/" | ||
master_url="https://raw.githubusercontent.com/blockscout/frontend/main/tools/scripts/favicon.svg" | ||
|
||
if [ ! -f "$secrets_file" ]; then | ||
echo "Error: File '$secrets_file' not found." | ||
exit 1 | ||
fi | ||
|
||
dotenv \ | ||
-v MASTER_URL=$master_url \ | ||
-e $secrets_file \ | ||
-- bash -c 'cd ./deploy/tools/favicon-generator && ./script.sh' | ||
|
||
if [ -d "$favicon_folder" ]; then | ||
rm -r "$favicon_folder" | ||
fi | ||
mkdir -p "$favicon_folder" | ||
cp -r ./deploy/tools/favicon-generator/output/* "$favicon_folder" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.