更新时间:2023-02-26 12:56:41
听起来像图像URL相对可能是一个问题.
It sounds like this might be a problem with image URLs being relative.
问题
在这种情况下,假设您在localhost:8000/mypage.html
中生成了一个content/mypage.md
中的Markdown页面,并且该页面具有对图像的(有效)引用:
If this is the case, suppose you have a Markdown page in content/mypage.md
that is generated into localhost:8000/mypage.html
, and it has a (working) reference to an image:
![Alt text](content/myimage.png)
呈现到html中的
<img src="content/myimage.png" />
并指向localhost:8000/content/myimage.png
.但是,如果您随后尝试对类别页面将相同的Markdown处理为HTML,则会呈现相同的图像Markdown:
and points to localhost:8000/content/myimage.png
. However, if you then try and process that same Markdown into HTML for a categories page, it will render the same image markdown:
![Alt text](content/myimage.png)
插入相同的html:
<img src="content/myimage.png" />
,但是由于它位于localhost:8000/categories/mycategory.html
的类别"页面上,所以此相对图像URL现在指向localhost:8000/categories/content/myimage.png
,并且图像在类别"和标记"页面上已损坏.
but since this is on the categories page at localhost:8000/categories/mycategory.html
, this relative image URL now points to localhost:8000/categories/content/myimage.png
and the image is broken on categories and tags pages.
解决方案
解决方案很简单:一个/
.在Markdown中使用对图像的绝对引用,方法是在它们前面加上/
:而不是使用content/myimage.png
,而使用/content/myimage.png
:
The solution is simple: one /
. Use absolute references to images in your Markdown by prefixing them with a /
: instead of using content/myimage.png
, use /content/myimage.png
:
![Alt text](/content/myimage.png)
无论在哪个页面上,都将始终在localhost:8000/content/myimage.png
处渲染图像.
That will always render the image at localhost:8000/content/myimage.png
, regardless of what page it is on.