How to add a favicon to a Pelican blog?
Asked Answered
E

4

24

I am creating a static site with Pelican and I'm confused about how to add a favicon to it.

I've seen in the documentation that:

You can also use the EXTRA_PATH_METADATA mechanism to place a favicon.ico or robots.txt at the root of any site.

I don't know where to put my favicon.ico file and what to specify in the EXTRA_PATH_METADATA setting (if this is really the setting that should be used).

Episcopalian answered 7/7, 2015 at 13:46 Comment(0)
D
40

In my pelicanconf.py, I have:

STATIC_PATHS = [
    'images',
    'extra',  # this
]
EXTRA_PATH_METADATA = {
    'extra/custom.css': {'path': 'custom.css'},
    'extra/robots.txt': {'path': 'robots.txt'},
    'extra/favicon.ico': {'path': 'favicon.ico'},  # and this
    'extra/CNAME': {'path': 'CNAME'},
    'extra/LICENSE': {'path': 'LICENSE'},
    'extra/README': {'path': 'README'},
}

The structure for these extra files is then:

/content
    /extra
        favicon.ico
        robots.txt

See the documentation, which shows a similar layout.

Doriadorian answered 7/7, 2015 at 13:50 Comment(7)
For some reason it doesn't work. I'm testing my blog locally, using python -m SimpleHTTPServer. Could this be the problem?Episcopalian
@PauloMiraMor could you be more specific that "doesn't work"? Are you seeing HTTP errors for the attempt to GET favicon.ico? Can you look in the output directory, does it get put in the right place?Doriadorian
It is not in the output at all. When I reload the page ther is no favicon.Episcopalian
@PauloMiraMor how are you rebuilding the site?Doriadorian
Using pelican content -s pelicanconf.pyEpiscopalian
@PauloMiraMor and favicon.ico is definitely in /content/extra? If so, I'm not sure why it isn't working, unless you have other STATIC_PATHS and EXTRA_PATH_METADATAs shadowing the ones you meant to use. I suggest you create a minimal example and ask a new question.Doriadorian
That was the problem. I had another STATIC_PATHS in my pelicanconf.py. Thanks.Episcopalian
A
4

The official way @jonrsharpe described doesn't work for my page. I don't know why, it should.

I decided to put the favicon.ico in the image folder and to insert a link in base.html to get it work:

<link rel="shortcut icon" href="{{ SITEURL }}/images/favicon.ico?v=2" />
Affricative answered 27/10, 2017 at 6:30 Comment(0)
R
0

I used the technique outlined on the Pelican Wiki: https://github.com/getpelican/pelican/wiki/Tips-n-Tricks#copying-faviconrobotstxt

Repeating here in case that page disappears:

  • create a directory beside your content dir, and put all your favicon items there.
  • in your Makefile, add if test -d $(BASEDIR)/extra; then cp $(BASEDIR)/extra/* $(OUTPUTDIR)/; fi to any spots that build the site (ex publish, html, etc)

Now when you build the site, everything in extra/ will get copied to the root of /output.

Runofthemine answered 1/4, 2018 at 0:9 Comment(0)
S
0

I couldn't see the favicon while working on my site locally. As it turns out, I had to access http://127.0.0.1:8000 instead of using the local DNS http://localhost:8000. The former worked.

Supranatural answered 25/2 at 21:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.