Skip to content

Commit

Permalink
Add Favicon. (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
bstopp authored Jul 31, 2023
1 parent 28f47a5 commit 49a6a8f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Binary file added icons/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,23 @@ async function loadEager(doc) {
}
}

/**
* Adds the favicon.
* @param {string} href The favicon URL
*/
export function addFavIcon(href) {
const link = document.createElement('link');
link.rel = 'icon';
link.type = 'image/png';
link.href = href;
const existingLink = document.querySelector('head link[rel="icon"]');
if (existingLink) {
existingLink.parentElement.replaceChild(link, existingLink);
} else {
document.getElementsByTagName('head')[0].appendChild(link);
}
}

/**
* Loads everything that doesn't need to be delayed.
* @param {Element} doc The container element
Expand All @@ -149,6 +166,7 @@ async function loadLazy(doc) {
loadFooter(doc.querySelector('footer'));

loadCSS(`${window.hlx.codeBasePath}/styles/lazy-styles.css`);
addFavIcon(`${window.hlx.codeBasePath}/icons/favicon.png`);
sampleRUM('lazy');
sampleRUM.observe(main.querySelectorAll('div[data-block-name]'));
sampleRUM.observe(main.querySelectorAll('picture > img'));
Expand Down

0 comments on commit 49a6a8f

Please sign in to comment.