-
Notifications
You must be signed in to change notification settings - Fork 285
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
Do not use inline scripts #173
Conversation
… scripts for the theme switcher (fixes #145)
Extensive changes to
Note that I renamed |
Wow! That would be great! |
I messed things up here. Scratch is actually necessary to get scripts from other templates, e.g. |
This is a lot more messy than I expected, with those third-party scripts expecting to be loaded at a particular time... |
I guess I'll keep the various third-party scripts unchanged at the bottom and only fix the built-in functionality. |
Third-party scripts are now in a separate template, back at the bottom of the page - no functionality change here. This allowed making the logic for the built-in scripts simpler again. |
|
||
{{- .Scratch.Add "script" (slice $custom) -}} | ||
{{- $processedScripts := slice ("" | resources.FromString "dummy.js") -}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a weird hack but it cannot be an empty slice. Apparently, slices are typed and an empty slice will be created with the wrong type making resources.Concat
fail.
Somehow I only noticed a bug after uploading this to a real website, it wasn't visible in local testing: |
* fix: Move loading JavaScript to the top of the page, don't use inline scripts for the theme switcher (fixes reuixiy#145) * fix: Do not use an inline script for HTTPS redirect * chore: Actually remove the inline script from page head * chore: Use scratch again (a private one) and fix lunr search * fix: Move third-party scripts back to the bottom of the page BREAKING CHANGE: custom.js is loaded at the top of the page now, before the page elements are available
The first commit here moves loading JavaScript to the top of the page, which requires putting lots of code into a DOMContentLoaded event listener - this code originally expected all the elements to be present already. The theme switcher's inline script has been removed (fixes #145 for me).
I will add more commits to get rid of other inline scripts as well.