-
Notifications
You must be signed in to change notification settings - Fork 207
Make image key configurable for thumbnails/images
#421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
minor refactoring in generator.rb
image key for thumbnails/imagesimage key configurable for thumbnails/images
- exchanged image.path and image defaults
|
Thanks for the PR! It's generally good hygiene to keep each PR narrowly focused. Would you mind pulling your refactor into a separate PR? Anything directly related to the image path change is fine to stay. |
|
OK, will do. |
|
Thank you! |
|
I hope we should be good to go now. |
parkr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! First pass of review.
README.md
Outdated
|
|
||
| * `image` - URL of an image that is representative of the post (can also be passed as `image.path`) | ||
| * `image` - URL of an image that is representative of the post. It can also be passed as `image.path` or set by the user. | ||
| To customize, go to your `_config.yml` and add the field `thumb_path_key: your.image.key`. Dots express nesting depth of the key. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean this to be all part of one list item in the unordered list? To create a new paragraph you'll need a blank line between. If intended, no problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lib/jekyll-feed/feed.xml
Outdated
| {% endif %} | ||
|
|
||
| {% assign post_image = post.image.path | default: post.image %} | ||
| {% assign thumb_key = site.data.thumb_key %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use the term "image" previously, not "thumb". Could you update this to "image_path_key" or "image_path_frontmatter_key"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, changing all ocurrences of "thumb" to "image" for consistency.
lib/jekyll-feed/feed.xml
Outdated
|
|
||
| {% assign post_image = post.image.path | default: post.image %} | ||
| {% assign thumb_key = site.data.thumb_key %} | ||
| {% capture key_parts %}{{ thumb_key }}{% endcapture %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key is already a string. Is the capture necessary? Couldn't it be split directly? I believe this is allowing the key to have liquid of its own which might be overkill.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right you are. It is a leftover of my tries to get the job done without having to split. Thought I could avoid the loop. Removed.
lib/jekyll-feed/generator.rb
Outdated
| Jekyll.logger.info "Jekyll Feed:", "Skipping feed generation in development" | ||
| return | ||
| end | ||
| site.data['image_key'] = get_image_key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this can be removed, is that right? I don't think we're using it in the feed.xml Liquid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently this is where I hand over the image key to feed.xml so it becomes available for retrieving the image path.
If we pulled the key from the config directly in Liquid, we could avoid adding code in ruby altogether. Without ruby involved though, I wouldn't know how to add the log line about using a custom path key.
lib/jekyll-feed/feed.xml
Outdated
| {% endif %} | ||
|
|
||
| {% assign post_image = post.image.path | default: post.image %} | ||
| {% assign image_key = site.data.image_key %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a site with site.data.image_key missing, will any of this fail? Perhaps we should consider adding a default: "image" here so that it always has an image_key. Then we can remove the default: post.image below on line 126.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wouldn't fail because site.data.image_key defaults to image.path which tries replicating the behavior we had before the change (if image.path is empty it tries post.image)
| Jekyll.logger.info "Jekyll Feed:", "Using custom image_path_key = #{image_path_key}" | ||
| end | ||
| return image_path_key | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with this -- I believe it can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As written above. Would you like me to try a liquid-only variant? It would be getting the key from the config posts_limit times then and we wouldn't have a log line, but it will definetely simplify things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep the log line - I think it's useful.
|
lib/jekyll-feed/feed.xml
Outdated
| {% assign image_key = site.image_path_key | default: "image.path" %} | ||
| {% assign key_array = image_key | split: "." %} | ||
|
|
||
| {% assign image_value = post %} | ||
| {% for key in key_array %} | ||
| {% assign image_value = image_value[key] %} | ||
| {% endfor %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just see that these lines could be moved above the "post" loop as they just need to be executed once which would make the code more efficient. On the other hand readability and cohesiveness would degrade, as the variable image_value is instantiated there but used somewhere else. Any opinions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The image_key and image_key_array could be pre-calculated above outside the loop to speed things up. The image_value would need to be calculated inside the loop to ensure it gets the right value for each post. I think the cleanest solution could be:
Outside the loop: if site.image_path_key is non-null, build key_array.
Inside the loop: if key_array is non-null, build image_value. Assign post_image as post_image = image_value | default: post.image.path | default: post.image
What do you think?
| Jekyll.logger.info "Jekyll Feed:", "Using custom image_path_key = #{image_path_key}" | ||
| end | ||
| return image_path_key | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep the log line - I think it's useful.
spec/jekyll-feed_spec.rb
Outdated
|
|
||
| image_key_tests.each do |test_case| | ||
| it "correctly processes image_key: '#{test_case[:thumbs]}'" do | ||
| site.data["image_key"] = test_case[:thumbs] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be image_path_key to pass?
lib/jekyll-feed/feed.xml
Outdated
| {% assign image_key = site.image_path_key | default: "image.path" %} | ||
| {% assign key_array = image_key | split: "." %} | ||
|
|
||
| {% assign image_value = post %} | ||
| {% for key in key_array %} | ||
| {% assign image_value = image_value[key] %} | ||
| {% endfor %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The image_key and image_key_array could be pre-calculated above outside the loop to speed things up. The image_value would need to be calculated inside the loop to ensure it gets the right value for each post. I think the cleanest solution could be:
Outside the loop: if site.image_path_key is non-null, build key_array.
Inside the loop: if key_array is non-null, build image_value. Assign post_image as post_image = image_value | default: post.image.path | default: post.image
What do you think?
Makes sense to me. What I can't get my head around right now (too tired) is how I should build the value outside the loop and prepend Will take another look at it tomorrow. |
spec: fix naming error image_path_key



Why this change?
Some people like me use themes where the
imagekey in a post's front matter is either already taken (e.g. for a banner image) or unused.I use (minimal mistakes) that has a different way of organizing a post's frontmatter with
header.teaser.This PR should solve the issue with a customizable key:
thumb_path_keycan be set in_config.ymland will point the liquid template to the correct thumbnail image path.This can help deduplicate front matter information.
What I touched
- I have reorganized the generator's code just a bit so its main routine looks shorter for readability.thumb_path_keyis evaluated and split to allow for higher nesting depths in the front matter likeheader.teaserStill this change keeps backwards compatibility due to default values for
imageandimage.path.Testing
feed.xml.rbpaths