Skip to content

Commit 4b296a5

Browse files
committed
fix(algolia): latest version fallback to latest fixed version
Signed-off-by: Christopher Haar <christopher.haar@upbound.io>
1 parent 24f7f8b commit 4b296a5

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

themes/geekboot/layouts/partials/scripts.html

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,29 @@
99

1010
<script src="https://cdn.jsdelivr.net/npm/@docsearch/js@3"></script>
1111
<script>
12+
{{/* Which track is this page on? Records are tagged "cli" or "core" by the
13+
crawler; everything that isn't the CLI track (core, knowledge base,
14+
contributing guide) searches the "core" records. */}}
15+
{{ $track := cond (eq (.Page.Params.track | default "core") "cli") "cli" "core" }}
16+
{{ $trackLatest := cond (eq $track "cli") .Site.Params.cliLatest .Site.Params.latest }}
17+
{{ $latestLink := cond (eq $track "cli") (printf "/cli/v%s/" .Site.Params.cliLatest) (printf "/v%s/" .Site.Params.latest) }}
18+
1219
{{ $cur_ver := "" }}
13-
{{/* Only filter if we have a version parameter and it's not "0" (static pages) */}}
20+
{{/* Every version folder is indexed, so always send a version facet.
21+
Pages without a version param (the build-time /latest and /cli/latest
22+
copies, the home page) fall back to the track's latest version.
23+
Static pages (version "0": contribute guide, knowledge base) are
24+
handled separately below so their own records stay searchable. */}}
1425
{{ if and .Page.Params.version (ne .Page.Params.version "0") }}
1526
{{ if eq .Page.Params.version "master" }}
1627
{{ $cur_ver = "0.0.0-master" }}
1728
{{ else }}
1829
{{ $cur_ver = .Page.Params.version }}
1930
{{ end }}
31+
{{ else if not .Page.Params.version }}
32+
{{ $cur_ver = $trackLatest }}
2033
{{ end }}
2134

22-
{{/* Which track is this page on? Records are tagged "cli" or "core" by the
23-
crawler; everything that isn't the CLI track (core, knowledge base,
24-
contributing guide) searches the "core" records. */}}
25-
{{ $track := cond (eq (.Page.Params.track | default "core") "cli") "cli" "core" }}
26-
{{ $trackLatest := cond (eq $track "cli") .Site.Params.cliLatest .Site.Params.latest }}
27-
{{ $latestLink := cond (eq $track "cli") (printf "/cli/v%s/" .Site.Params.cliLatest) (printf "/v%s/" .Site.Params.latest) }}
28-
2935
const docSearchInstance = docsearch({
3036
container: '#docSearch',
3137
appId: '9UXKYX61NK',
@@ -34,12 +40,12 @@
3440
placeholder: 'Search the docs',
3541
searchParameters: {
3642
attributesToRetrieve: ['hierarchy.lvl0', 'hierarchy.lvl1', 'hierarchy.lvl2', 'hierarchy.lvl3', 'hierarchy.lvl4', 'hierarchy.lvl5', 'hierarchy.lvl6', 'content', 'type', 'url', 'version'],
37-
facetFilters: [['track:{{ $track }}']{{ if $cur_ver }}, ['version:{{ $cur_ver }}']{{ end }}]
43+
facetFilters: [['track:{{ $track }}']{{ if $cur_ver }}, ['version:{{ $cur_ver }}']{{ else }}, ['version:0', 'version:{{ $trackLatest }}']{{ end }}]
3844
},
3945
transformItems(items) {
4046
// Add version warning banner and badges after DOM renders
4147
setTimeout(() => {
42-
{{ if and $cur_ver (ne .Page.Params.version "master") (ne .Page.Params.version $trackLatest) }}
48+
{{ if and $cur_ver .Page.Params.version (ne .Page.Params.version "master") (ne .Page.Params.version $trackLatest) }}
4349
// Add warning banner for old version
4450
const dropdown = document.querySelector('.DocSearch-Dropdown-Container');
4551
if (dropdown && !dropdown.hasAttribute('data-version-banner-added')) {

0 commit comments

Comments
 (0)