-
Notifications
You must be signed in to change notification settings - Fork 451
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
Separate NexT inline scripts and styles #226
Separate NexT inline scripts and styles #226
Conversation
- TODO: Compatibility with Pjax.
- Use <meta name="hexo-config[-page]"> to store configurations - Combine js scripts in `head.njk` and `head-unique.njk` into `load-config.js` - Remove unused class `hexo-configurations`
- Background image of `.link-grid-image` are defined by passing parameters to and then generated by `link-grid.js`, which means it can't be moved into single CSS file directly. A more proper way would be changing the type of it, from `<div>` to `<img>`, and use `src` instead of `style="background-image: "` - which needs a discussion
I separated most of the inline styles in the last commit. There are one inline style I left untouched in Background image of By changing the type, not only the related CSS code in NexT needs changes, styles defined by users may also be affected. So, should I leave the way it is or change its type and related CSS anyway? |
- Refactor `load-config.js` and `pjax.js` to load and update all configurations at once.
Scripts have (almost) all been separated into @stevenjoezhang What's our next move? ("Except" the "except"s, or leave the way they are?) |
08f5e7a
to
0e18826
Compare
Co-authored-by: Mimi <[email protected]>
Edit: see my next comment and ignore this. @next-theme/core I am trying to separate the scripts in
{%- if theme.baidu_analytics %}
<script{{ pjax }}>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?{{ theme.baidu_analytics }}";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
{%- endif %} I don't understand. What's the difference it made from: {%- if theme.baidu_analytics %}
<script{{ pjax }}>var _hmt = _hmt || [];</script>
<script{{ pjax }} src="https://hm.baidu.com/hm.js?{{ theme.baidu_analytics }}"></script>
{%- endif %} ? If there is something I missed out, appeciate you informing me. or I may refactor some parts of the scripts like this. |
baidu-analytics, this part of the code may be copied directly from Baidu |
@next-theme/core Ignore my last commit and take a look at this one 😅, I figured out a new way to implement the third party scripts, which is to edit and move the There is a possible sample, it
Most of the third party scripts are injected once it is enabled, while the ones about comments ( But it's easy to write some conditions for the pages that don't use Pjax, to not implement these Feel free to share your opinions. |
If we are lucky, changing the type of I decided to use
If you are fine with these changes, this pull request will be merged very soon, and future discussions about the third-party implements will continue in a new pull request. |
* Fix head inject point * Switch `.link-grid-image` to `<img>` * Switch `.link-grid-image` back to `<object>` - Set `type` to `image/jpeg` for image without file extension
PR Checklist
PR Type
What is the current behavior?
NexT is using several inline scripts and inline styles.
Issue resolved: #220
What is the new behavior?
Scripts (except third party and schedule modules) will be load in separate files. (Demo site now runs without setting
unsafe-inline
inscript-src
of CSP.)Inline styles remains where they are for now, since they are a little bit scattered.
But all of them will be separated in future commits.
Tests is not enough yet.
How to use?
In NexT
_config.yml
: