Skip to content

Commit

Permalink
fixed breadcrumbs
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Gadorek committed Jan 8, 2025
1 parent 8b0e7a8 commit 4bbbadc
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Setup mdBook
uses: peaceiris/actions-mdbook@v2
with:
mdbook-version: "latest"
mdbook-version: "0.4.40"

- name: Setup Pages
uses: actions/configure-pages@v4
Expand Down
2 changes: 2 additions & 0 deletions book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ language = "en"
multilingual = false
src = "src"
title = "ESP-docs mdbook theme"
description = "https://espressif.github.io/esp-docs-mdbook/"


[build]
Expand All @@ -17,3 +18,4 @@ smart-punctuation = true
git-repository-url="https://github.com/espressif/esp-docs-mdbook"
copy-theme = true
additional-files = ["theme"]
site-url = "/esp-docs-mdbook/"
124 changes: 63 additions & 61 deletions theme/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ function playground_text(playground, hidden = true) {

function get_theme() {
var theme;
return theme;
try {
theme = localStorage.getItem("mdbook-theme");
} catch (e) {}
Expand All @@ -361,6 +362,7 @@ function playground_text(playground, hidden = true) {
}

function set_theme(theme, store = true) {
return;
let ace_theme;

if (theme == "coal" || theme == "navy") {
Expand Down Expand Up @@ -411,36 +413,36 @@ function playground_text(playground, hidden = true) {

set_theme(theme, false);

themeToggleButton.addEventListener("click", function () {
if (themePopup.style.display === "block") {
hideThemes();
} else {
showThemes();
}
});
// themeToggleButton.addEventListener("click", function () {
// if (themePopup.style.display === "block") {
// hideThemes();
// } else {
// showThemes();
// }
// });

themePopup.addEventListener("click", function (e) {
var theme;
if (e.target.className === "theme") {
theme = e.target.id;
} else if (e.target.parentElement.className === "theme") {
theme = e.target.parentElement.id;
} else {
return;
}
set_theme(theme);
});
// themePopup.addEventListener("click", function (e) {
// var theme;
// if (e.target.className === "theme") {
// theme = e.target.id;
// } else if (e.target.parentElement.className === "theme") {
// theme = e.target.parentElement.id;
// } else {
// return;
// }
// set_theme(theme);
// });

themePopup.addEventListener("focusout", function (e) {
// e.relatedTarget is null in Safari and Firefox on macOS (see workaround below)
if (
!!e.relatedTarget &&
!themeToggleButton.contains(e.relatedTarget) &&
!themePopup.contains(e.relatedTarget)
) {
hideThemes();
}
});
// themePopup.addEventListener("focusout", function (e) {
// // e.relatedTarget is null in Safari and Firefox on macOS (see workaround below)
// if (
// !!e.relatedTarget &&
// !themeToggleButton.contains(e.relatedTarget) &&
// !themePopup.contains(e.relatedTarget)
// ) {
// hideThemes();
// }
// });

// Should not be needed, but it works around an issue on macOS & iOS: https://github.com/rust-lang/mdBook/issues/628
document.addEventListener("click", function (e) {
Expand Down Expand Up @@ -527,28 +529,28 @@ function playground_text(playground, hidden = true) {
}

// Toggle sidebar
sidebarToggleButton.addEventListener("click", function sidebarToggle() {
if (body.classList.contains("sidebar-hidden")) {
var current_width = parseInt(
document.documentElement.style.getPropertyValue("--sidebar-width"),
10
);
if (current_width < 150) {
document.documentElement.style.setProperty("--sidebar-width", "150px");
}
showSidebar();
} else if (body.classList.contains("sidebar-visible")) {
hideSidebar();
} else {
if (getComputedStyle(sidebar)["transform"] === "none") {
hideSidebar();
} else {
showSidebar();
}
}
});
// sidebarToggleButton.addEventListener("click", function sidebarToggle() {
// if (body.classList.contains("sidebar-hidden")) {
// var current_width = parseInt(
// document.documentElement.style.getPropertyValue("--sidebar-width"),
// 10
// );
// if (current_width < 150) {
// document.documentElement.style.setProperty("--sidebar-width", "150px");
// }
// showSidebar();
// } else if (body.classList.contains("sidebar-visible")) {
// hideSidebar();
// } else {
// if (getComputedStyle(sidebar)["transform"] === "none") {
// hideSidebar();
// } else {
// showSidebar();
// }
// }
// });

sidebarResizeHandle.addEventListener("mousedown", initResize, false);
// sidebarResizeHandle.addEventListener("mousedown", initResize, false);

function initResize(e) {
window.addEventListener("mousemove", resize, false);
Expand Down Expand Up @@ -692,9 +694,9 @@ function playground_text(playground, hidden = true) {
(function scrollToTop() {
var menuTitle = document.querySelector(".menu-title");

menuTitle.addEventListener("click", function () {
document.scrollingElement.scrollTo({ top: 0, behavior: "smooth" });
});
// menuTitle.addEventListener("click", function () {
// document.scrollingElement.scrollTo({ top: 0, behavior: "smooth" });
// });
})();

(function controllMenu() {
Expand All @@ -703,12 +705,12 @@ function playground_text(playground, hidden = true) {
(function controllPosition() {
var scrollTop = document.scrollingElement.scrollTop;
var prevScrollTop = scrollTop;
var minMenuY = -menu.clientHeight - 50;
// var minMenuY = -menu.clientHeight - 50;
// When the script loads, the page can be at any scroll (e.g. if you reforesh it).
menu.style.top = scrollTop + "px";
// menu.style.top = scrollTop + "px";
// Same as parseInt(menu.style.top.slice(0, -2), but faster
var topCache = menu.style.top.slice(0, -2);
menu.classList.remove("sticky");
// var topCache = menu.style.top.slice(0, -2);
// menu.classList.remove("sticky");
var stickyCache = false; // Same as menu.classList.contains('sticky'), but faster
document.addEventListener(
"scroll",
Expand Down Expand Up @@ -749,11 +751,11 @@ function playground_text(playground, hidden = true) {
})();
(function controllBorder() {
function updateBorder() {
if (menu.offsetTop === 0) {
menu.classList.remove("bordered");
} else {
menu.classList.add("bordered");
}
// if (menu.offsetTop === 0) {
// menu.classList.remove("bordered");
// } else {
// menu.classList.add("bordered");
// }
}
updateBorder();
document.addEventListener("scroll", updateBorder, { passive: true });
Expand Down
7 changes: 6 additions & 1 deletion theme/css/general.css
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ h1:visited,
h2:visited {
margin-top: 0;
color: #333;
text-decoration: none;
}

h1 a,
h2 a {
text-decoration: none;
}

.requirements-list {
Expand Down Expand Up @@ -145,7 +151,6 @@ h2:visited {
}
.main-content a {
color: #404040;
text-decoration: none; /* Optional: to remove underline from links */
}

.main-content a:hover {
Expand Down
57 changes: 34 additions & 23 deletions theme/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,32 @@
<link rel="shortcut icon" href="https://www.espressif.com/sites/all/themes/espressif/favicon.ico"
type="image/vnd.microsoft.icon">
<!-- Fonts -->
<link rel="stylesheet" href="{{ path_to_root }}FontAwesome/css/font-awesome.css">
<link rel="stylesheet" href="{{ config.book.site-url }}FontAwesome/css/font-awesome.css">
{{#if copy_fonts}}
<link rel="stylesheet" href="{{ path_to_root }}fonts/fonts.css">
<link rel="stylesheet" href="{{ config.book.site-url }}fonts/fonts.css">
{{/if}}

<link rel="stylesheet" href="{{ path_to_root }}css/general.css">
<link rel="stylesheet" href="{{ site-url }}css/general.css">

<!-- Highlight.js Stylesheets -->
<link rel="stylesheet" href="{{ path_to_root }}highlight.css">
<link rel="stylesheet" href="{{ path_to_root }}tomorrow-night.css">
<link rel="stylesheet" href="{{ path_to_root }}ayu-highlight.css">
{{!-- <link rel="stylesheet" href="{{ config.book.site-url }}highlight.css">
<link rel="stylesheet" href="{{ config.book.site-url }}tomorrow-night.css">
<link rel="stylesheet" href="{{ config.book.site-url }}ayu-highlight.css"> --}}
<script>
var path_to_root = "{{ path_to_root }}";
// {{ base_path }}
// {{ base_url }}
// {{ site_url }}
var config = {
book: {
"site-url": "{{ base_path }}",
"base_url": "{{ base_url }}",
"site_url": "{{ site_url }}",
}
};
var default_theme = "esp";
</script>
<script src="{{ path_to_root }}toc.js"></script>
<script src="{{ config.book.site-url }}toc.js"></script>
</head>

<body>
Expand Down Expand Up @@ -116,7 +126,7 @@
<ul class="nav-menu">
<mdbook-sidebar-scrollbox class="sidebar-scrollbox"></mdbook-sidebar-scrollbox>
<noscript>
<iframe class="sidebar-iframe-outer" src="{{ path_to_root }}toc.html"></iframe>
<iframe class="sidebar-iframe-outer" src="{{ config.book.site-url }}toc.html"></iframe>
</noscript>
</ul>
</nav>
Expand All @@ -138,13 +148,13 @@

<div class="navigation-buttons">
{{#previous}}
<button class="nav-button"><a rel="prev" href="{{ path_to_root }}{{link}}" class="nav-chapters previous"
<button class="nav-button"><a rel="prev" href="{{ config.book.site-url }}{{link}}" class="nav-chapters previous"
title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
« Previous
</a></button>
{{/previous}}
{{#next}}
<button class="nav-button"><a rel="next prefetch" href="{{ path_to_root }}{{link}}" class="nav-chapters next"
<button class="nav-button"><a rel="next prefetch" href="{{ config.book.site-url }}{{link}}" class="nav-chapters next"
title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
Next »
</a></button>
Expand Down Expand Up @@ -204,26 +214,27 @@
{{/if}}

{{#if playground_js}}
<script src="{{ path_to_root }}ace.js"></script>
<script src="{{ path_to_root }}editor.js"></script>
<script src="{{ path_to_root }}mode-rust.js"></script>
<script src="{{ path_to_root }}theme-dawn.js"></script>
<script src="{{ path_to_root }}theme-tomorrow_night.js"></script>
<script src="{{ config.book.site-url }}ace.js"></script>
<script src="{{ config.book.site-url }}editor.js"></script>
<script src="{{ config.book.site-url }}mode-rust.js"></script>
<script src="{{ config.book.site-url }}theme-dawn.js"></script>
<script src="{{ config.book.site-url }}theme-tomorrow_night.js"></script>
{{/if}}

{{#if search_js}}
<script src="{{ path_to_root }}elasticlunr.min.js"></script>
<script src="{{ path_to_root }}mark.min.js"></script>
<script src="{{ path_to_root }}searcher.js"></script>
<script src="{{ config.book.site-url }}elasticlunr.min.js"></script>
<script src="{{ config.book.site-url }}mark.min.js"></script>
<script src="{{ config.book.site-url }}searcher.js"></script>
{{/if}}

<script src="{{ path_to_root }}clipboard.min.js"></script>
<script src="{{ path_to_root }}highlight.js"></script>
<script src="{{ path_to_root }}book.js"></script>
<script src="{{ config.book.site-url }}clipboard.min.js"></script>
<script src="{{ config.book.site-url }}highlight.js"></script>

<script src="{{ config.book.site-url }}book.js"></script>

<!-- Custom JS scripts -->
{{#each additional_js}}
<script src="{{ ../path_to_root }}{{this}}"></script>
<script src="{{ ../config.book.site-url }}{{this}}"></script>
{{/each}}

{{#if is_print}}
Expand Down Expand Up @@ -295,7 +306,7 @@
const cleanPath = path.replace(/^\/|\/index\.html$|\/$/g, '');
// Split path into components
const components = cleanPath.split('/').filter(Boolean);
const components = cleanPath.replace('{{ path_to_root }}', '').split('/').filter(Boolean);
// Get the breadcrumb list element
const breadcrumbList = document.getElementById('breadcrumb-list');
Expand Down

0 comments on commit 4bbbadc

Please sign in to comment.