mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-07-28 14:47:17 -07:00
Fix chapter navigation links
This commit is contained in:
+6
-14
@@ -380,33 +380,25 @@
|
||||
|
||||
<nav class="nav-wrapper" aria-label="Page navigation">
|
||||
<!-- Mobile navigation buttons -->
|
||||
{{#if previous}}
|
||||
<a rel="prev" href="{{ path_to_root }}{{previous.path}}" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
||||
<a rel="prev" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left" hidden>
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
{{/if}}
|
||||
|
||||
{{#if next}}
|
||||
<a rel="next prefetch" href="{{ path_to_root }}{{next.path}}" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||||
<a rel="next prefetch" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right" hidden>
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
{{/if}}
|
||||
|
||||
<div style="clear: both"></div>
|
||||
</nav>
|
||||
|
||||
<nav class="nav-wide-wrapper" aria-label="Page navigation">
|
||||
{{#if previous}}
|
||||
<a rel="prev" href="{{ path_to_root }}{{previous.path}}" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
||||
<i class="fa fa-angle-left"></i><span style="font-size: medium; align-self: center; margin-left: 10px;">{{previous.name}}</span>
|
||||
<a rel="prev" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left" hidden>
|
||||
<i class="fa fa-angle-left"></i><span class="chapter-nav-label" style="font-size: medium; align-self: center; margin-left: 10px;"></span>
|
||||
</a>
|
||||
{{/if}}
|
||||
|
||||
{{#if next}}
|
||||
<a rel="next prefetch" href="{{ path_to_root }}{{next.path}}" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||||
<span style="font-size: medium; align-self: center; margin-right: 10px;">{{next.name}}</span><i class="fa fa-angle-right"></i>
|
||||
<a rel="next prefetch" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right" hidden>
|
||||
<span class="chapter-nav-label" style="font-size: medium; align-self: center; margin-right: 10px;"></span><i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
{{/if}}
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ class MDBookSidebarScrollbox extends HTMLElement {
|
||||
}
|
||||
}
|
||||
}
|
||||
updateChapterNavigation(links);
|
||||
// Track and set sidebar scroll position
|
||||
this.addEventListener('click', function(e) {
|
||||
if (e.target.tagName === 'A') {
|
||||
@@ -83,3 +84,84 @@ class MDBookSidebarScrollbox extends HTMLElement {
|
||||
}
|
||||
}
|
||||
window.customElements.define("mdbook-sidebar-scrollbox", MDBookSidebarScrollbox);
|
||||
|
||||
function normalizeChapterUrl(url) {
|
||||
try {
|
||||
var normalized = new URL(url, document.location.href);
|
||||
normalized.hash = "";
|
||||
normalized.search = "";
|
||||
if (normalized.pathname.endsWith("/")) {
|
||||
normalized.pathname += "index.html";
|
||||
}
|
||||
return normalized.href;
|
||||
} catch (_) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
function setChapterNavigationLink(selector, chapter) {
|
||||
var link = document.querySelector(selector);
|
||||
if (!link) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!chapter) {
|
||||
link.hidden = true;
|
||||
link.removeAttribute("href");
|
||||
return;
|
||||
}
|
||||
|
||||
link.href = chapter.href;
|
||||
link.hidden = false;
|
||||
|
||||
var label = link.querySelector(".chapter-nav-label") || link.querySelector("span");
|
||||
if (label) {
|
||||
label.textContent = chapter.title;
|
||||
}
|
||||
}
|
||||
|
||||
function updateChapterNavigation(links) {
|
||||
var current = normalizeChapterUrl(document.location.href);
|
||||
var seen = Object.create(null);
|
||||
var chapters = [];
|
||||
|
||||
links.forEach(function (link) {
|
||||
var rawHref = link.getAttribute("href");
|
||||
if (!rawHref || rawHref.startsWith("#") || link.classList.contains("external-link")) {
|
||||
return;
|
||||
}
|
||||
|
||||
var url;
|
||||
try {
|
||||
url = new URL(link.href, document.location.href);
|
||||
} catch (_) {
|
||||
return;
|
||||
}
|
||||
if (url.origin !== document.location.origin && url.protocol !== "file:") {
|
||||
return;
|
||||
}
|
||||
|
||||
var normalized = normalizeChapterUrl(url.href);
|
||||
if (!normalized || seen[normalized]) {
|
||||
return;
|
||||
}
|
||||
seen[normalized] = true;
|
||||
|
||||
chapters.push({
|
||||
href: link.href,
|
||||
key: normalized,
|
||||
title: link.textContent.trim()
|
||||
});
|
||||
});
|
||||
|
||||
var index = chapters.findIndex(function (chapter) {
|
||||
return chapter.key === current;
|
||||
});
|
||||
var previous = index > 0 ? chapters[index - 1] : null;
|
||||
var next = index >= 0 && index < chapters.length - 1 ? chapters[index + 1] : null;
|
||||
|
||||
setChapterNavigationLink(".mobile-nav-chapters.previous", previous);
|
||||
setChapterNavigationLink(".nav-chapters.previous", previous);
|
||||
setChapterNavigationLink(".mobile-nav-chapters.next", next);
|
||||
setChapterNavigationLink(".nav-chapters.next", next);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user