Search code examples
pythongithubpelican

CNAME file not being copied to root output when publishing Pelican blog


I am following Tip #2 from the Pelican documentation to utilize a custom domain on GitHub pages. For this to work correctly, the CNAME file needs to be at the root of my site.

From the doc:

To use a custom domain with GitHub Pages, you need to put the domain of your site inside a CNAME file at the root of your site. To do this, create the content/extra/ directory and add a CNAME file to it. Then use the STATIC_PATHS setting to tell Pelican to copy this file to your output directory. For example:

STATIC_PATHS = ['images', 'extra/CNAME']
EXTRA_PATH_METADATA = {'extra/CNAME': {'path': 'CNAME'},}

I have done this. My pelicanconf.py has the following two settings:

STATIC_PATHS = ['images', 'extra/CNAME']
EXTRA_PATH_METADATA = {'extra/CNAME': {'path': 'CNAME'},}

I have created my CNAME file and placed it in content/extra/CNAME, as described in the documentation.

I publish the application like this:

pelican content --output output --settings pelicanconf.py

This generates my site in the output directory. The pages are all set up correctly. However, CNAME is not at the root. Instead it is at the extra/CNAME location.

I receive no errors or warnings when publishing. If I publish with the --debug parameter, this line appears in the output:

-> Copying H:\mysite\content\extra\CNAME to extra/CNAME

This clearly shows that it's copying it to extra instead of the root. According to the documentation, I've set my STATIC_PATHS and EXTRA_PATH_METADATA correctly to copy this to the root. How do I change my settings so that CNAME is copied to the correct location instead of the extra directory?


Solution

  • maggick was correct in his assessment in the comments.

    Could this be a Windows related problem?

    There is one tiny mention in the basic settings overview

    Extra metadata dictionaries keyed by relative path. Relative paths require correct OS-specific directory separators (i.e. / in UNIX and \ in Windows) unlike some other Pelican file settings. See Path metadata.

    (emphasis is mine)

    This tidbit of information isn't mentioned in the Path metadata documentation or in the tips, both of which I'd been utilizing.

    My solution, since I am running this on Windows, is to change:

    EXTRA_PATH_METADATA = {'extra/CNAME': {'path': 'CNAME'},}
    

    to:

    EXTRA_PATH_METADATA = {'extra\CNAME': {'path': 'CNAME'},}
                                 ^ This is OS specific
    

    Notice the single changed slash in the dictionary key.