-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This reverts commit 744df6c.
- Loading branch information
Showing
8 changed files
with
246 additions
and
62 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
const { TypesenseInstantSearchAdapter, instantsearch } = window; | ||
const observer = lozad(); | ||
|
||
const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({ | ||
server: { | ||
apiKey: "oRW875O3vjeV3qX4ENl1iIA0u2IRDbTQ", // Be sure to use an API key that only allows search operations | ||
nodes: [ | ||
{ | ||
host: "cgnvrk0xwyj9576lp-1.a1.typesense.net", | ||
port: "443", | ||
protocol: "https", | ||
}, | ||
], | ||
cacheSearchResultsForSeconds: 2 * 60, // Cache search results from server. Defaults to 2 minutes. Set to 0 to disable caching. | ||
}, | ||
// The following parameters are directly passed to Typesense's search API endpoint. | ||
// So you can pass any parameters supported by the search endpoint below. | ||
// query_by is required. | ||
additionalSearchParameters: { | ||
query_by: "resource,title,description", | ||
sort_by: "featured:asc,date:desc", | ||
}, | ||
}); | ||
|
||
const searchClient = typesenseInstantsearchAdapter.searchClient; | ||
|
||
const search = instantsearch({ | ||
indexName: "tutorials", | ||
searchClient, | ||
}); | ||
|
||
|
||
const customRefinementList = instantsearch.connectors.connectRefinementList( | ||
({ items, refine, widgetParams }, isFirstRender) => { | ||
|
||
const container = document.getElementById(widgetParams.container); | ||
|
||
if (isFirstRender) { | ||
container.addEventListener("click", ({ target }) => { | ||
const input = target.closest("input"); | ||
|
||
if (input) { | ||
let refinements = search.helper.state.disjunctiveFacetsRefinements["platformarea"]; | ||
if (refinements.length) { | ||
if (refinements[0] == input.name) { | ||
refine(refinements[0]); | ||
} else { | ||
refine(refinements[0]); | ||
refine(input.name) | ||
} | ||
} else { | ||
refine(input.name) | ||
} | ||
} | ||
}); | ||
|
||
return; | ||
} | ||
|
||
const list = widgetParams.items.map(({ label: staticLabel, value: staticValue }) => { | ||
const elem = items.find(({ label }) => label === staticValue); | ||
|
||
let count = 0; | ||
let isRefined = false; | ||
if (elem) { | ||
count = elem.count; | ||
isRefined = elem.isRefined; | ||
} | ||
|
||
return ` | ||
<li> | ||
<label> | ||
<input | ||
type="button" | ||
value="${staticLabel}" | ||
name="${staticValue}" | ||
class="filterbutton ${isRefined ? "refined" : ""}" | ||
${isRefined || count ? "" : "disabled"} | ||
/> | ||
</label> | ||
</li> | ||
`; | ||
}); | ||
|
||
container.innerHTML = ` | ||
<ul> | ||
${list.join("")} | ||
</ul> | ||
`; | ||
}, | ||
); | ||
|
||
let refinementLists = [customRefinementList({ | ||
container: "platformarea-list", | ||
attribute: "platformarea", | ||
operator: "or", | ||
sortBy: ["name:asc"], | ||
items: [ | ||
{ label: "Data Management", value: "data" }, | ||
{ label: "Machine Learning", value: "ml" }, | ||
{ label: "Control hardware", value: "core" }, | ||
{ label: "Fleet Management", value: "fleet" }, | ||
{ label: "Integrate other hardware", value: "registry" }, | ||
{ label: "Mobility", value: "mobility" }, | ||
], | ||
}), | ||
customRefinementList({ | ||
container: "resource-list", | ||
attribute: "resource", | ||
operator: "or", | ||
sortBy: ["name:asc"], | ||
items: [ | ||
{ label: "tutorial" }, | ||
{ label: "how-to" }, | ||
{ label: "quickstart" }, | ||
{ label: "blogpost" }, | ||
{ label: "codelab" }, | ||
], | ||
})] | ||
|
||
let searchWidgets = [ | ||
instantsearch.widgets.hits({ | ||
container: "#hits", | ||
templates: { | ||
item: ` | ||
<div class="col hover-card"> | ||
<a href="{{relpermalink}}" target="_blank"> | ||
<div class="small-hover-card-div"> | ||
<div class="title">{{title}}</div> | ||
<div class="description"> | ||
{{#description}}<p>{{description}}</p>{{/description}} | ||
</div> | ||
</div> | ||
</a> | ||
</div> | ||
`, | ||
}, | ||
}), | ||
instantsearch.widgets.configure({ | ||
hitsPerPage: 12, | ||
}), | ||
instantsearch.widgets.pagination({ | ||
container: "#pagination", | ||
}), | ||
]; | ||
|
||
search.addWidgets(refinementLists); | ||
|
||
search.start(); | ||
// Only show guide & howtos | ||
search.addWidgets([{ | ||
init: function(options) { | ||
options.helper.toggleRefinement('resource', 'how-to'); | ||
options.helper.toggleRefinement('resource', 'quickstart'); | ||
} | ||
}]); | ||
|
||
let widgetsAdded = false; | ||
|
||
search.on("render", function () { | ||
if (search.helper.state.disjunctiveFacetsRefinements.platformarea.length) { | ||
if (!widgetsAdded) { | ||
widgetsAdded = true; | ||
search.addWidgets(searchWidgets); | ||
document.getElementById("how-to-paths").classList.add("isHidden"); | ||
} | ||
} else { | ||
if (widgetsAdded) { | ||
widgetsAdded = false; | ||
search.removeWidgets(searchWidgets); | ||
document.getElementById("how-to-paths").classList.remove("isHidden"); | ||
} | ||
} | ||
|
||
if ( | ||
search.helper.state.facetsRefinements && | ||
search.helper.state.disjunctiveFacetsRefinements.platformarea | ||
) { | ||
document | ||
.querySelectorAll(".pill-component") | ||
.forEach((e) => | ||
search.helper.state.disjunctiveFacetsRefinements.platformarea.includes( | ||
e.textContent, | ||
) | ||
? e.classList.add("pill-highlight") | ||
: e.classList.remove("pill-highlight"), | ||
); | ||
} | ||
|
||
observer.observe(); | ||
}); |
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 |
---|---|---|
|
@@ -38,5 +38,13 @@ | |
|
||
{{ partial "scripts.html" . }} | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/typesense-instantsearch-adapter@2/dist/typesense-instantsearch-adapter.min.js"></script> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script> | ||
|
||
{{ $jsTutorials := resources.Get "js/tutorials.js" }} | ||
{{ $jsTutorials := $jsTutorials | minify }} | ||
<script type="text/javascript" src="{{ $jsTutorials.RelPermalink }}" crossorigin="anonymous"></script> | ||
|
||
</body> | ||
</html> |
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 |
---|---|---|
|
@@ -118,20 +118,8 @@ <h4 class="alert-heading">Javascript</h4> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script> | ||
|
||
{{ $jsTutorials := resources.Get "js/tutorials.js" }} | ||
{{ if (eq (substr .Site.BaseURL -1) "/" ) }} | ||
{{- $opts := dict | ||
"params" (dict "baseURL" (substr .Site.BaseURL 0 -1 )) | ||
-}} | ||
{{- $jsTutorials = $jsTutorials | js.Build $opts -}} | ||
{{ $jsTutorials := $jsTutorials | minify }} | ||
<script type="text/javascript" src="{{ $jsTutorials.RelPermalink }}" crossorigin="anonymous"></script> | ||
{{ else }} | ||
{{- $opts := dict | ||
"params" (dict "baseURL" .Site.BaseURL) | ||
-}} | ||
{{- $jsTutorials = $jsTutorials | js.Build $opts -}} | ||
{{ $jsTutorials := $jsTutorials | minify }} | ||
<script type="text/javascript" src="{{ $jsTutorials.RelPermalink }}" crossorigin="anonymous"></script> | ||
{{ end }} | ||
|
||
</body> | ||
</html> |
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 |
---|---|---|
@@ -1,35 +1,35 @@ | ||
{{- $recentlyChanged := (lt (sub now.Unix .Lastmod.Unix) 3600) -}} | ||
{{ $recentlyChanged := (lt (sub now.Unix .Lastmod.Unix) 3600) }} | ||
|
||
{{- if .Params.metaDescription -}} | ||
{{if gt (len .Params.metaDescription) 158 -}} | ||
{{if .Params.metaDescription }} | ||
{{if gt (len .Params.metaDescription) 158}} | ||
{{- warnf "Page description too long (%d) - should be 50-158 characters: %q." (len .Params.metaDescription) .Path -}} | ||
{{- end -}} | ||
{{- if lt (len .Params.metaDescription) 50 -}} | ||
{{ end }} | ||
{{if lt (len .Params.metaDescription) 50}} | ||
{{- warnf "Page description too short (%d) - should be 50-158 characters: %q." (len .Params.metaDescription) .Path -}} | ||
{{- end -}} | ||
{{- with .Params.metaDescription | plainify -}} | ||
{{- . -}} | ||
{{- end -}} | ||
{{- else if .Description -}} | ||
{{- if $recentlyChanged -}} | ||
{{- if gt (len .Description) 158 -}} | ||
{{ end }} | ||
{{ with .Params.metaDescription | plainify -}} | ||
{{ . -}} | ||
{{ end }} | ||
{{else if .Description }} | ||
{{ if $recentlyChanged}} | ||
{{if gt (len .Description) 158}} | ||
{{- warnf "Page description too long (%d) - change it or add a metaDescription with 50-158 characters: %q." (len .Description) .Path -}} | ||
{{- end -}} | ||
{{if lt (len .Description) 50 -}} | ||
{{ end }} | ||
{{if lt (len .Description) 50}} | ||
{{- warnf "Page description too short (%d) - change it or add a metaDescription with 50-158 characters: %q.\n This may be a good start:\n%q" (len .Description) .Path (.Summary | plainify) -}} | ||
{{- end -}} | ||
{{- end -}} | ||
{{- with .Description | plainify -}} | ||
{{- . -}} | ||
{{- end -}} | ||
{{- else -}} | ||
{{- if .IsPage -}} | ||
{{- if not .Params.empty_node -}} | ||
{{ end }} | ||
{{ end }} | ||
{{ with .Description | plainify -}} | ||
{{ . -}} | ||
{{ end }} | ||
{{ else -}} | ||
{{ if .IsPage -}} | ||
{{ if not .Params.empty_node }} | ||
{{- errorf "No description for page %q" .Path -}} | ||
{{- end -}} | ||
{{- else -}} | ||
{{- with .Site.Params.description | plainify -}} | ||
{{- . -}} | ||
{{- end -}} | ||
{{- end -}} | ||
{{- end -}} | ||
{{ end -}} | ||
{{ else -}} | ||
{{ with .Site.Params.description | plainify -}} | ||
{{ . -}} | ||
{{ end -}} | ||
{{ 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 |
---|---|---|
|
@@ -38,21 +38,20 @@ | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script> | ||
|
||
{{ $jsModels := resources.Get "js/models.js" }} | ||
{{ if (eq (substr .Site.BaseURL -1) "/" ) }} | ||
{{- $opts := dict | ||
"params" (dict "baseURL" (substr .Site.BaseURL 0 -1 )) | ||
-}} | ||
{{- $jsModels = $jsModels | js.Build $opts -}} | ||
{{ $jsModels := $jsModels | minify }} | ||
<script type="text/javascript" src="{{ $jsModels.RelPermalink }}" crossorigin="anonymous"></script> | ||
{{ else }} | ||
{{- $opts := dict | ||
"params" (dict "baseURL" .Site.BaseURL) | ||
-}} | ||
{{- $jsModels = $jsModels | js.Build $opts -}} | ||
{{ $jsModels := $jsModels | minify }} | ||
<script type="text/javascript" src="{{ $jsModels.RelPermalink }}" crossorigin="anonymous"></script> | ||
{{ end }} | ||
|
||
<!-- JS for how to page --> | ||
{{ if .Page.Params.howtojs }} | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/typesense-instantsearch-adapter@2/dist/typesense-instantsearch-adapter.min.js"></script> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script> | ||
|
||
{{ $jsHowtos := resources.Get "js/howtos.js" }} | ||
{{ $jsHowtos := $jsHowtos | minify }} | ||
<script type="text/javascript" src="{{ $jsHowtos.RelPermalink }}" crossorigin="anonymous"></script> | ||
{{ end }} | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" | ||
|