-
Notifications
You must be signed in to change notification settings - Fork 878
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
Algolia support from config only #1662
Merged
chalin
merged 5 commits into
google:main
from
chalin:chalin-im-algolia-out-of-the-box-2023-08-11
Aug 17, 2023
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,8 @@ | |
<link rel="stylesheet" href="{{ "css/prism.css" | relURL }}"/> | ||
{{ end -}} | ||
|
||
{{ template "algolia/head" . -}} | ||
|
||
{{ partial "hooks/head-end.html" . -}} | ||
|
||
{{/* To comply with GDPR, cookie consent scripts places in head-end must execute before Google Analytics is enabled */ -}} | ||
|
@@ -52,3 +54,18 @@ | |
{{ template "_internal/google_analytics_async.html" . -}} | ||
{{ end -}} | ||
{{ end -}} | ||
|
||
{{ 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we better place this in |
||
integrity="sha512-O6ywtjtiV4QGgC6cD75C2Tf04SlTn9vvka8oV/dYpDL1JWM4lVP0QoZbdZt5RLtOWDpaP+MObzUrwl43ssqfvg==" | ||
crossorigin="anonymous" /> | ||
{{ end -}} | ||
|
||
{{ if ne .Site.Params.algolia_docsearch nil -}} | ||
{{ warnf `Config 'params.algolia_docsearch' is deprecated: use 'params.search.algolia' | ||
For details, see https://www.docsy.dev/docs/adding-content/search/#algolia-docsearch.` -}} | ||
{{ end -}} | ||
|
||
{{ end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +0,0 @@ | ||
{{ with .Site.Params.algolia_docsearch }} | ||
<!-- scripts for algolia docsearch --> | ||
{{ end }} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +0,0 @@ | ||
{{ with .Site.Params.algolia_docsearch }} | ||
<!-- stylesheet for algolia docsearch --> | ||
{{ end }} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -102,4 +102,26 @@ | |||||||||||||||||||||||||||||||||||||||||
{{ end -}} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
<script src='{{ "js/tabpane-persist.js" | relURL }}'></script> | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
{{- if and .Site.Params.search (isset .Site.Params.search "algolia") -}} | ||||||||||||||||||||||||||||||||||||||||||
{{ template "algolia/scripts" .Site.Params.search.algolia -}} | ||||||||||||||||||||||||||||||||||||||||||
{{ end -}} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
{{ partial "hooks/body-end.html" . -}} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
{{ define "algolia/scripts" }} | ||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as for css: why not retrieving the .js resource at build time?
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
<script src="https://cdn.jsdelivr.net/npm/@docsearch/js@3" | ||||||||||||||||||||||||||||||||||||||||||
integrity="sha512-sQFwlNnBlEyWdI4EwJ9d2wjViu0ZPmIMjPP8kCmBoOjqcljGndf2gb4mldT4ZHxKCQcrdJ0+rxnMFKHuGWB7ag==" | ||||||||||||||||||||||||||||||||||||||||||
crossorigin="anonymous" ></script> | ||||||||||||||||||||||||||||||||||||||||||
<script type="text/javascript"> | ||||||||||||||||||||||||||||||||||||||||||
const containers = ['#docsearch-0', '#docsearch-1']; | ||||||||||||||||||||||||||||||||||||||||||
for (let c of containers) { | ||||||||||||||||||||||||||||||||||||||||||
docsearch({ | ||||||||||||||||||||||||||||||||||||||||||
container: c, | ||||||||||||||||||||||||||||||||||||||||||
appId: {{ .appId | default "R2IYF7ETH7" }}, | ||||||||||||||||||||||||||||||||||||||||||
apiKey: {{ .apiKey | default "599cec31baffa4868cae4e79f180729b" }}, | ||||||||||||||||||||||||||||||||||||||||||
indexName: {{ .indexName | default "docsearch" }}, | ||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
</script> | ||||||||||||||||||||||||||||||||||||||||||
{{ end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
: