Skip to content

Commit

Permalink
Fix favicon "not found" error on non-homepage pages
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
vidipsingh committed Dec 30, 2024
1 parent b5ee41f commit 58177ea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion _layouts/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link id="defaultIcon1" rel="shortcut icon" href="{{ site.baseurl }}assets/favicon_06.png" />
<link id="defaultIcon1" rel="shortcut icon" href="/assets/favicon.png" />
<title>{{ page.title }}</title>
<link href="{{ site.baseurl }}/css/googleFonts.css" rel="stylesheet" type="text/css" >
<meta name="robots" content="index,follow,NOODP" />
Expand Down
19 changes: 18 additions & 1 deletion js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit 58177ea

Please sign in to comment.