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

Paolo Mainardi
02.22.2023 c3bcde658bfca3a779b7948e5817f19bdc30298c
feat: Add support for custom remote javascript files (#751)

### Prerequisites

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

- [ ] This pull request fixes a bug.
- [X] This pull request adds a feature - #750
- [ ] This pull request introduces breaking change.

### Description

Add a new configuration item and use resources.GetRemote to gather the
remote asset.

### Checklist

#### General

- [X] Describe what changes are being made
- [X] Explain why and how the changes were necessary and implemented
respectively

#### Resources

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

#### Contributors

- [X] Add yourself to `CONTRIBUTORS.md` if you aren't on it already
3 files modified
16 ■■■■■ changed files
docs/configurations.md 1 ●●●● patch | view | raw | blame | history
exampleSite/config.toml 4 ●●●● patch | view | raw | blame | history
layouts/_default/baseof.html 11 ●●●●● patch | view | raw | blame | history
docs/configurations.md
@@ -149,6 +149,7 @@
| customCSS                     | list   | No       | Add extra CSS files to the website.              | []                               | `["css/extra-style.css"]`                        |
| customSCSS                    | list   | No       | Add extra SCSS files to the website.             | []                               | `["scss/extra-style.scss"]`                      |
| 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`                                |
### Social Icons Configuration
exampleSite/config.toml
@@ -39,9 +39,13 @@
customCSS = []
# Custom SCSS, file path is relative to Hugo's asset folder (default: {your project root}/assets)
customSCSS = []
# Custom JS
customJS = []
# Custom remote JS files
customRemoteJS = []
# If you want to use fathom(https://usefathom.com) for analytics, add this section
# [params.fathomAnalytics]
# siteID = "ABCDE"
layouts/_default/baseof.html
@@ -49,6 +49,17 @@
  {{ end }}
  {{ end }}
  {{ range .Site.Params.customRemoteJS }}
  {{ if $.Site.IsServer }}
  {{ $script := resources.GetRemote . }}
  <script src="{{ $script.RelPermalink }}"></script>
  {{ else }}
  {{ $script := resources.GetRemote . | minify | fingerprint }}
  <script src="{{ $script.RelPermalink }}" integrity="{{ $script.Data.Integrity }}"></script>
  {{ end }}
  {{ end }}
  {{ template "_internal/google_analytics.html" . }}
  {{ if and .Site.Params.fathomAnalytics .Site.Params.fathomAnalytics.siteID }}