In which folder should I put my static files in Jekyll?

While I'm watching a document. 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 

When do I need to include an image inside my message. Where should I put the image to use the site.static_files function mentioned here (section of static files in the documentation)? So I can use a variable like file.path and file.modified_time directly.

Previously, when I used Jekyll 2.x, I did something like below, creating my own resource directory.

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

enter image description here

+6
source share
2 answers

Assuming you have your gallery images in a structure like

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

You can access them in the collection or on the page as follows:

 {% 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 %} 

This goes through all the static files and checks for a specific path ( img/gallery in this example).

Than access to metadata of a static file for this file. (I called it an “image” in this example, but you can call it whatever you want after the for keyword).

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

+6
source

A static file can be placed anywhere in the site directory, which is not a collection. Therefore, not in the directory that begins with "_". What makes it static is the fact that it does not have a front-end YAML.

Id recommends creating a directory with the name "assets" or "images" and placing them there.

edit:

What are you trying to use this feature for?

+4
source

All Articles