如何在 github 上托管的 jekyll 项目中包含图像?

How to include images in a jekyll project hosted on github?

我正在使用 jekyll 构建博客并使用 gh-pages 在 github 上托管它。我的项目的根目录如下所示:

├── LICENSE
├── README.md
├── _config.yml
├── _img
│   ├── 2016-09-09\ 14.48.20.png
│   └── 2016-09-09\ 15.25.09.png
.
.
.
├── _posts
│   ├── 2016-09-08-seven-weeks-before-applying-to-devops-job.markdown
│   └── 2016-09-09-an-hour-with-ansible.md
.
.
.
├── _site
│   ├── 2016
│   │   └── 09
│   │       ├── 08
│   │       │   └── seven-weeks-before-applying-to-devops-job.html
│   │       └── 09
│   │           └── an-hour-with-ansible.html
│   ├── LICENSE
│   ├── README.md
│   ├── about
│   │   └── index.html
│   ├── css
│   │   └── main.css
│   ├── feed.xml
│   └── index.html
├── about.md
├── css
│   └── main.scss
├── feed.xml
└── index.html

文档给出了以下示例:

Because of Jekyll’s flexibility, there are many solutions to how to do this. One common solution is to create a folder in the root of the project directory called something like assets or downloads, into which any images, downloads or other resources are placed. Then, from within any post, they can be linked to using the site’s root as the path for the asset to include. Again, this will depend on the way your site’s (sub)domain and path are configured, but here are some examples (in Markdown) of how you could do this using the site.url variable in a post.

在 post 中包含图像资源:

... which is shown in the screenshot below:
![My helpful screenshot]({{ site.url }}/assets/screenshot.jpg)

我已经尝试了几种不同的方法,但是一旦我向上推 gh-pages 都没有用:

![]({{ site.github.url }}/_img/2016-09-09 14.48.20.png)

![]({{ site.url }}/_img/2016-09-09 15.25.09.png)

我还尝试 "keeping" _img 目录,方法是将以下内容放入我的 _config.yaml

# Build settings
markdown: kramdown

keep_files: ["_img"]

但这也行不通。那么如何在 github 上托管的 jeykll 项目中包含图像?

感谢您的帮助:)

所有以下划线开头的文件夹都不会复制到构建目标。最常见的存储图像的方法是将它们添加到 assets/img 文件夹中。 如果你想使用 _img 你必须添加到你的 _config.yml:

include:
  - "_img"
  • 为你的图片创建一个文件夹,你可以随意命名(我的是"images")
  • 找到要包含在 post 中的图片的图片地址 (您可以通过转到您的文件夹图片并右键单击您的图片,然后复制图片地址来做到这一点)
  • 现在您在 post 中使用该地址没有任何问题。