Support subdirectories for posts with additional resources #881

rgov opened this Issue Mar 25, 2013 · 20 comments


None yet

It'd be nice to be able to have a _posts structure that supports posts with their own directories of resources, such as photos or CSS.


I investigated creating a custom Generator plugin, but this does not seem practical because the Post class makes assumptions about the directory structure.

Jekyll member

I'll need to talk to @mojombo about this. It adds a level of complexity he may wish to avoid.


I would like to see this.


This would be very nice to have. A lot cleaner than my current solution of creating post specific folders manually under /images. 👍


It seems like keeping small files near the page (or post in this case) in which they finally appear is a nice way to organize things.

Jekyll member

I would propose to:

  1. name index.markdown not post.markdown in originally proposed structure
  2. support alternative structure (in addition to the one already shown):

@ixti I think the original structure is better, with a inside the folder being picked up as the post, as opposed to having a folder and a file at root level (if you want to rename, you need to rename both, etc).


I agree with @goldfeld

Jekyll member

From my experience it’s not possible to tell: “this resource belongs forever to that post only”. One day you get older and decide to write a post with a selection of photos from previous posts. People collects things, it’s how we think. So now your great subdirectory work flow is broken, because you don’t really want to copy the existent photos into your new post’s subdirectory.

If this feature is added to Jekyll, next thing to change would be the include and exclude feature. And so on. What you try to do is topic based information architecture.

But it doesn’t scale well, because human change their mind and tend to use more dimensions to review thing in the past.

I estimate the proposal as hard to maintain and I would say no to it.

Jekyll member

It is possible to do it properly and have image content be directly related to the rest of the content on a post or page, but I agree with @penibelst that the chances of getting very disorganized increase ever higher once you get to scale.

Besides complicating the simple flat post file list, this would modify the convention for defining where the formatted text lives, and create inconsistency when creating new posts or pages.


@penibeist Admittedly there is the potential for things to become complicated as time progresses, but the alternative is to have no post scope resource organization at all and I don't think that is the better option. Not all use cases would require cross-references between posts.


I agree with #881 (comment) and also say - the more code involved in any software application, the grater the propensity for bugs and issues. The proposed "sub-sub-directory" asset folder can't fail if it isn't an existing feature to start with.

More effort should be put into a cool commenting system that isn't so h4x07 that the commenter has to clone a repo just to comment each time, and I use Disqus, but I find it teriibly bloated and laggy. I've started working on something, but I digress. We're talking about post-post-asset folders

It's just my opinion, of course, but I tend to stray away from embedding of video and audio a lot of the time - especially Flash based. So usually the only media I'd have included in blog posts would be pictures. I can't help but think, why not just encode them as Base64 or self-host them in Dropbox, Imgur or Droplr?


P.s. what if these "special posts" were actually called something else... like Exposes, or Special Reports. Promos - and each. I like how Scriptogram does it; simply parses either posts or pages, and nothing more as I wrote about as it started to make sense how these partials and Tom Selleck's mustache worked. Last year around this time, I had no clue. Funny how that works.

Jekyll member

but the alternative is to have no post scope resource organization at all

@rgov You are already able to organize your assets post driven:




I understand your natural desire not to write the whole path to the resource. I see an include as a solution.

{% include img.html param='dr-jekyll-brings-medicine.jpg' %}

The include img.html just concatenate the 3 strings: assets, post’s file name (is it exposed to liquid?), include.param. Done.

Jekyll member

@penibelst presents a really neat idea here, and definitely the preferred way to do this. Jekyll is not about the magic, but about is stupid simplicity. A feature like this diminishes the simplicity, and if it can be done (quite well, I might add) as described above, then no need for Jekyll to fake things out.

To get the filename, you'd need to do a bit of transformation:

{{ post.path | split:"/" | last | split:"." | first }}

From your post or page, do the following:

{% include img.html name='dr-jekyll-brings-medicine.jpg' %}

Then in img.html, you'd do something like this:

{% capture namespace %}{{ post.path | split:"/" | last | split:"." | first }}{% endcapture %}
<img src="/assets/{{ namespace }}/{{ }}">

Boom. 👏 @penibelst.


Nice. That could easily be made into a Jekyll plugin if you prefer a more specific tag name.

I think a soft post/asset connection like this one is preferable. Enforcing or encouraging the binding of assets to posts is a quick way to increase complexity on small to mid-sized sites.


I am satisfied with @penibelst and @parkr's solution to this style of organization for now. Sometimes the solution isn't obvious 👍

Jekyll member

One thing I would say should come out of this conversation is the addition of or something that is just YYYY-MM-DD-post-slug.


I've written a plugin (as @robwierzbowski suggested) to help with asset organisation:

{% asset_path my-image.png %}

in post 2013-01-01-post-title would output:


in page my-first-page would output:

Jekyll member

@samrayner Thanks for writing this plugin! If you want to submit a pull request against the site docs (they're in the site directory on master) to add your plugin to the plugin list, we'll gladly merge it. Thanks! ❤️

That being said, I'm going to close this issue. There are several other solutions available and I don't foresee us adding this particular feature to Jekyll's core in the future.

@mattr- mattr- closed this Oct 29, 2013
@parkr parkr pushed a commit that referenced this issue Nov 5, 2013
@samrayner samrayner Add Asset Path Tag to plugin list in docs
Requested by @mattr-
#881 (comment)

I wonder if it would be well received if I open a new issue on this topic, but at least I can point to a comment I made on StackOverflow… ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment