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

Handle multiple link elements with rel=icon #76

Merged
merged 5 commits into from
Jul 21, 2020
Merged
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
17 changes: 6 additions & 11 deletions src/siteMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,16 @@ function getSiteName (window) {

/**
* Extracts an icon for the site from the DOM
* @returns {string|null} an icon URL
*/
async function getSiteIcon (window) {
const { document } = window

// Use the site's favicon if it exists
let icon = document.querySelector('head > link[rel="shortcut icon"]')
if (icon && await imgExists(icon.href)) {
return icon.href
}

// Search through available icons in no particular order
icon = Array.from(document.querySelectorAll('head > link[rel="icon"]'))
.find((_icon) => Boolean(_icon.href))
if (icon && await imgExists(icon.href)) {
return icon.href
const icons = document.querySelectorAll('head > link[rel~="icon"]')
for (const icon of icons) {
if (icon && await imgExists(icon.href)) {
return icon.href
}
}

return null
Expand Down