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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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="/assets/favicon.png" />
Copy link
Contributor

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?

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 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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

<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';
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) {
// Use absolute path for favicon
var faviconPath = '/assets/favicon_' + logoID + '.png';

// Test if favicon exists before setting
Copy link
Contributor

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.

Copy link
Contributor Author

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.

var img = new Image();
img.onload = function() {
defaultIcon.href = faviconPath;
};
img.onerror = function() {
// Fallback to default favicon
defaultIcon.href = '/assets/favicon.png';
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

As above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok sure.

};
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