From bea9c5418c0499f2bc7a1d71d2d1bb3fe7ee2940 Mon Sep 17 00:00:00 2001 From: Naomi Pentrel <5212232+npentrel@users.noreply.github.com> Date: Thu, 24 Aug 2023 22:51:55 +0100 Subject: [PATCH] Move back to typesense --- layouts/_default/list.algolia.json | 9 +++++++-- layouts/docs/tutorials.html | 8 ++------ static/js/tutorials.js | 32 ++++++++++++++++++++++++++++-- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/layouts/_default/list.algolia.json b/layouts/_default/list.algolia.json index 91bc3be6aab..1a2d2a94107 100644 --- a/layouts/_default/list.algolia.json +++ b/layouts/_default/list.algolia.json @@ -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 @@ -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 -}} \ No newline at end of file diff --git a/layouts/docs/tutorials.html b/layouts/docs/tutorials.html index 0d985dc9e9c..6fc754e0516 100644 --- a/layouts/docs/tutorials.html +++ b/layouts/docs/tutorials.html @@ -15,6 +15,7 @@
+
@@ -35,12 +36,7 @@

{{ .Title }}

{{ partial "scripts.html" . }} - - + diff --git a/static/js/tutorials.js b/static/js/tutorials.js index a9b2018241a..00d7615db99 100644 --- a/static/js/tutorials.js +++ b/static/js/tutorials.js @@ -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', @@ -61,12 +80,14 @@ 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' }, @@ -74,6 +95,13 @@ search.addWidgets([ 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', }),