Skip to content

Add favicon for subpages #3054

Answered by pdehaan
NING3739 asked this question in Q&A
Sep 22, 2023 · 2 comments · 3 replies
Discussion options

You must be logged in to vote

If the above idea sounds tedious and boring, another approach might be just looking at {{ page.url }} and using some custom filter like this untested code:

eleventyConfnig.addFilter("faviconify", function (pageUrl) {
  const _favicon = (icon) => `/assets/image/favicon/${icon}.svg`;
  if (pageUrl === "/") return _favicon("homepage");
  if (pageUrl.startsWith("/blog/")) return _favicon("blog");
  if (pageUrl.startsWith("/project/")) return _favicon("project");
  ...
  return ""; // some default favicon slug here.
}

The above code is so repetitive you could almost put it in a loop (although you might need to rename "photo.svg" to plural "photos.svg" so it matches the directory name). Plus th…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@NING3739
Comment options

@pdehaan
Comment options

@NING3739
Comment options

Answer selected by NING3739
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants