发布 Pelican 博客时 CNAME 文件未复制到根输出

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

我正在关注 Pelican 文档中的 Tip #2,以便在 GitHub 页面上使用自定义域。为了使其正常工作,CNAME 文件需要位于我网站的根目录中。

来自文档:

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'},}

我已经做到了。我的 pelicanconf.py 有以下两个设置:

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

我已经创建了 CNAME 文件并将其放在 content/extra/CNAME 中,如文档中所述。

我这样发布应用:

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

这会在 output 目录中生成我的站点。页面都设置正确。但是,CNAME 不在根目录中。相反,它位于 extra/CNAME 位置。

我在发布时没有收到任何错误或警告。如果我使用 --debug 参数发布,则此行会出现在输出中:

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

这清楚地表明它正在将其复制到 extra 而不是根目录。根据文档,我已正确设置 STATIC_PATHSEXTRA_PATH_METADATA 以将其复制到根目录。如何更改我的设置以便将 CNAME 复制到正确的位置而不是 extra 目录?

在评论中的评价是正确的。

Could this be a Windows related problem?

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.

(重点是我的)

我一直在使用的 Path metadata documentation or in the tips 中没有提到这些信息。

我的解决方案,因为我是 运行 这个 Windows,就是改变:

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

至:

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

注意字典键中的单个更改的斜杠。

这种行为很奇怪。文档清楚地提到即使在 windows 中你也需要使用正斜杠。

来自 readthedocs Pelican 3.6.4 - 最新版本

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

注意:使用正斜杠 /,即使在 Windows 上也是如此。 但是这个解决方案有效。