-
Notifications
You must be signed in to change notification settings - Fork 241
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
base: master
Are you sure you want to change the base?
Conversation
You have a commit to add author name display to blog, yet this pull request is for the favicon problem. Please remove the commit 9c1b988. Also, you have placed in the pull request opening comment text that should be in the commit message of 53cb483. Please do read our guide to making commits carefully. |
- 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.
53cb483
to
58177ea
Compare
@quozl, I have removed the commit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced this is the right approach. Details are in the feedback below.
- rewrite commit messages as suggested earlier.
_layouts/base.html
Outdated
@@ -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" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is site.baseurl removed?
Why is there no file assets/favicon.png yet you link to it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will revert the changes in _layouts/base.html
to the previous version.
Since there is no /favicon.png
, should I refer to /assets/favicon_06.png
here instead as before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't mind either way, just that it should refer to something that exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, then I will change it to {{ site.baseurl }}/assets/favicon_06.png
.
js/main.js
Outdated
}; | ||
img.onerror = function() { | ||
// Fallback to default favicon | ||
defaultIcon.href = '/assets/favicon.png'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no file assets/favicon.png
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there is no /assets/favicon.png
, should I refer to /assets/favicon_06.png
here instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok sure.
js/main.js
Outdated
// Use absolute path for favicon | ||
var faviconPath = '/assets/favicon_' + logoID + '.png'; | ||
|
||
// Test if favicon exists before setting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why we need to test if it exists. We know exactly how many files we have, what their names are, and we know the code above this section in js/main.js.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll remove the favicon test since we already know the number and names of the images.
@@ -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'; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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/?
There was a problem hiding this comment.
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.
Hi @quozl, Thanks for the feedback. I’ll work on the changes as suggested. |
Sure. When I went to your commit message and read it, assuming the persona of a future developer trying to figure out why
It is alarming when a pull request opening comment has such a huge amount of detail that is left out of the commit message. Remember that the git commit message is kept in perpetuity, and pull requests are deleted eventually. The git repository clone on a developer's system is where everything necessary to development must be present. GitHub is only a public hosting point for the repository. |
Thanks for the feedback, @quozl! I’ll make sure to incorporate these practices in future commits and ensure all relevant details are included directly in the commit message. |
So you're saying you won't fix it for this pull request? Why not? Our purpose for review includes managing the history. You have just one commit. All you have to do is See our guide for reviewers to understand our review practices, and please learn to review your own work and others. We need more reviewers. |
Sorry about that, @quozl! I’ll make the necessary changes to the recent commit and ensure to follow these practices for all future commits as well. |
@pikurasa ready for your review; this pull request has finished technical review and is on the way toward commit message goodness, just need to know you are happy with the solution to the issue. |
if (logoID < 10) { | ||
logoID = "0" + logoID; | ||
} | ||
defaultIcon.href = 'assets/favicon_' + logoID + '.png'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, is use of relative path. Oops.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still taking a relative path?
I ask because I still see things like this in the logs:
Yes, it is now taking relative paths as intended. Previously, the code was referencing the favicon like this:
document.querySelector('#defaultIcon1').href = 'https://www.sugarlabs.org/assets/favicon_' + logoID + '.png';
However, I have updated it to use relative paths, as shown here:
defaultIcon.href = 'assets/favicon_' + logoID + '.png';
After this change, I am no longer seeing any errors in my logs, whether on Firefox or other browsers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, relative or absolute, doesn't matter, as long as the directory that contains the icons is accessed on both the root and lower pages. It works for the root page, but as @pikurasa said it doesn't work on lower pages, such as about-us/
. That's what you need to fix now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(a relative access from about-us/
would be to ../assets/
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, relative or absolute, doesn't matter, as long as the directory that contains the icons is accessed on both the root and lower pages. It works for the root page, but as @pikurasa said it doesn't work on lower pages, such as
about-us/
. That's what you need to fix now.
In the _layouts/base.html
, the previous line was:
<link id="defaultIcon1" rel="shortcut icon" href="{{ site.baseurl }}assets/favicon_06.png" />
I changed it to:
<link id="defaultIcon1" rel="shortcut icon" href="{{ site.baseurl }}/assets/favicon_06.png" />
The issue was that there was no forward slash between {{ site.baseurl }}
and assets
, which caused incorrect path resolution when navigating between pages like /about-us/
. Now, the problem of the favicon "not found" error on non-homepage pages is not there in Firefox.
Noted edited commit message on 1939ac9 Review comments;
|
- 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 sugarlabs#507
1939ac9
to
15f9065
Compare
This PR addresses the issue where favicons were not found on non-homepage pages, particularly on Firefox browser. The problem was traced to an incorrect favicon path that was not being handled properly across different pages.
Changes Made:
_layouts/base.html
to use a consistent, absolute path.js/main.js
to dynamically update the favicon based on a random color scheme.Issue Link:
Closes #507
How to Test:
/about-us
or/press
) on Firefox.Additional Notes:
OS and Browser Information: