-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Any official way to insert HTML codes once per file? #3086
Comments
I found a plugin: |
The current way you did in your plugin (by registering a Although I know you want to insert custom code in the page, I don't know what you want this feature to be: A filter that replace |
Why not do it in your theme's code directly? |
For plugins (like player) require third-party library, there is no better way to insert custom HTML element. Themes can not handle this as well. For my own theme, I have to write custom HTML inside I wonder if Hexo could provide a API to do this (by utilizing filter). |
Environment Info
Node version(
node -v
):v9.7.1
Hexo and Plugin version(
npm ls --depth 0
):hexo@3.6.0
For feature request
Our plugin wants to inject some HTML codes into every pages once:
Our current code is to use
hexo.extend.filter.register('after_render:html', (str, data)
and(/<\/body>/gi.test(htmlContent))
ors.replace(/<\/head>/, tag + '</head>')
to inject it into HTML:https://github.com/MoePlayer/hexo-tag-dplayer/blob/master/index.js#L64
https://github.com/EYHN/hexo-helper-live2d/blob/master/index.js#L188
We are discussing whether it is the hacking way, or it is just the correct way.
We need to test the content for
<body>
because the filter will offer all the files(including all kings of HTML fragment), if we don't test for it, all the fragment will be insert a code, and the finally page will be like:(eg.index.html
)We just want it be added once, but I'm not sure even
(/<\/body>/gi.test(htmlContent))
can promise it.Is there any API or ways to make it directly?
Related:
MoePlayer/hexo-tag-dplayer#18 (comment)
The text was updated successfully, but these errors were encountered: