changed the judgement of whether it has been injected #5573
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?
When I introduced the Hexo injector in my blog post: 'Here we can see that between and there are many div blocks that we injected using the injector, and at the same time, between and there are JavaScript script blocks and canvas elements that we injected. I believe by now you can understand the functionality of the injector.' However, I found that the custom effects implemented through the injector were not working, so I checked the source code and found an issue with the logic that determines whether the injector has inserted content. When content like hexo injector body exists in my article, the injector mistakenly thinks it has already been inserted.
I tried to ensure that the comments and tags are tightly connected by using the condition (flag==='head_begin' && /<head.?>\s[\S\s]/.test(input)), but this causes the test cases in the test to fail. So, I changed the condition to if (input.includes(, it still causes the injector to fail. Therefore, I still have some doubts about the condition and test cases. Will a situation like really occur in thetest? I don’t think it will in practical applications. If this situation doesn’t occur, then using the regex condition (flag==='head_begin' && /<head.?>\s[\S\s]/.test(input))` to check if the comment and tag are connected seems like a better choice, as it can handle all the cases mentioned above. Of course, this is just my thought, and I would appreciate any guidance if I'm mistaken.
Screenshots
My homepage has
But after mentioning and in the article, the injector stopped working."
Pull request tasks