Skip to content

Load sidemenu navigation via jQuery.load #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,11 @@ def generate_src(target_version: nil)
cd target_dir do
cp INDEX_HTML, 'index.html'

if target_version.nil?
mv 'navigation.html', '_includes/navigation.html', force: true
else
# Replace absolute path in navigation.html
content = File.read("navigation.html")
content.gsub!("<a href=\"/", "<a href=\"/#{target_version}/")
File.write("navigation.html", content)
return if target_version.nil?

mv 'navigation.html', "../_includes/navigation#{target_version}.html", force: true
end
# Replace absolute path in navigation.html
content = File.read("navigation.html")
content.gsub!("<a href=\"/", "<a href=\"/#{target_version}/")
File.write("navigation.html", content)
end
end
3 changes: 3 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ defaults:
version: 6.1
image: https://avatars.githubusercontent.com/u/4223
toc: true
root_path: '/'
- scope:
path: "6.0"
values:
version: 6.0
root_path: '/6.0/'
- scope:
path: "5.2"
values:
version: 5.2
root_path: '/5.2/'
File renamed without changes.
1 change: 1 addition & 0 deletions src/6.0/navigation.html

Large diffs are not rendered by default.

Empty file added src/_includes/.keep
Empty file.
1 change: 0 additions & 1 deletion src/_includes/navigation.html

This file was deleted.

1 change: 0 additions & 1 deletion src/_includes/navigation6.0.html

This file was deleted.

1 change: 0 additions & 1 deletion src/_includes/navigation6.1.html

This file was deleted.

7 changes: 5 additions & 2 deletions src/_layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
gtag('js', new Date());

gtag('config', 'UA-134470810-1');

window.config = {
rootPath: "{{ page.root_path }}"
}
</script>
</head>
<body>
Expand Down Expand Up @@ -49,8 +53,7 @@
<div class="container-fluid">
<div class="row">
<nav class="col-12 col-md-3 col-xl-2 d-none d-md-block bg-light sidebar-sticky">
<div class="sidebar-content">
{%- include_cached navigation{{ page.version }}.html -%}
<div id="navigation" class="sidebar-content">
</div>
</nav>

Expand Down
18 changes: 10 additions & 8 deletions src/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ $(() => {
// highlight.js
hljs.highlightAll();

$(".sidebar-sticky .icon").on("click", function (e) {
$(this).siblings("ul").toggle();
this.classList.toggle("icon-opened");
});
$(`.sidebar-content a[href='${window.location.pathname}']`)
.attr("class", "active-link")
.parents('ul')
.show();
$("#navigation").load(`${config.rootPath}navigation.html`, function() {
$(".sidebar-sticky .icon").on("click", function (e) {
$(this).siblings("ul").toggle();
this.classList.toggle("icon-opened");
});
$(`.sidebar-content a[href='${window.location.pathname}']`)
.attr("class", "active-link")
.parents('ul')
.show();
})
});
1 change: 1 addition & 0 deletions src/navigation.html

Large diffs are not rendered by default.