Skip to content
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

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

Merged
merged 3 commits into from
Dec 27, 2024

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.

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
@stevenjoezhang stevenjoezhang merged commit 6637528 into hexojs:master Dec 27, 2024
21 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants