Skip to content

Commit 309ed59

Browse files
authored
Load sidemenu navigation via jQuery.load (#83)
* load sidemenu navigation via jQuery.load * Set rootPath for JavaScript * Generate new navigation.html for JS * Generate single navigations for each Rails version Single navigation.html instead of _includes/navigation.html * load each navigations
1 parent e2a8918 commit 309ed59

File tree

11 files changed

+25
-22
lines changed

11 files changed

+25
-22
lines changed

Rakefile

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,11 @@ def generate_src(target_version: nil)
6666
cd target_dir do
6767
cp INDEX_HTML, 'index.html'
6868

69-
if target_version.nil?
70-
mv 'navigation.html', '_includes/navigation.html', force: true
71-
else
72-
# Replace absolute path in navigation.html
73-
content = File.read("navigation.html")
74-
content.gsub!("<a href=\"/", "<a href=\"/#{target_version}/")
75-
File.write("navigation.html", content)
69+
return if target_version.nil?
7670

77-
mv 'navigation.html', "../_includes/navigation#{target_version}.html", force: true
78-
end
71+
# Replace absolute path in navigation.html
72+
content = File.read("navigation.html")
73+
content.gsub!("<a href=\"/", "<a href=\"/#{target_version}/")
74+
File.write("navigation.html", content)
7975
end
8076
end

_config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ defaults:
2525
version: 6.1
2626
image: https://avatars.githubusercontent.com/u/4223
2727
toc: true
28+
root_path: '/'
2829
- scope:
2930
path: "6.0"
3031
values:
3132
version: 6.0
33+
root_path: '/6.0/'
3234
- scope:
3335
path: "5.2"
3436
values:
3537
version: 5.2
38+
root_path: '/5.2/'
File renamed without changes.

src/6.0/navigation.html

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/_includes/.keep

Whitespace-only changes.

src/_includes/navigation.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/_includes/navigation6.0.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/_includes/navigation6.1.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/_layouts/default.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
gtag('js', new Date());
1919

2020
gtag('config', 'UA-134470810-1');
21+
22+
window.config = {
23+
rootPath: "{{ page.root_path }}"
24+
}
2125
</script>
2226
</head>
2327
<body>
@@ -49,8 +53,7 @@
4953
<div class="container-fluid">
5054
<div class="row">
5155
<nav class="col-12 col-md-3 col-xl-2 d-none d-md-block bg-light sidebar-sticky">
52-
<div class="sidebar-content">
53-
{%- include_cached navigation{{ page.version }}.html -%}
56+
<div id="navigation" class="sidebar-content">
5457
</div>
5558
</nav>
5659

src/assets/js/app.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ $(() => {
66
// highlight.js
77
hljs.highlightAll();
88

9-
$(".sidebar-sticky .icon").on("click", function (e) {
10-
$(this).siblings("ul").toggle();
11-
this.classList.toggle("icon-opened");
12-
});
13-
$(`.sidebar-content a[href='${window.location.pathname}']`)
14-
.attr("class", "active-link")
15-
.parents('ul')
16-
.show();
9+
$("#navigation").load(`${config.rootPath}navigation.html`, function() {
10+
$(".sidebar-sticky .icon").on("click", function (e) {
11+
$(this).siblings("ul").toggle();
12+
this.classList.toggle("icon-opened");
13+
});
14+
$(`.sidebar-content a[href='${window.location.pathname}']`)
15+
.attr("class", "active-link")
16+
.parents('ul')
17+
.show();
18+
})
1719
});

0 commit comments

Comments
 (0)