From 58177ead48db03d571d671691715414545fcfa27 Mon Sep 17 00:00:00 2001
From: Vidip Singh <112854574+vidipsingh@users.noreply.github.com>
Date: Sun, 29 Dec 2024 15:07:40 +0530
Subject: [PATCH] Fix favicon "not found" error on non-homepage pages
- Updated `_layouts/base.html` to use a consistent favicon path.
- Modified `js/main.js` to handle dynamic favicon changes with error handling.
- Added fallback to the default favicon if a specific favicon is not found.
---
_layouts/base.html | 2 +-
js/main.js | 19 ++++++++++++++++++-
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/_layouts/base.html b/_layouts/base.html
index 656bc3fb..3e103da4 100755
--- a/_layouts/base.html
+++ b/_layouts/base.html
@@ -4,7 +4,7 @@
-
+
{{ page.title }}
diff --git a/js/main.js b/js/main.js
index cc9809bc..df1b9ed0 100755
--- a/js/main.js
+++ b/js/main.js
@@ -16,7 +16,24 @@ $(document).ready(function () {
if (logoID < 10) {
logoID = "0" + logoID;
}
- document.querySelector('#defaultIcon1').href = 'https://www.sugarlabs.org/assets/favicon_' + logoID + '.png';
+
+ var defaultIcon = document.querySelector('#defaultIcon1');
+ if (defaultIcon) {
+ // Use absolute path for favicon
+ var faviconPath = '/assets/favicon_' + logoID + '.png';
+
+ // Test if favicon exists before setting
+ var img = new Image();
+ img.onload = function() {
+ defaultIcon.href = faviconPath;
+ };
+ img.onerror = function() {
+ // Fallback to default favicon
+ defaultIcon.href = '/assets/favicon.png';
+ };
+ img.src = faviconPath;
+ }
+
var h = document.querySelector('.logo1').innerHTML;
h = h.replace(/033cd2/g, selectedColors[0]);
h = h.replace(/78e600/g, selectedColors[1]);