Skip to content

Commit

Permalink
Move back to typesense
Browse files Browse the repository at this point in the history
  • Loading branch information
npentrel committed Aug 24, 2023
1 parent 6d2e6d7 commit bea9c54
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
9 changes: 7 additions & 2 deletions layouts/_default/list.algolia.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
{{- $section := $.Site.GetPage "section" .Section }}
{{- range .Site.AllPages -}}
{{- if or (and (.IsDescendant $section) (and (not .Draft) (and (not .Params.private) (not .Params.empty_node)))) $section.IsHome -}}
{{ if eq .Section "tutorials" }}
{{- if not (.Params.cost) -}}
{{ errorf "No cost on tutorial: %s" .Title }}
{{- end -}}
{{- $.Scratch.Add "index"
(dict
"objectID" .File.UniqueID
"id" .File.UniqueID
"date" .Date.UTC.Unix
"description" .Description
"expirydate" .ExpiryDate.UTC.Unix
Expand All @@ -29,9 +33,10 @@
"viamservices" (intersect (.Params.viamresources) (slice "data" "motion" "frame_system" "mlmodel" "navigation" "base_rc" "sensors" "slam" "vision"))
"viamcomponents" (intersect (.Params.viamresources) (slice "arm" "base" "board" "camera" "encoder" "gantry" "gripper" "input_controller" "motor" "movement_sensor" "sensor" "servo"))
"level" .Params.level
"cost" .Params.cost
"cost" (int (.Params.cost))
"content" ( .Plain | safeHTML | truncate 8000 )
)}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $.Scratch.Get "index" | jsonify -}}
8 changes: 2 additions & 6 deletions layouts/docs/tutorials.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<div id="languages-list"></div>
<div id="components-list"></div>
<div id="services-list"></div>
<div id="level-list"></div>
<div id="cost-range"></div>
</div>
<!-- {{ partial "sidebar.html" . }} -->
Expand All @@ -35,12 +36,7 @@ <h1>{{ .Title }}</h1>

{{ partial "scripts.html" . }}

<!-- search only version -->
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/algoliasearch-lite.umd.js"
integrity="sha256-qzlNbRtZWHoUV5I2mI2t9QR7oYXlS9oNctX+0pECXI0="
crossorigin="anonymous"
></script>
<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>
<script src="../js/tutorials.js"></script>
Expand Down
32 changes: 30 additions & 2 deletions static/js/tutorials.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
const { algoliasearch, instantsearch } = window;
const { TypesenseInstantSearchAdapter, instantsearch } = window;

const searchClient = algoliasearch('1CE6L976W0', '69b45c725273606d93690c9e89c56ad3');
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: "title,description",
},
});
const searchClient = typesenseInstantsearchAdapter.searchClient;

const search = instantsearch({
indexName: 'tutorials',
Expand Down Expand Up @@ -61,19 +80,28 @@ search.addWidgets([
})(instantsearch.widgets.refinementList)({
container: '#components-list',
attribute: 'viamcomponents',
operator: 'and'
}),
instantsearch.widgets.panel({
templates: { header: 'Services' },
})(instantsearch.widgets.refinementList)({
container: '#services-list',
attribute: 'viamservices',
operator: 'and'
}),
instantsearch.widgets.panel({
templates: { header: 'Approximate cost' },
})(instantsearch.widgets.rangeInput)({
container: '#cost-range',
attribute: 'cost',
}),
instantsearch.widgets.panel({
templates: { header: 'Level' },
})(instantsearch.widgets.refinementList)({
container: '#level-list',
attribute: 'level',
operator: 'and'
}),
instantsearch.widgets.pagination({
container: '#pagination',
}),
Expand Down

0 comments on commit bea9c54

Please sign in to comment.