mirror of https://github.com/luizdepra/hugo-coder.git

Muqeet Malik
18.44.2024 3afaa3f1b890d368f635cffb2cf8faada12389e1
Allow users to disable default theme-switching Javascript files (#870)

### Prerequisites

Put an `x` into the box(es) that apply:

- [ ] This pull request fixes a bug.
- [x] This pull request adds a feature.
- [ ] This pull request introduces breaking change.

### Description

This PR enables users to use the theme independently of JavaScript,
requiring only minimal changes. I've introduced a
`disableDefaultJsScripts` flag, rather than a `disableJS` toggle, to
avoid implying zero JavaScript. This approach keeps separately
configured JavaScript features like comments and analytics functional,
ensuring they are logically consistent with the
`disableDefaultJsScripts` configuration.

Moreover, when disableDefaultJsScripts is enabled, hideColorSchemeToggle
must be set to true, or else the app will fail with an error message. I
felt that this is a misconfiguration and alerting the user would provide
a better overall user experience ( I would not want somebody spending
time trying to figure out why the theme is not switching)

### Issues Resolved

#831

### Checklist

Put an `x` into the box(es) that apply:

#### General

- [x] Describe what changes are being made
- [x] Explain why and how the changes were necessary and implemented
respectively
- [x] Reference issue with `#<ISSUE_NO>` if applicable

#### Resources

- [ ] If you have changed any SCSS code, run `make release` to
regenerate all CSS files

#### Contributors

- [ ] Add yourself to `CONTRIBUTORS.md` if you aren't on it already

---------

Co-authored-by: Muqeet Malik <muqeet.malik.-nd@disneystreaming.com>
2 files modified
7 ■■■■ changed files
docs/configurations.md 1 ●●●● patch | view | raw | blame | history
layouts/_default/baseof.html 6 ●●●● patch | view | raw | blame | history
docs/configurations.md
@@ -129,6 +129,7 @@
| customJS                      | list   | No       | Add extra JS files to the website.               | []                               | `["js/extra-script.js"]`                         |
| customRemoteJS                | list   | No       | Add extra remote JS files to the website.        | []                               | `["https://www.example.com/file.js"]` |
| enableTwemoji                 | bool   | No       | Adds support for Twemoji                         | `false`                          | `true` or `false`                                |
| disableDefaultJsScripts       | bool   | No       | If true, disables default js scripts (coder.js)  | `false`                          | `true` or `false`                                |
### Social Icons Configuration
layouts/_default/baseof.html
@@ -33,7 +33,11 @@
  </script>
  {{ end }}
  {{ if .Site.IsServer }}
  {{ if .Site.Params.disableDefaultJsScripts }}
  {{ if not .Site.Params.hideColorSchemeToggle }}
  {{ errorf "Invalid configuration. Default JS scripts are disabled, but 'hideColorSchemeToggle' is false." }}
  {{end}}
  {{ else if .Site.IsServer }}
  {{ $script := resources.Get "js/coder.js" }}
  <script src="{{ $script.RelPermalink }}"></script>
  {{ else }}