2

I am new to Jekyll. I have a post with the following yml front matter:

---
layout: images-grid
title: Grid Sample
image: "/imgs/image1.jpg"
---

I would like to create .rb plugin that identifies all the posts with "layout = images-grid" and adds the height and the width of the image as a yaml metadata so the height and the width will be available to the liquid templates.

Is there any way to do this?

Naor
  • 23,465
  • 48
  • 152
  • 268

2 Answers2

0

could you not do something like this in your file?

{% if page.layout == images-grid %}
// do something
<img src="{{image}}" class="image-class"/>
{% endif %}
0

I'm looking for something similar (well not really similar, but the goal is the same, use a plugin to edit the front-matter of a post or posts).

So far the only option that I've found is to actually use the ruby File class to open and edit the file. So something like:

fileHandler = File.open("2013-11-23-post-title.html", "w+")

and then read in lines, editing/adding your new content to the front matter as necessary, i.e.:

fileHandler.puts "height: 480px\n width: 640px"

It would be nicer/ideal if the front-matter was available for manipulation as an attribute of the page or post object, but I don't think it is. I'm going to check the project page on github to see if there is already a feature request open for that.