通过“类别”查看文章时,Pelican 图像链接断开

uho*_*hoh 4 python pelican

我确定我遗漏了一些明显的东西。我通过内容文件夹内的文件夹名称定义类别。如果我content在查看页面时单击,我会看到文件夹名称(例如,categ1、categ2)加上“misc”,这很好。当我单击 categ1 时,我会看到一篇完整的文章,但图像链接现在都已损坏。

localhost:8000/category/categ1.html
Run Code Online (Sandbox Code Playgroud)

我希望看到的只是该类别中可点击的文章列表。或者至少,没有断开的链接。

(如果我尝试使用标签,我有类似的行为,但一次只做一件事......)

.rst文件中没有类别行。

除了名称、时区等。我在我的配置中使用这些。

更新:图像位于内容的图像文件夹中。我还在categ1 中放了一个Images 文件夹的副本,但没有帮助。

THEME = 'nmnlist' 

PATH = 'content'

# ARTICLE_PATHS = ['articles']    # have tried this also

STATIC_PATHS = ['images', 'pdfs']

RELATIVE_URLS = True  # have tried False also

PLUGINS = ["render_math"]
Run Code Online (Sandbox Code Playgroud)

cha*_*id1 6

听起来这可能是图像 URL 相对的问题。

问题

如果是这种情况,假设您有一个 Markdown 页面content/mypage.md生成到 中localhost:8000/mypage.html,并且它具有对图像的(工作)引用:

![Alt text](content/myimage.png)
Run Code Online (Sandbox Code Playgroud)

它被渲染到 html 中:

<img src="content/myimage.png" />
Run Code Online (Sandbox Code Playgroud)

并指向localhost:8000/content/myimage.png。但是,如果您随后尝试将相同的 Markdown 处理为类别页面的 HTML,它将呈现相同的图像 Markdown:

![Alt text](content/myimage.png)
Run Code Online (Sandbox Code Playgroud)

进入同一个html:

<img src="content/myimage.png" />
Run Code Online (Sandbox Code Playgroud)

但由于这是在类别页面上localhost:8000/categories/mycategory.html,因此此相对图像 URL 现在指向localhost:8000/categories/content/myimage.png并且图像在类别和标签页面上已损坏。

解决方案

解决办法很简单:一/。通过在 Markdown 中使用对图像的绝对引用,在它们前面加上/: 而不是 using content/myimage.png,而是使用/content/myimage.png

![Alt text](/content/myimage.png)
Run Code Online (Sandbox Code Playgroud)

localhost:8000/content/myimage.png无论它在哪个页面上,这将始终在 处呈现图像。