mirror of https://github.com/lxndrblz/anatole.git

Alexander Bilz
21.34.2020 fa9e56007f66f4cf30795f4b901ed053eec3bd41
⌨ Added abilitiy to include remote JavaScript files

Closes #39
2 files modified
26 ■■■■ changed files
README.md 10 ●●●●● patch | view | raw | blame | history
layouts/partials/head.html 16 ●●●●● patch | view | raw | blame | history
README.md
@@ -150,6 +150,16 @@
```
`hello.js` and `world.js` will be bundled into a `custom.min.js`.
You can also include links to remote javascript files (hosted on CDNs for example). But be aware, that integrity settings and minification won't be applied. Further make sure to adjust your CSP. You can load a remote script like this:
```toml
[params]
customJs = ["http://cdn.exmple.org/fancyscript.js"]
```
Both approaches can even be mixed:
```toml
[params]
customJs = ["https://cdn.exmple.org/fancyscript.js", "js/world.js"]
```
### Content Security Policy
The theme is compliant with most strict CSP policies out of the box. A sample CSP for an Anatole-based site would look something like this:
layouts/partials/head.html
@@ -28,12 +28,16 @@
    
    {{- $js := "" -}}
    {{- range .Site.Params.customJs -}}
      {{- $customJS := resources.Get . -}}
      {{- if $customJS -}}
        {{- if eq $js "" -}}
          {{- $js = $customJS -}}
        {{- else -}}
          {{- $js = slice $js $customJS | resources.Concat "js/custom.js" -}}
      {{- if or (in . "http://") (in . "https://")  -}}
      <script src="{{ . | relURL }}"></script>
      {{- else -}}
        {{- $customJS := resources.Get . -}}
        {{- if $customJS -}}
          {{- if eq $js "" -}}
            {{- $js = $customJS -}}
          {{- else -}}
            {{- $js = slice $js $customJS | resources.Concat "js/custom.js" -}}
          {{- end -}}
        {{- end -}}
      {{- end -}}
    {{- end -}}