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

mbi*_*ras 4 github jekyll github-flavored-markdown

我正在使用 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
Run Code Online (Sandbox Code Playgroud)

文档给出了以下示例:

由于 Jekyll 的灵活性,有很多解决方案可以做到这一点。一种常见的解决方案是在项目目录的根目录中创建一个名为assets或的文件夹downloads,其中放置任何图像、下载或其他资源。然后,从任何帖子中,它们可以链接到使用站点的根目录作为要包含的资产的路径。同样,这将取决于您站点(子)域和路径的配置方式,但这里有一些示例(在 Markdown 中)说明您如何使用site.url帖子中的变量执行此操作。

在帖子中包含图像资产:

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

我尝试了几种不同的方法,但是一旦我gh-pages向上推,就不起作用:

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

![]({{ site.url }}/_img/2016-09-09 15.25.09.png)
Run Code Online (Sandbox Code Playgroud)

我还尝试_img通过将以下内容放在我的目录中来“保留”目录_config.yaml

# Build settings
markdown: kramdown

keep_files: ["_img"]
Run Code Online (Sandbox Code Playgroud)

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

谢谢你的帮助 :)

Dir*_*tyF 9

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

include:
  - "_img"
Run Code Online (Sandbox Code Playgroud)