我应该将静态文件放在哪个文件夹中? [英] Which folder should I put my static files in Jekyll?

查看:158
本文介绍了我应该将静态文件放在哪个文件夹中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查找文档.我看到了以下文档结构,

While I am looking the doc. I saw the following document structure,

.
├── _config.yml
├── _drafts
|   ├── begin-with-the-crazy-ideas.textile
|   └── on-simplicity-in-technology.markdown
├── _includes
|   ├── footer.html
|   └── header.html
├── _layouts
|   ├── default.html
|   └── post.html
├── _posts
|   ├── 2007-10-29-why-every-programmer-should-play-nethack.textile
|   └── 2009-04-26-barcamp-boston-4-roundup.textile
├── _data
|   └── members.yml
├── _site
├── .jekyll-metadata
└── index.html

当我需要在帖子中添加图片时.我应该在哪里使用图像来使用此处提到的site.static_files功能(静态文件"部分在文档中)?这样我就可以直接使用file.pathfile.modified_time之类的变量.

When I need to include an image inside my post. Where should I put the image to use the feature of site.static_files mentioned here (Static Files Section in the Documentation)? So that I can use variable like file.path and file.modified_time directly.

以前,当我使用Jekyll 2.x时,我通过创建自己的资产目录来进行如下操作.

Previously when I was using Jekyll 2.x, I was doing something like below by creating my own asset directory.

<link rel="stylesheet" href="{{ "/assets/css/index.css" | prepend: site.url }}">

推荐答案

假设您的图片库结构类似

Assuming you have your gallery images in a structure like

-img
  -gallery
    -image1.png
    -image2.png
    etc.

您可以像这样在集合或页面中访问它们:

you can access them in a collection or page like this:

{% for image in site.static_files %}
{% if image.path contains 'img/gallery' %}
    <p>{{image.path}} - {{image.modified_time}}</p>
    <img src="{{site.baseurl}}{{image.path}}">
{% endif %}
{% endfor %}

这将遍历所有静态文件并检查特定路径(在此示例中为img/gallery).

This goes through all static files and check for a certain path (img/gallery in this example).

然后您可以访问该文件的静态文件元数据. (在此示例中,我将其命名为图片",但您可以在for关键字之后随意命名).

Than you can access the static file metadata for that file. (I named it 'image' in this example but you can name it whatever you want after the for keyword).

我认为将这样的内容放在博客文章中,而不是放在pagecollection中是没有太大意义的.

I think it doesn't make too much sense to put something like this in a blog post but rather in a page or a collection.

这篇关于我应该将静态文件放在哪个文件夹中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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