Skip to content
This repository has been archived by the owner on Mar 31, 2021. It is now read-only.

favicon #7

Open
jdaudier opened this issue Jul 12, 2014 · 3 comments
Open

favicon #7

jdaudier opened this issue Jul 12, 2014 · 3 comments

Comments

@jdaudier
Copy link

Is there a way to add this link to the header when you run hexo generate?

@montanaflynn
Copy link

You could add the favicon link to the template manually. Here's how:

In the file hexo/themes/casper/layout/casper/head.ejs just above line 32 we can add a new block to check for a favicon and add the html link if it's found. This example is assuming your favicon is a png, otherwise modify the link as necessary.

<% if (config.favicon) { %>
<link rel="icon" type="image/png" href="<%- config.favicon %>" />
<% } %>

in hexo/_config.yml add a line to define your favicon like this:

favicon: //path-or-url/to/favicon.png

Voila!

@montanaflynn
Copy link

There is also a built-in favicon_tag helper available from hexo core but it only works for .ico favicons.

This updated code works for .ico, .png and .gif formats:

<% if (config.favicon) { %>
  <% var faviconFileType = config.favicon.split('.').pop() %>
  <% if (faviconFileType == "ico") { %> 
    <link rel="icon" type="image/x-icon" href="<%- config.favicon %>" />
  <% } else { %>
    <link rel="icon" type="image/<%- faviconFileType %>" href="<%- config.favicon %>" />
  <% } %>
<% } %>

@ricardogouveia3
Copy link

Hi guys. I'm trying to put a favicon and tested these 2 solutions:

First one had no effect to me.
Second just broke everything. And don't worked.

I've heard about hexo was updated no long ago. Does that changes affect these methods?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants