如何在由 Jekyll 提供支持的博客上的帖子中显示图像?

问题描述 投票:0回答:5

我正在尝试遵循 Jekyll 文档,但卡在如何显示图像上。我尝试了以下 Markdown:

---
layout: post
title:  "My first post!"
date:   2016-10-20 16:17:57 +0200
categories: jekyll update
regenerate: true
---

This is in the `_posts` directory.
It can be edited then rebuild the site to see the changes.
You can rebuild the site in many different ways, but the most common way is to run `jekyll serve`, which launches a web server and auto-regenerates your site when a file is updated.

![name of the image][{{site.url}}/assets/P6740674.JPG]

如何让图像出现在渲染后的帖子中?

image jekyll
5个回答
53
投票

如果您想使用

site.url
,您必须将
url
变量添加到您的
_config.yml
文件中。更多信息请参见 Jekyll 文档

但是您可能根本不需要使用

site.url
。任何以
/
斜杠开头的网址都将相对于您域的顶层。所以你可以这样做:

![image tooltip here](/assets/image.jpg)

10
投票

我可以看到默认情况下在

images
下创建了一个
assets
目录。我放置了如下图像。

assets/images/myimage.jpg
并在帖子中添加以下行。

![My image Name](/assets/images/myimage.jpg)

运行

bundle exec jekyll serve
看看是否有错误。如果您提到文件位置不匹配,您将在此处看到错误。


4
投票

这里的问题很烦人,很简单 - 您的图像链接格式错误。

应该是

![name](link)
。你有
![name][link]
。注意括号中的区别。其他都还好。


1
投票

我知道这是一个老问题,但我花了大约 15 分钟来解决这个问题(jekyll/github 博客是我的第二博客)。所以在这里添加一个建议。

简单地说,按照 Kevin 建议,将图像文件添加到根目录下的路径中,并给出该文件的路径。确保文件/目录正在被跟踪;不是.gitignored。

我的资产目录位于 _site 目录内。但是,当我在该路径下添加新图像时,git status 并未将其显示为新添加的 - .gitignore 忽略了 _site 目录。所以凯文的建议并没有发挥作用。但根据他的建议,我推断文档是我网站的根目录,如果我在那里添加一个图像目录并在该目录下添加图像,那么就像

![image description](/images/my_image.png)

应该可以。它是这样运作的。不确定这是否是最好的方法。如果您有类似的配置,请在此分享。


0
投票

就我而言,我忘记将图像推送到远程,因此图像没有显示。只是为了记住这一点。

© www.soinside.com 2019 - 2024. All rights reserved.