Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix favicon "not found" error on non-homepage pages #617

Merged
merged 6 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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="{{ site.baseurl }}/assets/favicon_06.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
20 changes: 19 additions & 1 deletion js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,25 @@ $(document).ready(function () {
if (logoID < 10) {
logoID = "0" + logoID;
}
document.querySelector('#defaultIcon1').href = 'https://www.sugarlabs.org/assets/favicon_' + logoID + '.png';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code you are removing has nothing to do with the issue; the issue and my tests of master branch just now show the error to be a reference to press/assets/favicon_06.png and this line you are removing is an absolute link without press.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have simplified the favicon logic by making the path relative to /press/, removing the full domain URL, and eliminating unnecessary existence checks, as shown in the following code:

var defaultIcon = document.querySelector('#defaultIcon1');
if (defaultIcon) {
    var logoID = colorIndex + 1;
    if (logoID < 10) {
        logoID = "0" + logoID;
    }
    defaultIcon.href = '/press/assets/favicon_' + logoID + '.png';
}

Also, I have removed the testing and existence checks. Is this approach fine?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've lost me here. Why would the path be made absolute from /press/?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I think relative path will be better for this like:

var defaultIcon = document.querySelector('#defaultIcon1');
if (defaultIcon) {
    var logoID = colorIndex + 1;
    if (logoID < 10) {
        logoID = "0" + logoID;
    }
    defaultIcon.href = 'assets/favicon_' + logoID + '.png';
}

Now it's pointing to the assets/ directory relative to the current location, which should be more flexible.


var defaultIcon = document.querySelector('#defaultIcon1');
if (defaultIcon) {
var logoID = colorIndex + 1;
if (logoID < 10) {
logoID = "0" + logoID;
}

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;
h = h.replace(/033cd2/g, selectedColors[0]);
h = h.replace(/78e600/g, selectedColors[1]);
Expand Down