From 76d0ea3113933da30c1251e8c8b7016a677dfa42 Mon Sep 17 00:00:00 2001 From: johannst Date: Thu, 7 Nov 2024 22:05:24 +0000 Subject: deploy: 8c7f8b75acf4eb4fc0e8d606cffa4bcdae865606 --- toc.js | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 toc.js (limited to 'toc.js') diff --git a/toc.js b/toc.js new file mode 100644 index 0000000..bd20cc3 --- /dev/null +++ b/toc.js @@ -0,0 +1,70 @@ +// Populate the sidebar +// +// This is a script, and not included directly in the page, to control the total size of the book. +// The TOC contains an entry for each page, so if each page includes a copy of the TOC, +// the total size of the page becomes O(n**2). +class MDBookSidebarScrollbox extends HTMLElement { + constructor() { + super(); + } + connectedCallback() { + this.innerHTML = '
  1. Introduction
  2. Shells
    1. zsh
    2. bash
    3. fish
  3. CLI foo
    1. awk
    2. cut
    3. sed
    4. column
    5. sort
    6. tr
    7. tac
    8. rev
    9. paste
  4. Tools
    1. tmux
    2. screen
    3. emacs
    4. gpg
    5. radare2
    6. qemu
    7. pacman
    8. dot
    9. ffmpeg
    10. gnuplot
    11. restic
    12. qrencode
  5. Process management & inspection
    1. lsof
    2. pidstat
    3. pgrep
    4. ps
    5. pmap
    6. pstack
    7. taskset
    8. nice
  6. Trace and Profile
    1. time
    2. strace
    3. ltrace
    4. perf
    5. OProfile
    6. callgrind
    7. valgrind
  7. Debug
    1. gdb
    2. gdbserver
  8. Binary
    1. od
    2. xxd
    3. readelf
    4. objdump
    5. nm
  9. Development
    1. c++filt
    2. c++
    3. glibc
    4. gcc
    5. git
    6. cmake
    7. make
    8. ld.so
    9. symbol versioning
    10. python
    11. gcov
    12. pgo
  10. Linux
    1. systemd
    2. coredump
    3. ptrace_scope
    4. cryptsetup
    5. swap
    6. input
    7. acl
    8. zfs
    9. cpufreq
    10. cups
  11. Network
    1. ssh
    2. ss
    3. tcpdump
    4. tshark
    5. firewall-cmd
    6. nftables
  12. Web
    1. html
    2. css
    3. chartjs
    4. plotly
  13. Arch
    1. x86_64
    2. armv8
    3. arm64
    4. armv7
    5. riscv
'; + // Set the current, active page, and reveal it if it's hidden + let current_page = document.location.href.toString(); + if (current_page.endsWith("/")) { + current_page += "index.html"; + } + var links = Array.prototype.slice.call(this.querySelectorAll("a")); + var l = links.length; + for (var i = 0; i < l; ++i) { + var link = links[i]; + var href = link.getAttribute("href"); + if (href && !href.startsWith("#") && !/^(?:[a-z+]+:)?\/\//.test(href)) { + link.href = path_to_root + href; + } + // The "index" page is supposed to alias the first chapter in the book. + if (link.href === current_page || (i === 0 && path_to_root === "" && current_page.endsWith("/index.html"))) { + link.classList.add("active"); + var parent = link.parentElement; + if (parent && parent.classList.contains("chapter-item")) { + parent.classList.add("expanded"); + } + while (parent) { + if (parent.tagName === "LI" && parent.previousElementSibling) { + if (parent.previousElementSibling.classList.contains("chapter-item")) { + parent.previousElementSibling.classList.add("expanded"); + } + } + parent = parent.parentElement; + } + } + } + // Track and set sidebar scroll position + this.addEventListener('click', function(e) { + if (e.target.tagName === 'A') { + sessionStorage.setItem('sidebar-scroll', this.scrollTop); + } + }, { passive: true }); + var sidebarScrollTop = sessionStorage.getItem('sidebar-scroll'); + sessionStorage.removeItem('sidebar-scroll'); + if (sidebarScrollTop) { + // preserve sidebar scroll position when navigating via links within sidebar + this.scrollTop = sidebarScrollTop; + } else { + // scroll sidebar to current active section when navigating via "next/previous chapter" buttons + var activeSection = document.querySelector('#sidebar .active'); + if (activeSection) { + activeSection.scrollIntoView({ block: 'center' }); + } + } + // Toggle buttons + var sidebarAnchorToggles = document.querySelectorAll('#sidebar a.toggle'); + function toggleSection(ev) { + ev.currentTarget.parentElement.classList.toggle('expanded'); + } + Array.from(sidebarAnchorToggles).forEach(function (el) { + el.addEventListener('click', toggleSection); + }); + } +} +window.customElements.define("mdbook-sidebar-scrollbox", MDBookSidebarScrollbox); -- cgit v1.2.3