为什么我的网页上指定了图片地址(img src),但图片没有显示出来?

huangapple go评论73阅读模式
英文:

Why is my image specified by img src not shown on my webpage?

问题

我正在为我的个人网站(使用hugo academics by wowchemy搭建)设置页面,以下是我其中一个文件夹的结构:

.
├── ABF.md
├── EXE.md
├── Figures
│   ├── sampling.gif
│   └── sampling_compressed.gif
├── HREMD.md
├── MetaD.md
├── REUS.md
├── TREMD.md
├── US.md
├── _index.md
├── alchemical_MetaD.md
├── appendix.md
├── intro.md
└── test.gif

_index.md 文件中,我有以下代码来读取一个GIF文件:

<center>
<img src="Figures/sampling_compressed.gif">
</center>

在与 _index.md 文件位于同一文件夹下的 intro.md 文件中,我也有同样的代码来读取相同的GIF文件。然而,在localhost上,GIF文件能够显示在由 _index.md 创建的页面上,但却不能显示在由 intro.md 创建的页面上。我该如何解决这个问题,为什么会发生这种情况?提前感谢您的帮助!

英文:

I'm setting up pages on my personal website(hugo academics by wowchemy) and here is the structure of one of the folders I have:

.
├── ABF.md
├── EXE.md
├── Figures
│   ├── sampling.gif
│   └── sampling_compressed.gif
├── HREMD.md
├── MetaD.md
├── REUS.md
├── TREMD.md
├── US.md
├── _index.md
├── alchemical_MetaD.md
├── appendix.md
├── intro.md
└── test.gif

In _index.md, I have the following lines to read in a GIF file:

&lt;center&gt;
&lt;img src=&quot;Figures/sampling_compressed.gif&quot;&gt;
&lt;/center&gt;

In intro.md, which is in the same folder as _index.md, I also have the same lines to read in the same GIF file. However, in localhost, the GIF file is shown in the page made by _index.md, but not the one built by intro.md. How can I solve the problem and why is this happening? Thanks in advance!

答案1

得分: 1

你对输出结构的假设是错误的。Hugo在你的文件夹根目录下构建了_index.md,而intro.md文件(在使用pretty URL时)被构建在一个子文件夹中:intro/index.html

话虽如此...我测试了你的设置,发现Section目录中的图片(该目录下有一个_index.md文件)默认情况下不会被处理。我会将图片移动到static目录,这样你可以在任何文件中通过绝对路径引用它,特别是因为这张图片不仅仅属于一个页面。

如果它只会被一个页面使用,你可以将intro.md改为intro/index.md,将该目录创建为一个Page bundle,在其中放置你的图片,并使用resources变量引用它。

英文:

Your assumptions about the output structure are wrong. Hugo builds _index.md in the root of you folder, while the intro.md file (when processed with pretty URL's) is built in a subfolder: intro/index.html.

That being said... I tested your setup and an image in a Section directory (which is a directory with an _index.md file) is not processed by default. I would solve this by moving the image to the static directory so you can reference it from any file in the same way (with an absolute path), especially because this image does not belong to just one page.

If it WERE to be used by just one page, you could have turned the intro.md into intro/index.md and make that directory a Page bundle in which you could put your image and reference it by using the resources variable.

huangapple
  • 本文由 发表于 2023年2月14日 04:23:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/75440821.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定