Search code examples
pythonfaviconpelican

How to add a favicon to a Pelican blog?


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).


Solution

  • 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.