From f85e36bb59a39e7e2e30433521c79f216c4504c6 Mon Sep 17 00:00:00 2001
From: Naomi Pentrel <5212232+npentrel@users.noreply.github.com>
Date: Thu, 9 Jan 2025 13:42:49 +0100
Subject: [PATCH] Try to fix js for staging
---
assets/js/howtos.js | 191 -------------------------
assets/js/models.js | 8 +-
assets/js/tutorials.js | 4 +-
layouts/docs/landing.html | 8 --
layouts/docs/tutorials.html | 14 +-
layouts/partials/page-description.html | 58 ++++----
layouts/partials/scripts.html | 23 +--
7 files changed, 61 insertions(+), 245 deletions(-)
delete mode 100644 assets/js/howtos.js
diff --git a/assets/js/howtos.js b/assets/js/howtos.js
deleted file mode 100644
index 0a6b41240c..0000000000
--- a/assets/js/howtos.js
+++ /dev/null
@@ -1,191 +0,0 @@
-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 `
-
-
-
- `;
- });
-
- container.innerHTML = `
-
- `;
- },
-);
-
-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: `
-
-`,
- },
- }),
- 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();
-});
diff --git a/assets/js/models.js b/assets/js/models.js
index 081a88aa47..403ffdc46b 100644
--- a/assets/js/models.js
+++ b/assets/js/models.js
@@ -43,7 +43,7 @@ if (api == "") {
};
itemtemplate = `
{{#helpers.highlight}}{ "attribute": "api" }{{/helpers.highlight}}
-
+
{{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}}
`;
} else {
@@ -52,7 +52,7 @@ if (api == "") {
hitsPerPage: 5,
};
itemtemplate = `
-
+
{{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}}
`;
}
@@ -140,7 +140,7 @@ if (mlmodel) {
hitsPerPage: 5,
};
itemtemplateML = `
-
+
{{#helpers.highlight}}{ "attribute": "type" }{{/helpers.highlight}}
{{#helpers.highlight}}{ "attribute": "framework" }{{/helpers.highlight}}
{{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}}
@@ -228,7 +228,7 @@ if (scripts) {
hitsPerPage: 5,
};
itemtemplateScripts = `
-
+
{{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}}
`;
diff --git a/assets/js/tutorials.js b/assets/js/tutorials.js
index 394d132772..b1eed5afd8 100644
--- a/assets/js/tutorials.js
+++ b/assets/js/tutorials.js
@@ -1,3 +1,5 @@
+import params from "@params";
+
const { TypesenseInstantSearchAdapter, instantsearch } = window;
const observer = lozad();
@@ -97,7 +99,7 @@ search.addWidgets([
templates: {
item: `