Skip to content

fix:changed the judgement of whether it has been injected#5573

Merged
stevenjoezhang merged 3 commits intohexojs:masterfrom
mRNA16:injector_change
Dec 27, 2024
Merged

fix:changed the judgement of whether it has been injected#5573
stevenjoezhang merged 3 commits intohexojs:masterfrom
mRNA16:injector_change

Conversation

@mRNA16
Copy link
Contributor

@mRNA16 mRNA16 commented Nov 15, 2024

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*<!-- hexo injector head_begin start -->[\S\s]*<!-- hexo injector head_begin end -->/.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

blocks inserted within the tag.
1
But after mentioning and in the article, the injector stopped working."
2
3

Pull request tasks

  • Add test cases for the changes.
  • Passed the CI test.

@github-actions
Copy link

How to test

git clone -b injector_change https://github.com/mRNA16/hexo.git
cd hexo
npm install
npm test

@mRNA16
Copy link
Contributor Author

mRNA16 commented Dec 24, 2024

I have made modifications to node_modules/hexo/dist/extend/injector.js locally. Both methods I proposed can solve the above issue. The changes I suggested should fix the bug. Please review my PR,thx!
屏幕截图 2024-12-24 223417
屏幕截图 2024-12-24 223713
屏幕截图 2024-12-24 223611

@mRNA16 mRNA16 changed the title changed the judgement of whether it has been injected fix:changed the judgement of whether it has been injected Dec 24, 2024
Signed-off-by: Mimi <1119186082@qq.com>
@stevenjoezhang stevenjoezhang merged commit 6637528 into hexojs:master Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The Injector fails when certain specific content is included in the blog post.(Injector在博客文章中包含某些特定内容时失效)

2 participants