为了让Pelican生成的html链接到图像,表达路径的正确方法是什么? [英] What is the correct way to express a path in order to get Pelican generated html to link to an image?

查看:112
本文介绍了为了让Pelican生成的html链接到图像,表达路径的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始与Pelican创建一个博客,并希望链接到一个图像。我通过在我的Markdown文件中包含以下行来做到这一点:

 < img src =./ myImg1a.pngalt =./ myImg.pngstyle =width:750px; height:800px;/> 

该行已成功复制到html文件中,该文件位于输出目录(即 / myBlog /输出)。我将png文件放在输出目录(即与html文件相同的目录中,并且出现以下错误:

 警告: root:无法找到文件/category/myImg1a.png/index.html或变体

其中 / category 是指 myBlog / output / category 当我使用下面的html代码时:

 < img src =/ myImg1a.pngalt =/ myImg.pngstyle =width:750px; height:800px;/> 

一切正常,我不明白为什么应该这样:


  1. 如果图像文件与html文件位于同一目录中,./myImg1.png不正确,/myImg.png不正确?


  2. 为什么要寻找文件夹 /category/myImg1a.png/index.html



解决方案

首先,按设计,您不应更改内容输出直接/手动。

您应该将所有静态内容放在单独的目录中,通常命名为 images 路径。然后,将 pelicanconf.py 中的路径配置为:

 #... 
PATH ='content'
STATIC_PATHS = ['images','files']#添加任意号码。的地点
#...

在这种情况下,当Pelican构建实际页面时,它会查找 ./ content / images ./ content / files 位置中的任何引用静态文件。如果找不到,它会发出错误信息。



现在,回答您的问题...



By,

  ... src =./ myImg1a.png... 

Pelican 寻找这个 myImg1a.png 文件存在于 myBlog / content / 文件夹中,因为您提及 ./ 这是 Pelican 正在处理的根文件夹。



但是,当您将它称为 p>

  ... src =/ myImg1a.png... 

Pelican 最终会在 html 文件的目录中找到它。通过获取 / 作为位置, Pelican 正在您的 myblog的相同目录中查找/my-blog-post/index.html myblog / my-blog-post /

因此,加工。但不是理想的方式。



为了更深入了解,请查看Pelican的文档 on this matter



  1. 为什么要找到文件夹/category/myImg1a.png/index.html?


Pelican ,这里只是为了聪明。


I'm just starting to create a blog with Pelican and wanted to link to an image. I did this by including the following line in my Markdown file:

<img src="./myImg1a.png" alt="./myImg.png" style="width: 750px; height: 800px;"/>

This line was successfully reproduced in the html file, which Pelican placed in the output directory (i.e. /myBlog/output). I placed the png files in the output directory (i.e. the same directory as the html files and got the following error:

WARNING:root:Unable to find file /category/myImg1a.png/index.html or variations. 

where /category refers to myBlog/output/category. When I, instead, used the following html code:

<img src="/myImg1a.png" alt="/myImg.png" style="width: 750px; height: 800px;"/>

everything worked fine. I don't understand why this should be:

  1. If the image file is in the same directory as the html file, shouldn't "./myImg1.png" be correct and "/myImg.png" be incorrect?

  2. Why was the folder /category/myImg1a.png/index.html being sought at all?

解决方案

First of all, by design, you should not change the contents of the output directly/manually.
You should put all your static contents in separate directory which is usually named as images or paths. And, then configure the path(s) in pelicanconf.py as:

# ...
PATH = 'content'
STATIC_PATHS = ['images', 'files']  # add any no. of locations
# ...

In that case, when Pelican is building actual page, it will look for any referenced static file in ./content/images and ./content/files locations. If cannot find there, it will emit the error message.

Now, answering to your trouble ...

By,

... src="./myImg1a.png" ...

Pelican look for this myImg1a.png file in your myBlog/content/ folder as you are mentioning ./ which is the root folder for Pelican is working on.

But, when you are referring it as

... src="/myImg1a.png" ...

Pelican eventually finds it in the html file's directory. By getting / as location, Pelican is looking for it in the same directory of your myblog/my-blog-post/index.html which is myblog/my-blog-post/.
Hence, working. But not in the ideal way.

For a deeper understanding, please take a look into Pelican's documentation on this matter.

  1. Why was the folder /category/myImg1a.png/index.html being sought at all?

Pelican, here, just trying to be smart.

这篇关于为了让Pelican生成的html链接到图像,表达路径的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆