refactor(meta_generator): update regex and avoid edge case #3697
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.
What does it do?
After #3671 & #3696 , meta_generator filter will replace
</title>
with<meta name="generator" content="Hexo ${hexo.version}"></title>
.@curbengh has mentioned some edge cases will cause unwanted behavior:
This PR introduce replacing
</head>
with<meta name="generator" content="Hexo ${hexo.version}"></head>
with a pattern that ignore empty<head>
tag.How to test
A test case about
ignore empty head tag
has been added in this PR as well.Screenshots
According to benchmark, use regex to match
</head>
is about1%
slower than replace</title>
directly.meta_generator
</title>
directly (current master branch)Pull request tasks