From 744df6c6066cefc0485f752202a58bf1b4782fdd Mon Sep 17 00:00:00 2001 From: Naomi Pentrel <5212232+npentrel@users.noreply.github.com> Date: Thu, 9 Jan 2025 14:23:38 +0100 Subject: [PATCH] Fix js for staging (#3823) --- 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/navbar.html | 2 +- layouts/partials/page-description.html | 58 ++++---- layouts/partials/scripts.html | 23 +-- 8 files changed, 62 insertions(+), 246 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: ` -
    - -
    -
    {{title}}
    -
    - {{#description}}

    {{description}}

    {{/description}} -
    -
    -
    -
    -`, - }, - }), - 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..3485140f2e 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": "model" }{{/helpers.highlight}}

    +

    {{#helpers.highlight}}{ "attribute": "model" }{{/helpers.highlight}}

    {{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}}
    `; } else { @@ -52,7 +52,7 @@ if (api == "") { hitsPerPage: 5, }; itemtemplate = ` -

    {{#helpers.highlight}}{ "attribute": "model" }{{/helpers.highlight}}

    +

    {{#helpers.highlight}}{ "attribute": "model" }{{/helpers.highlight}}

    {{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}}
    `; } @@ -140,7 +140,7 @@ if (mlmodel) { hitsPerPage: 5, }; itemtemplateML = ` -

    {{#helpers.highlight}}{ "attribute": "model_id" }{{/helpers.highlight}}

    +

    {{#helpers.highlight}}{ "attribute": "model_id" }{{/helpers.highlight}}

    {{#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": "model_id" }{{/helpers.highlight}}

    +

    {{#helpers.highlight}}{ "attribute": "model_id" }{{/helpers.highlight}}

    {{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}}
    `; diff --git a/assets/js/tutorials.js b/assets/js/tutorials.js index 394d132772..8ff5860ec0 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: `
    - + {{#webm}}
    diff --git a/layouts/docs/landing.html b/layouts/docs/landing.html index aab8d630c8..75b635318b 100644 --- a/layouts/docs/landing.html +++ b/layouts/docs/landing.html @@ -38,13 +38,5 @@ {{ partial "scripts.html" . }} - - - - - {{ $jsTutorials := resources.Get "js/tutorials.js" }} - {{ $jsTutorials := $jsTutorials | minify }} - - diff --git a/layouts/docs/tutorials.html b/layouts/docs/tutorials.html index 0ad56c5def..91c6d7084c 100644 --- a/layouts/docs/tutorials.html +++ b/layouts/docs/tutorials.html @@ -118,8 +118,20 @@

    Javascript

    {{ $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 }} - + {{ else }} + {{- $opts := dict + "params" (dict "baseURL" .Site.BaseURL) + -}} + {{- $jsTutorials = $jsTutorials | js.Build $opts -}} + {{ $jsTutorials := $jsTutorials | minify }} + + {{ end }} diff --git a/layouts/partials/navbar.html b/layouts/partials/navbar.html index 054488c91a..5716c01bcb 100644 --- a/layouts/partials/navbar.html +++ b/layouts/partials/navbar.html @@ -24,7 +24,7 @@