-
Notifications
You must be signed in to change notification settings - Fork 242
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,16 @@ $(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) { | ||
var logoID = colorIndex + 1; | ||
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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (a relative access from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In the <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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I know, but I was not talking about that part of the change. I was talking about the part of the change that this discussion thread is linked to; js/main.js line 26, which loads a relative path into the element href, without dereferencing the current document's relative path, which is why the browser then reports failures to find the png files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@quozl The change that I made for this is as follows: var defaultIcon = document.querySelector('#defaultIcon1');
if (defaultIcon) {
var logoID = colorIndex + 1;
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';
} And in <link id="defaultIcon1" rel="shortcut icon" href="{{ site.baseurl }}/assets/favicon_06.png" /> This approach resolves the issue of subdirectories by dynamically extracting the base path from the current favicon and then updating only the filename. By preserving the base path that starts from Would this be a good approach to resolve the issue? I’d also appreciate any suggestions you might have to improve it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hope so. Commit the change and push to the pull request branch so that I can see it in context and we can test. |
||
} | ||
|
||
var h = document.querySelector('.logo1').innerHTML; | ||
h = h.replace(/033cd2/g, selectedColors[0]); | ||
h = h.replace(/78e600/g, selectedColors[1]); | ||
|
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: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:
Now it's pointing to the
assets/
directory relative to the current location, which should be more flexible.