-
Notifications
You must be signed in to change notification settings - Fork 327
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
Parse "jbake-" prefixed asciidoc headers like normal metadata #580
Parse "jbake-" prefixed asciidoc headers like normal metadata #580
Conversation
JBake explicitly supports adding complex metadata in the form of string encoded JSON objects. This support was missing from metadata sourced from native asciidoc headers. The support is only added for explicit "jbake-" headers, to not interfere with normal asciidoc operation.
1 similar comment
Interesting. Thank you. I schedule some time for a review. Maybe end of the weekend. |
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.
Thanks for catching this. I added a few comments I would like to discuss.
content.put(key, JSONValue.parse(value)); | ||
} else { | ||
content.put(key, value); | ||
void processHeader(String inputKey, String inputValue, Map<String, Object> content) { |
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'm searching for a better name here. How about processHeaderValue
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'm ok with changing the name, I used processHeader
because this is key/value, an alternative would be storeHeaderValue
, but I have no strong feeling into any direction.
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.
Thats even a better name. That alignes with my attempt to build a document and template model abstraction. Which could be a new home for this method later. See #532
if(value instanceof String) { | ||
processHeader(pKey, (String) value, documentModel); | ||
} else { | ||
documentModel.put(pKey, value); |
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 could always call processHeader
. As the last case in that method adds the value for the given key to the documentModel Map. See line 284 in MarkupEngine
.
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 decided to special case the "String" case, as I don't want to interfere with the asciidoc engine. As NULL
could be generated, we'd still need a guard as in
if(value != null) {
processHeader(pKey, value.toString(), documentModel);
}
I have zero experience with asciidocj, so can't predict if other types, than string are possible.
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.
Yes you are right. asciidoctorj takes a Map<Sting, Object> for attributes. So it would be worth a try. On the other hand we could postpone it for a later cleanup session.
I pushed two updates, that try to address the comments. I kept them separate to make review easier, for integration I would squash them. |
Thanks for the contribution @matthiasblaesing 👍 |
JBake explicitly supports adding complex metadata in the form of string
encoded JSON objects. This support was missing from metadata sourced
from native asciidoc headers. The support is only added for explicit
"jbake-" headers, to not interfere with normal asciidoc operation.