Skip to content

Commit

Permalink
Revert "Fix js for staging (#3823)"
Browse files Browse the repository at this point in the history
This reverts commit 744df6c.
  • Loading branch information
npentrel authored Jan 9, 2025
1 parent 744df6c commit 775bcf6
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 62 deletions.
191 changes: 191 additions & 0 deletions assets/js/howtos.js
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();
});
8 changes: 4 additions & 4 deletions assets/js/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if (api == "") {
};
itemtemplate = `
<div class="type"><p><code>{{#helpers.highlight}}{ "attribute": "api" }{{/helpers.highlight}}</code></p></div>
<div class="name"><p><a href="` + params.baseURL.substr(-1) === '/' ? params.baseURL.slice(0, -1) : params.baseURL +`{{url}}"><code>{{#helpers.highlight}}{ "attribute": "model" }{{/helpers.highlight}}</code></a></p></div>
<div class="name"><p><a href="{{url}}"><code>{{#helpers.highlight}}{ "attribute": "model" }{{/helpers.highlight}}</code></a></p></div>
<div class="description">{{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}}</div>
`;
} else {
Expand All @@ -52,7 +52,7 @@ if (api == "") {
hitsPerPage: 5,
};
itemtemplate = `
<div class="name"><p><a href="` + params.baseURL.substr(-1) === '/' ? params.baseURL.slice(0, -1) : params.baseURL +`{{url}}"><code>{{#helpers.highlight}}{ "attribute": "model" }{{/helpers.highlight}}</code></a></p></div>
<div class="name"><p><a href="{{url}}"><code>{{#helpers.highlight}}{ "attribute": "model" }{{/helpers.highlight}}</code></a></p></div>
<div class="description">{{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}}</div>
`;
}
Expand Down Expand Up @@ -140,7 +140,7 @@ if (mlmodel) {
hitsPerPage: 5,
};
itemtemplateML = `
<div class="name"><p><a href="` + params.baseURL.substr(-1) === '/' ? params.baseURL.slice(0, -1) : params.baseURL +`{{url}}"><code>{{#helpers.highlight}}{ "attribute": "model_id" }{{/helpers.highlight}}</code></a></p></div>
<div class="name"><p><a href="{{url}}"><code>{{#helpers.highlight}}{ "attribute": "model_id" }{{/helpers.highlight}}</code></a></p></div>
<div class="type">{{#helpers.highlight}}{ "attribute": "type" }{{/helpers.highlight}}</div>
<div class="framework">{{#helpers.highlight}}{ "attribute": "framework" }{{/helpers.highlight}}</div>
<div class="description">{{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}}</div>
Expand Down Expand Up @@ -228,7 +228,7 @@ if (scripts) {
hitsPerPage: 5,
};
itemtemplateScripts = `
<div class="name"><p><a href="` + params.baseURL.substr(-1) === '/' ? params.baseURL.slice(0, -1) : params.baseURL +`{{url}}"><code>{{#helpers.highlight}}{ "attribute": "model_id" }{{/helpers.highlight}}</code></a></p></div>
<div class="name"><p><a href="{{url}}"><code>{{#helpers.highlight}}{ "attribute": "model_id" }{{/helpers.highlight}}</code></a></p></div>
<div class="description">{{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}}</div>
`;

Expand Down
4 changes: 1 addition & 3 deletions assets/js/tutorials.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import params from "@params";

const { TypesenseInstantSearchAdapter, instantsearch } = window;
const observer = lozad();

Expand Down Expand Up @@ -99,7 +97,7 @@ search.addWidgets([
templates: {
item: `
<div class="col tutorial hover-card {{resource}}">
<a href="` + params.baseURL.substr(-1) === '/' ? params.baseURL.slice(0, -1) : params.baseURL +`{{relpermalink}}" target="_blank">
<a href="{{relpermalink}}" target="_blank">
{{#webm}}
<div class="hover-card-video">
<div>
Expand Down
8 changes: 8 additions & 0 deletions layouts/docs/landing.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
14 changes: 1 addition & 13 deletions layouts/docs/tutorials.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 1 addition & 1 deletion layouts/partials/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<div class="td-navbar-nav-scroll ml-md-auto td-topbar-sections" id="main_navbar">
<ul>
<li><a href="https://app.viam.com/fleet/" title="Fleet" class="navsectiontop">Fleet</a></li>
<li><a href="https://app.viam.com/data/view/" title="Data" class="navsectiontop">Data</a></li>
<li><a href="https://app.viam.com/data/view" title="Data" class="navsectiontop">Data</a></li>
<li><a href="https://app.viam.com/registry/" title="Registry" class="navsectiontop">Registry</a></li>
<li><a href="{{ .Site.BaseURL }}" title="Docs" class="navsectiontop active-path">Docs</a></li>
</ul>
Expand Down
58 changes: 29 additions & 29 deletions layouts/partials/page-description.html
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 -}}
23 changes: 11 additions & 12 deletions layouts/partials/scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 775bcf6

Please sign in to comment.