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 1/4] 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]); From 15f9065f1aa705e3863ec1a60fa47d40437c5d96 Mon Sep 17 00:00:00 2001 From: Vidip Singh <112854574+vidipsingh@users.noreply.github.com> Date: Sat, 4 Jan 2025 14:55:02 +0530 Subject: [PATCH 2/4] Fix favicon path issue on non-homepage pages in Firefox - Fixed "favicon not found" error on non-homepage pages, particularly in Firefox. - Problem traced to incorrect favicon path introduced in commit 58177ea. - Updated path from absolute to relative to resolve the issue. - Ensures favicons load correctly across all pages. Fixes #507 --- _layouts/base.html | 2 +- js/main.js | 18 +++++------------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/_layouts/base.html b/_layouts/base.html index 3e103da4..2be9fdfc 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 df1b9ed0..c411f555 100755 --- a/js/main.js +++ b/js/main.js @@ -19,19 +19,11 @@ $(document).ready(function () { 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 logoID = colorIndex + 1; + if (logoID < 10) { + logoID = "0" + logoID; + } + defaultIcon.href = 'assets/favicon_' + logoID + '.png'; } var h = document.querySelector('.logo1').innerHTML; From 245ea8cdae5f20236727dcb2adca67b004d38d85 Mon Sep 17 00:00:00 2001 From: Vidip Singh <112854574+vidipsingh@users.noreply.github.com> Date: Sat, 11 Jan 2025 01:03:24 +0530 Subject: [PATCH 3/4] Fix dynamic favicon path handling for subdirectory pages - Fixed issue with favicon path on subdirectory pages by dynamically extracting and updating favicon filename. - Problem traced to previous commit 15f9065 which introduced static favicon path. - Ensured favicon loads correctly across all pages in firefox. Fixes #507 --- _layouts/base.html | 2 +- js/main.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/_layouts/base.html b/_layouts/base.html index 2be9fdfc..f1f9d1c2 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 c411f555..481828e4 100755 --- a/js/main.js +++ b/js/main.js @@ -23,7 +23,13 @@ $(document).ready(function () { if (logoID < 10) { logoID = "0" + logoID; } - defaultIcon.href = 'assets/favicon_' + logoID + '.png'; + + // Extract the base path from the current favicon href + var currentHref = defaultIcon.getAttribute('href'); + var basePath = currentHref.substring(0, currentHref.lastIndexOf('/') + 1); + + // Update only the filename portion while keeping the original path + defaultIcon.href = basePath + 'favicon_' + logoID + '.png'; } var h = document.querySelector('.logo1').innerHTML; From 7c5c491da8ed15ebf1337413ac0e76f97425f7e1 Mon Sep 17 00:00:00 2001 From: Vidip Singh <112854574+vidipsingh@users.noreply.github.com> Date: Thu, 16 Jan 2025 22:26:09 +0530 Subject: [PATCH 4/4] Fix dynamic favicon path handling using root URL - Updated favicon handling to dynamically set the favicon path based on the root URL. - Fixed the issue in the commit 245ea8c where favicon would not load correctly on subdirectory pages by calculating the site root URL using window location. Fixes #507 --- js/main.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/js/main.js b/js/main.js index 481828e4..4050c5fe 100755 --- a/js/main.js +++ b/js/main.js @@ -23,13 +23,16 @@ $(document).ready(function () { if (logoID < 10) { logoID = "0" + logoID; } - - // Extract the base path from the current favicon href - var currentHref = defaultIcon.getAttribute('href'); - var basePath = currentHref.substring(0, currentHref.lastIndexOf('/') + 1); - // Update only the filename portion while keeping the original path - defaultIcon.href = basePath + 'favicon_' + logoID + '.png'; + var rootUrl = ''; + var baseTag = document.querySelector('base'); + if (baseTag && baseTag.href) { + rootUrl = baseTag.href; + } else { + rootUrl = window.location.protocol + '//' + window.location.host + '/'; + } + + defaultIcon.href = rootUrl + 'assets/favicon_' + logoID + '.png'; } var h = document.querySelector('.logo1').innerHTML;