Skip to content

Commit

Permalink
fix: don't prepend host url to external js if it starts with http:// …
Browse files Browse the repository at this point in the history
…or https://
  • Loading branch information
vividvilla committed Dec 31, 2019
1 parent 76678b5 commit 7aba720
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -85,8 +85,9 @@ paginate = 10
customDarkCSS = "css/custom-dark.css"

# Custom list of Javascript files to load. Just like custom CSS you can place js files under
# `static/js` folder and specify path here as `js/script-name.js`.
customJS = ["js/abc.js", "js/xyz.js"]
# `static/js` folder and specify path here as `js/script-name.js`. You can also specify full url,
# for example you may want to include external JS library.
customJS = ["js/abc.js", "js/xyz.js", "https://code.jquery.com/jquery-3.4.1.js"]

# Main menu which appears below site header.
[[menu.main]]
Expand Down
2 changes: 1 addition & 1 deletion exampleSite/config.toml
Expand Up @@ -20,7 +20,7 @@ disqusShortname = "ezhil-demo"
mode = "auto" # "dark", "auto", "light"
# customCSS = "css/custom.css" # Custom CSS applied to default styles.
# customDarkCSS = "css/custom-dark.css" # Custom styles applied to dark mode css.
# customJS = ["js/custom.js", "js/custom1.js"] # Custom JS scripts.
customJS = ["https://code.jquery.com/jquery-3.4.1.js", "js/custom1.js"] # Custom JS scripts.

[[menu.main]]
name = "Home"
Expand Down
4 changes: 4 additions & 0 deletions layouts/partials/header.html
Expand Up @@ -42,7 +42,11 @@
<script src="{{ .Site.BaseURL }}js/main.js"></script>
{{- if isset .Site.Params "customjs" -}}
{{- range .Site.Params.customJS }}
{{- if or (hasPrefix . "http://") (hasPrefix . "https://") }}
<script src="{{ . }}"></script>
{{- else }}
<script src="{{ $.Site.BaseURL }}{{ . }}"></script>
{{- end }}
{{- end }}
{{- end }}
</head>

0 comments on commit 7aba720

Please sign in to comment.