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
Throw a warning if a layout does not exist #2620
Conversation
Throw a warning if a non-"none" layout is specified but the corresponding layout file does not exist.
|
||
if !data["layout"].nil? && data["layout"] != "none" && layout.nil? | ||
Jekyll.logger.warn("Build Warning:", "Layout #{data["layout"]} does not exist.") | ||
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.
This is all very complicated. Can you put it in a method which encapsulates this? 🐸
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.
Sure. It also seems the Travis build failed because some docs don't have a data
variable; I'll fix that as well.
@@ -163,6 +172,9 @@ def place_in_layout? | |||
def render_all_layouts(layouts, payload, info) | |||
# recursively render layouts | |||
layout = layouts[data["layout"]] | |||
|
|||
Jekyll.logger.warn("Build Warning:", "Layout #{data["layout"]} does not exist.") if invalid_layout? layout |
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 should also mention in which file the layout is being called.
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.
Done!
# | ||
# Returns true if the layout is invalid, false if otherwise | ||
def invalid_layout?(layout) | ||
!data["layout"].nil? && data["layout"] != "none" && layout.nil? && self.class.to_s != "Jekyll::Excerpt" |
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.
Please use #is_a?
for class checking
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.
Fixed! 😛
# | ||
# Returns true if the layout is invalid, false if otherwise | ||
def invalid_layout?(layout) | ||
!document.data["layout"].nil? && document.data["layout"] != "none" && layout.nil? |
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.
none
should be a valid layout name. Can we just do the first and last checks? If a layout is specified but doesn't exist, warn.
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.
@parkr Yeah, here I'm excluding none
as a valid layout, so if a page has layout: none
in the front matter, Jekyll won't throw a warning.
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.
layout: none
would be invalid unless _layouts/none.html
exists. We should only consider nil
(and maybe false?) as the user not specifying a layout. If I have a layout called none
but haven't created the file, I'm going to be upset that this warning didn't catch my error.
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.
Sure, I'll update the code to match that.
Looking pretty good. One comment above and I'll merge. |
Throw a warning if a layout is specified in a
Convertible
orDocument
but the layout file (in the_layouts
dir) does not exist.Should address #2251 and #2583.