Set categories on post if they appear in site frontmatter defaults#2373
Conversation
|
/cc @maul-esel |
|
Hey guys, just dropping in to check on this. Any thoughts/feedback? |
lib/jekyll/utils.rb
Outdated
There was a problem hiding this comment.
Why not value_from_singular_key(hash, singular_key) || value_from_plural_key(hash, plural_key)?
|
Unfortunately, that won't work because The way that I interpreted the description for I could update the code for I will defer to you guys as far as the coding style, though. Let me know what you prefer :) |
|
For clarity, I've added a diff of what changes could be made to support a one-liner. I've also cleaned up the diff --git a/lib/jekyll/utils.rb b/lib/jekyll/utils.rb
index 6dab612..e1b4704 100644
--- a/lib/jekyll/utils.rb
+++ b/lib/jekyll/utils.rb
@@ -35,14 +35,13 @@ module Jekyll
#
# Returns an array
def pluralized_array_from_hash(hash, singular_key, plural_key)
- array = []
- array << value_from_singular_key(hash, singular_key)
- array << value_from_plural_key(hash, plural_key) if array.flatten.compact.empty?
- array.flatten.compact
+ [].tap do |array|
+ array << (value_from_singular_key(hash, singular_key) || value_from_plural_key(hash, plural_key))
+ end.flatten.compact
end
def value_from_singular_key(hash, key)
- [hash[key]] if hash.has_key?(key) || (hash.default_proc && hash[key])
+ hash[key] if (hash.has_key?(key) || (hash.default_proc && hash[key]))
end
def value_from_plural_key(hash, key) |
|
Thanks for looking into it. Kind of wish |
|
After thinking about this more, I agree that |
|
👍 😄 |
…lar_key` per suggestion from @parkr Switched to using the `#tap` method for more concise code. Also returning the value from `value_from_singular_key` instead of returning an array wrapped presentation of the value. This allows for a one-liner in `pluralized_array_from_hash`.
|
Cool, this looks good to me. Think we should update the documentation? Anything you can see in the configuration.md file that looks wrong to you? |
|
I don't see anything that looks wrong. In the section about Front-matter defaults, it's not really mentioned that you can set the |
|
Maybe you can add a note about the cascade? |
|
Will do. I'll push that sometime tomorrow. |
|
Awesome, thanks! We're trying to make sure |
|
If you wouldn't mind following up with some docs, that'd be ⭐! |
This pull request is the result of a discussion on #2343.
If category or categories were set in the site frontmatter defaults, they were not being picked up by the post when the site was being built. This was preventing the proper subdirectories from being built.