Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When publishing a draft without a date, the code that inserts the publish date into the post was not restricting itself to the YAML front-matter section of the post. Rather, it would search anywhere in the post for the
date:
andtitle:
keys and attempt to parse their values.If a draft didn't have a date in the front matter, but had the pattern
date:
somewhere in the body of the post,read_post_yaml
would find the pattern and attempt to parse the rest of the line.If it was successful, it would then try to remove the old date entry and add a new one in the front matter, corrupting the body of the post.
I attempted to fix this by using
YAML.safe_load
to parse the front-matter, but ran into two issues:YAML.safe_load
doesn't tell you where it finished parsing, so there was no way to get at the rest of the post after the front matter without using the regex anyway.In the end, I opted for a simpler approach: use the regex (the same one that Jekyll uses) to split out the front matter and the body, update the front matter, and reassemble the new front matter with the existing body.
I was not able to craft a proper
clash
test for this fix; all my attempts toecho
some additional content into the draft failed unless I ran with the-t
flag. I'm not sure why that is.