Skip to content

Commit

Permalink
Fix js for staging (#3823)
Browse files Browse the repository at this point in the history
  • Loading branch information
npentrel authored Jan 9, 2025
1 parent ec8d308 commit 744df6c
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 246 deletions.
191 changes: 0 additions & 191 deletions assets/js/howtos.js

This file was deleted.

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="{{url}}"><code>{{#helpers.highlight}}{ "attribute": "model" }{{/helpers.highlight}}</code></a></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="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="{{url}}"><code>{{#helpers.highlight}}{ "attribute": "model" }{{/helpers.highlight}}</code></a></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="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="{{url}}"><code>{{#helpers.highlight}}{ "attribute": "model_id" }{{/helpers.highlight}}</code></a></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_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="{{url}}"><code>{{#helpers.highlight}}{ "attribute": "model_id" }{{/helpers.highlight}}</code></a></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_id" }{{/helpers.highlight}}</code></a></p></div>
<div class="description">{{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}}</div>
`;

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

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

Expand Down Expand Up @@ -97,7 +99,7 @@ search.addWidgets([
templates: {
item: `
<div class="col tutorial hover-card {{resource}}">
<a href="{{relpermalink}}" target="_blank">
<a href="` + params.baseURL.substr(-1) === '/' ? params.baseURL.slice(0, -1) : params.baseURL +`{{relpermalink}}" target="_blank">
{{#webm}}
<div class="hover-card-video">
<div>
Expand Down
8 changes: 0 additions & 8 deletions layouts/docs/landing.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,5 @@

{{ 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: 13 additions & 1 deletion layouts/docs/tutorials.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,20 @@ <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: 12 additions & 11 deletions layouts/partials/scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,21 @@
<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 744df6c

Please sign in to comment.