Skip to content
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

Add a partial to download the assets from CDNs #4

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions fetch-static.sh

This file was deleted.

19 changes: 19 additions & 0 deletions layouts/partials/dl-asset.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{/*

A partial to download an asset from a CDN at build time and serve it from our
server. It outputs a string which is the relative path to the asset.

It accepts a string, which is the URL of the asset to download.

*/}}
{{- $url := . -}}

{{ with resources.GetRemote $url -}}
{{ with .Err -}}
{{ errorf "Could not retrieve asset at '%s' from CDN. Reason: %s." $url . -}}
{{ else -}}
{{ .RelPermalink -}}
{{ end -}}
{{ else -}}
{{ errorf "Could not find asset at '%s' on the CDN." $url -}}
{{ end -}}
6 changes: 3 additions & 3 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
{{ template "_internal/twitter_cards.html" . -}}
{{ partialCached "head-css.html" . "asdf" -}}
<script
src="{{ "/js/jquery-3.6.3.min.js" | relURL }}"
src="{{ partial "dl-asset.html" "https://code.jquery.com/jquery-3.6.3.min.js" }}"
integrity="sha512-STof4xm1wgkfm7heWqFJVn58Hm3EtS31XFaagaa8VMReCXAkQnJZ+jEy8PCC/iT18dFy95WcExNHFTqLyp72eQ=="
crossorigin="anonymous"></script>
{{ if .Site.Params.offlineSearch -}}
<script defer
src="{{ "/js/lunr-2.3.9.min.js" | relURL }}"
src="{{ partial "dl-asset.html" "https://unpkg.com/lunr@2.3.9/lunr.min.js" }}"
integrity="sha384-203J0SNzyqHby3iU6hzvzltrWi/M41wOP5Gu+BiJMz5nwKykbkUx8Kp7iti0Lpli"
crossorigin="anonymous"></script>
{{ end -}}
Expand All @@ -57,7 +57,7 @@
{{ define "algolia/head" -}}

{{ if and .Site.Params.search (isset .Site.Params.search "algolia") -}}
<link rel="stylesheet" href="{{ "/css/docsearch-3.5.2.min.css" | relURL }}"
<link rel="stylesheet" href="{{ partial "dl-asset.html" "https://cdn.jsdelivr.net/npm/@docsearch/css@3.5.2" }}"
integrity="sha512-TW5eKlwwg7OfQUVBqxjp94/uqtjJJbhkRE3++XGEQjAL1n3y//QVqS3acPkwqkzInaFRtj+w05uyxDbfDXiI1A=="
crossorigin="anonymous" />
{{ end -}}
Expand Down
14 changes: 7 additions & 7 deletions layouts/partials/scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
};
</script>
<script src="{{ "/js/markmap-autoloader.js" | relURL }}"></script>
<script src="{{ partial "dl-asset.html" "https://cdn.jsdelivr.net/npm/markmap-autoloader" }}"></script>
{{ end -}}

{{ if .Site.Params.plantuml.enable -}}
Expand All @@ -41,22 +41,22 @@

{{ if $needKaTeX -}}
{{/* load stylesheet and scripts for KaTeX support */ -}}
<link rel="stylesheet" href="{{ "/css/[email protected]/dist/katex.min.css" | relURL }}"
<link rel="stylesheet" href="{{ partial "dl-asset.html" "https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" }}"
integrity="sha512-mQwom8Ns4op+H29oDkD/LXO/OsXPvCFfkgZkFAVrhhePzRLU8NUI3Nkm43NhWUSmj3p5Cca2HTEkMQmXQRwDQQ==" crossorigin="anonymous">
{{/* The loading of KaTeX is deferred to speed up page rendering */ -}}
<script defer src="{{ "/js/[email protected]/dist/katex.min.js" | relURL }}"
<script defer src="{{ partial "dl-asset.html" "https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" }}"
integrity="sha512-sHSNLECRJSK+BFs7E8DiFc6pf6n90bLI85Emiw1jhreduZhK3VXgq9l4kAt9eTIHYAcuQBKHL01QKs4/3Xgl8g=="
crossorigin="anonymous">
</script>
{{ if $needmhchem -}}
{{/* To add support for displaying chemical equations and physical units, load the mhchem extension: */ -}}
<script defer src="{{ "/js/[email protected]/dist/contrib/mhchem.min.js" | relURL }}"
<script defer src="{{ partial "dl-asset.html" "https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/mhchem.min.js" }}"
integrity="sha512-V1hl0fnOXW6Cdqe5ZVqtw8TBpJVpu3XRDRQti96j/04+tMarPrCdXEUE3UdfvfKYTpOn9DV4zEZBVr0HhDiuiQ=="
crossorigin="anonymous">
</script>
{{ end -}}
{{/* To automatically render math in text elements, include the auto-render extension: */ -}}
<script defer src="{{ "/js/[email protected]/dist/contrib/auto-render.min.js" | relURL }}"
<script defer src="{{ partial "dl-asset.html" "https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" }}"
integrity="sha512-iWiuBS5nt6r60fCz26Nd0Zqe0nbk1ZTIQbl3Kv7kYsX+yKMUFHzjaH2+AnM6vp2Xs+gNmaBAVWJjSmuPw76Efg==" crossorigin="anonymous"
{{ printf "onload='renderMathInElement(%s, %s);'" (( $.Page.Site.Params.katex.html_dom_element | default "document.body" ) | safeJS ) ( printf "%s" ( $.Page.Site.Params.katex.options | jsonify )) | safeHTMLAttr }}>
</script>
Expand All @@ -78,7 +78,7 @@

{{ if $needmermaid -}}
{{ $jsArray = $jsArray | append $jsMermaid -}}
<script src="{{ "/js/mermaid-9.3.0.min.js" | relURL }}" integrity="sha512-ku2nmBrzAXY5YwohzTqLYH1/lvyMrpTVxgQKrvTabd/b/uesqltLORdmpVapYv6QhZVCLUX6wkvFaKOAY4xpUA==" crossorigin="anonymous"></script>
<script src="{{ partial "dl-asset.html" "https://cdn.jsdelivr.net/npm/mermaid@9.3.0/dist/mermaid.min.js" }}" integrity="sha512-ku2nmBrzAXY5YwohzTqLYH1/lvyMrpTVxgQKrvTabd/b/uesqltLORdmpVapYv6QhZVCLUX6wkvFaKOAY4xpUA==" crossorigin="anonymous"></script>
{{ end -}}

{{ $js := $jsArray | resources.Concat "js/main.js" -}}
Expand Down Expand Up @@ -108,7 +108,7 @@
{{ partial "hooks/body-end.html" . -}}

{{ define "algolia/scripts" -}}
<script src="{{ "/js/docsearch-3.5.2.min.js" | relURL }}"
<script src="{{ partial "dl-asset.html" "https://cdn.jsdelivr.net/npm/@docsearch/js@3.5.2" }}"
integrity="sha512-LzxWPDNELae1RSIsDRSitKYPJpRtjYo22GbOl+d+xLcjKiZQRRdxSTI3cRRHw7O05e0MbIIu33QnU2rt6ymQ6A=="
crossorigin="anonymous" ></script>
<script type="text/javascript">
Expand Down
8 changes: 0 additions & 8 deletions static/css/docsearch-3.5.2.min.css

This file was deleted.

1 change: 0 additions & 1 deletion static/css/[email protected]/dist/katex.min.css

This file was deleted.

Loading