Skip to content

Commit e627aad

Browse files
authored
Merge pull request #52590 from lmktfy/20250929_docsy_body_end_partial
Move sidebar splitter to end of page source
2 parents 853d8ea + 2a22dbe commit e627aad

File tree

4 files changed

+32
-31
lines changed

4 files changed

+32
-31
lines changed

assets/js/sidebar-tree.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

layouts/partials/hooks/body-end.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,37 @@
11
{{ with .Site.Params.algolia_docsearch }}
22
<!-- scripts for algolia docsearch -->
33
{{ end }}
4+
{{/* sidebar splitter */}}
5+
<!--script src="https://unpkg.com/split.js/dist/split.min.js"></script-->
6+
<script src="/js/split-1.6.0.js" integrity="sha384-0blL3GqHy6+9fw0cyY2Aoiwg4onHAtslAs4OkqZY7UQBrR65/K4gI+hxLdWDrjpz"></script>
7+
<script>
8+
let splitInstance = null;
9+
10+
function enableSplitter(mediaQuery) {
11+
if (mediaQuery.matches) {
12+
if (!splitInstance) {
13+
splitInstance = Split(["#sidebarnav", "#maindoc"], {
14+
sizes: [20, 80],
15+
minSize: 100,
16+
});
17+
}
18+
} else {
19+
if (splitInstance) {
20+
splitInstance.destroy();
21+
splitInstance = null;
22+
}
23+
}
24+
}
25+
26+
const screenWidthMediaQuery = window.matchMedia("(min-width: 768px)");
27+
28+
const eleNav = document.getElementById("sidebarnav");
29+
if (eleNav !== null) {
30+
enableSplitter(screenWidthMediaQuery);
31+
screenWidthMediaQuery.addListener(enableSplitter);
32+
}
33+
</script>
34+
435
{{/* copy-and-paste helper for codenew shortcode */}}
536
{{- if or (.HasShortcode "code_sample") (.HasShortcode "code") (.HasShortcode "codenew") -}}
637
{{- $toastrJs := resources.Get "js/toastr-2.1.4.min.js" | minify | fingerprint -}}

layouts/partials/hooks/head-end.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,5 @@
109109
{{ with .Params.js }}{{ range (split . ",") }}<script src="{{ (trim . " ") | relURL }}"></script><!-- custom js added -->
110110
{{ end }}{{ else }}<!-- no custom js detected -->{{ end }}
111111

112-
<!--for the splitter-->
113-
<!--script src="https://unpkg.com/split.js/dist/split.min.js"></script-->
114-
<script src="/js/split-1.6.0.js" integrity="sha384-0blL3GqHy6+9fw0cyY2Aoiwg4onHAtslAs4OkqZY7UQBrR65/K4gI+hxLdWDrjpz"></script>
115-
116112
{{- $legacyScriptJs := resources.Get "js/legacy-script.js" -}}
117113
<script src="{{ $legacyScriptJs.RelPermalink }}"></script>

layouts/partials/scripts.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@
2929
{{ $jsBase := resources.Get "js/base.js" }}
3030
{{ $jsAnchor := resources.Get "js/anchor.js" }}
3131
{{ $jsNav := resources.Get "js/nav.js" | resources.ExecuteAsTemplate "js/nav.js" .Site.Params }}
32-
{{ $jsSidebarTree := resources.Get "js/sidebar-tree.js" | resources.ExecuteAsTemplate "js/sidebar-tree.js" .Site.Params }}
3332
{{ $jsSearch := resources.Get "js/search.js" | resources.ExecuteAsTemplate "js/search.js" .Site.Home }}
3433
{{ if .Site.Params.offlineSearch }}
3534
{{ $jsSearch = resources.Get "js/offline-search.js" }}
3635
{{/* Revisit this if / when either of https://github.com/google/docsy/issues/2194 and https://github.com/google/docsy/pull/1512 are closed */}}
3736
{{ else if .Site.Params.customSearch }}
3837
{{ $jsSearch = resources.Get "js/custom-search.js" }}
3938
{{ end }}
40-
{{ $js := (slice $jsBs $jsBase $jsAnchor $jsNav $jsSidebarTree $jsSearch) | resources.Concat "js/main.js" -}}
39+
{{ $js := (slice $jsBs $jsBase $jsAnchor $jsNav $jsSearch) | resources.Concat "js/main.js" -}}
4140
{{ if hugo.IsProduction -}}
4241
{{ $js := $js | minify | fingerprint -}}
4342
<script src="{{ $js.RelPermalink }}" integrity="{{ $js.Data.Integrity }}" crossorigin="anonymous"></script>

0 commit comments

Comments
 (0)