Conversation
e43b37e to
1dbcca6
Compare
| {{ define "algolia/head" -}} | ||
|
|
||
| {{ if and .Site.Params.search (isset .Site.Params.search "algolia") -}} | ||
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@docsearch/css@3" |
There was a problem hiding this comment.
Should we better place this in head-css.html?
|
|
||
| {{ define "algolia/head" -}} | ||
|
|
||
| {{ if and .Site.Params.search (isset .Site.Params.search "algolia") -}} |
There was a problem hiding this comment.
Since minimum required version is hugo v0.110 now, what about fetching the docsearch npm resource at build time rather than at runtime? This way, we also have better GDPR support (#1354).
Also, I amended the code so that users now can specify the wanted docsearch version inside thier project's hugo.yaml:
params:
search:
algolia:
version: 3.5.1
| {{ if and .Site.Params.search (isset .Site.Params.search "algolia") -}} | |
| {{ if and .Site.Params.search (isset .Site.Params.search "algolia") -}} | |
| {{ $version := "v3.5.1" -}} | |
| {{ with .Site.Params.search.algolia.version -}} | |
| {{ $version = . -}} | |
| {{ end -}} | |
| {{ $cdnurl := printf "https://cdn.jsdelivr.net/npm/@docsearch/css@%s" $version -}} | |
| {{ if eq (resources.GetRemote $cdnurl) nil -}} | |
| {{ errorf "Invalid Algolia version %s, could not retrieve this version from CDN" $version -}} | |
| {{ end -}} | |
| {{ with resources.GetRemote $cdnurl -}} | |
| {{ with .Err -}} | |
| {{ errorf "Error while retrieving resource %q from CDN. Status: %s." $cdnurl .Data.Status -}} | |
| {{ else -}} | |
| {{ $secureCSS := . | resources.Fingerprint "sha512" -}} | |
| <link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ $secureCSS.Data.Integrity }}" crossorigin="anonymous" /> | |
| {{ end -}} | |
| {{ end -}} | |
| {{ end -}} | |
|
|
||
| {{ partial "hooks/body-end.html" . -}} | ||
|
|
||
| {{ define "algolia/scripts" }} |
There was a problem hiding this comment.
Same as for css: why not retrieving the .js resource at build time?
| {{ define "algolia/scripts" }} | |
| {{ define "algolia/scripts" }} | |
| {{ $version := "v3.5.1" -}} | |
| {{ with .Site.Params.search.algolia.version -}} | |
| {{ $version = . -}} | |
| {{ end -}} | |
| {{ $cdnurl := printf "https://cdn.jsdelivr.net/npm/@docsearch/js@%s" $version -}} | |
| {{ if eq (resources.GetRemote $cdnurl) nil -}} | |
| {{ errorf "Invalid Algolia version %s, could not retrieve this version from CDN" $version -}} | |
| {{ end -}} | |
| {{ with resources.GetRemote $cdnurl -}} | |
| {{ with .Err -}} | |
| {{ errorf "Error while retrieving resource %q from CDN. Status: %s." $cdnurl .Data.Status -}} | |
| {{ else -}} | |
| {{ $secureJS := . | resources.Fingerprint "sha512" -}} | |
| <script src="{{ .RelPermalink }}" integrity="{{ $secureJS.Data.Integrity }}" | |
| crossorigin="anonymous" ></script> | |
| {{ end -}} | |
| {{ end -}} |
|
Thanks for your valuable feedback @deining. I've updated the UG as you suggested. Great idea to fetch dependencies at build time. It should be used uniformly for all 3rd-party features! But for now, I would rather keep this PR simple and consistent with Docy's current way of supporting 3rd-party features/services. There is a plan to eventually address GDPR requirements, and better (modular) handling of 3rd-party dependencies. I'd rather keep that separate. As for using So I'd leave the rest of this PR as is for now. |
You are welcome.
Great!
Agreed. I have more Algolia related improvements in the pipeline, let's get this merged first! |
82bbc9e to
780e6af
Compare
780e6af to
cfb1d19
Compare
|
Thanks, awaiting your approval @deining. |
layouts/partials/hooks/head-end.htmlandlayouts/partials/hooks/body-end.htmlfrom the skeletal Algolia-support code.Preview: https://deploy-preview-1662--docsydocs.netlify.app/docs/adding-content/search/#algolia-docsearch