diff --git a/book.toml b/book.toml
index 55f8eeb4f03..3d588387c78 100644
--- a/book.toml
+++ b/book.toml
@@ -22,6 +22,7 @@ after = ["links"]
[preprocessor.hacktricks]
command = "python3 ./hacktricks-preprocessor.py"
+env = "prod"
[output.html]
additional-css = ["theme/pagetoc.css", "theme/tabs.css"]
diff --git a/hacktricks-preprocessor.py b/hacktricks-preprocessor.py
index 37f54910110..fedfdef99b4 100644
--- a/hacktricks-preprocessor.py
+++ b/hacktricks-preprocessor.py
@@ -30,14 +30,16 @@ def ref(matchobj):
href = matchobj.groups(0)[0].strip()
title = href
if href.startswith("http://") or href.startswith("https://"):
- # pass
- try:
- raw_html = str(urlopen(Request(href, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0'})).read())
- match = re.search('
(.*?)', raw_html)
- title = match.group(1) if match else href
- except Exception as e:
- logger.debug(f'Error opening URL {href}: {e}')
- pass #nDont stop on broken link
+ if context['config']['preprocessor']['hacktricks']['env'] == 'dev':
+ pass
+ else:
+ try:
+ raw_html = str(urlopen(Request(href, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0'})).read())
+ match = re.search('(.*?)', raw_html)
+ title = match.group(1) if match else href
+ except Exception as e:
+ logger.debug(f'Error opening URL {href}: {e}')
+ pass #nDont stop on broken link
else:
try:
if href.endswith("/"):
@@ -90,7 +92,7 @@ def iterate_chapters(sections):
context, book = json.load(sys.stdin)
logger.debug(f"Context: {context}")
-
+ logger.debug(f"Env: {context['config']['preprocessor']['hacktricks']['env']}")
for chapter in iterate_chapters(book['sections']):
logger.debug(f"Chapter: {chapter['path']}")
diff --git a/theme/book.js b/theme/book.js
index 1c8d7728706..ccba5040417 100644
--- a/theme/book.js
+++ b/theme/book.js
@@ -590,6 +590,61 @@ function playground_text(playground, hidden = true) {
});
})();
+
+(function menubarLanguage() {
+ var menubarLanguageToggleButton = document.getElementById('menubar-languages-toggle');
+ var menubarLanguagePopup = document.getElementById('menubar-languages-popup');
+ var languageButtons = menubarLanguagePopup.querySelectorAll('.menu-bar-link');
+
+ function showLanguage() {
+ menubarLanguagePopup.style.display = 'flex';
+ menubarLanguageToggleButton.setAttribute('aria-expanded', true);
+ }
+
+ function hideLanguage() {
+ menubarLanguagePopup.style.display = 'none';
+ menubarLanguageToggleButton.setAttribute('aria-expanded', false);
+ menubarLanguageToggleButton.focus();
+ }
+
+ menubarLanguageToggleButton.addEventListener('click', function () {
+ if (menubarLanguagePopup.style.display === 'flex') {
+ hideLanguage();
+ } else {
+ showLanguage();
+ }
+ });
+
+ menubarLanguagePopup.addEventListener('focusout', function(e) {
+ // e.relatedTarget is null in Safari and Firefox on macOS (see workaround below)
+ if (!!e.relatedTarget && !menubarLanguageToggleButton.contains(e.relatedTarget) && !menubarLanguagePopup.contains(e.relatedTarget)) {
+ hideLanguage();
+ }
+ });
+
+ // 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) {
+ if (menubarLanguagePopup.style.display === 'block' && !menubarLanguageToggleButton.contains(e.target) && !menubarLanguagePopup.contains(e.target)) {
+ hideLanguage();
+ }
+ });
+
+ languageButtons.forEach((btn) => {
+ btn.addEventListener('click', function(e) {
+ const regex = /(?:(?:\/)+(?[a-z]{2}(?=\/|$)))?(?(?:\/)*.*)?/g
+ var match = regex.exec(window.location.pathname)
+
+ var path = match.groups.path
+ console.log(`Path: ${path} ${typeof path}`)
+
+ const lang = match.groups.lang
+ console.log(`Lang: ${lang}`)
+
+ window.location = `/${e.target.id}${path}${window.location.hash}`
+ });
+ })
+})();
+
(function chapterNavigation() {
document.addEventListener('keydown', function (e) {
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { return; }
diff --git a/theme/css/chrome.css b/theme/css/chrome.css
index 8cbda7c6936..ead7ee8812f 100644
--- a/theme/css/chrome.css
+++ b/theme/css/chrome.css
@@ -83,6 +83,13 @@ body.sidebar-visible #menu-bar {
}
}
+.right-buttons .icons {
+ display: flex;
+ flex-direction: row;
+ flex-wrap: wrap;
+ column-gap: 0.5rem;
+}
+
.icon-button {
border: none;
background: var(--bg);
@@ -139,10 +146,13 @@ body.sidebar-visible #menu-bar {
/* Collapse Menu Popup */
+#menubar-collapse-toggle {
+ position: relative;
+}
#menubar-collapse-popup {
position: absolute;
- right: 30px;
- top: var(--menu-bar-height);
+ right: 0px;
+ top: 35px;
z-index: 105;
border-radius: 5px;
font-size: 14px;
@@ -172,6 +182,44 @@ body.sidebar-visible #menu-bar {
background-color: var(--theme-hover);
}
+/* Languages Menu Popup */
+#menubar-languages-toggle {
+ position: relative;
+}
+
+#menubar-languages-popup {
+ position: absolute;
+ right: 0px;
+ top: 35px;
+ z-index: 105;
+ border-radius: 5px;
+ font-size: 14px;
+ color: var(--fg);
+ background: var(--bg);
+ border: 1px solid var(--table-border-color);
+ margin: 0;
+ padding: 0px;
+ display: none;
+ flex-direction: column;
+ max-height: 300px;
+ width: 150px;
+ overflow: scroll;
+}
+#menubar-languages-popup .menu-bar-link {
+ border: 0;
+ margin: 0;
+ padding: 8px 20px;
+ line-height: 25px;
+ white-space: nowrap;
+ text-align: start;
+ cursor: pointer;
+ color: inherit;
+ background: inherit;
+ font-size: inherit;
+}
+#menubar-languages-popup .menu-bar-link:hover {
+ background-color: var(--theme-hover);
+}
.left-buttons {
display: flex;
diff --git a/theme/index.hbs b/theme/index.hbs
index ecd2565f4a1..95c964391db 100644
--- a/theme/index.hbs
+++ b/theme/index.hbs
@@ -144,34 +144,60 @@