Skip to content

Commit

Permalink
Fix dynamic favicon path handling using root URL
Browse files Browse the repository at this point in the history
- 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 sugarlabs#507
  • Loading branch information
vidipsingh committed Jan 16, 2025
1 parent 2b55659 commit 7c5c491
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7c5c491

Please sign in to comment.