From 987f25700960a2d1a59ac7c522e7fb2a91edd0a9 Mon Sep 17 00:00:00 2001 From: Congon4tor Date: Fri, 3 Jan 2025 01:09:11 +0100 Subject: [PATCH 1/5] Fixes language UI --- theme/css/chrome.css | 17 +++++++++++++++++ theme/index.hbs | 7 ++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/theme/css/chrome.css b/theme/css/chrome.css index 17e5411639..4fc0b2a710 100644 --- a/theme/css/chrome.css +++ b/theme/css/chrome.css @@ -182,6 +182,13 @@ body.sidebar-visible #menu-bar { } /* Languages Menu Popup */ + +@media only screen and (max-width:799px) { + #menubar-languages-toggle span { + display: none !important; + } +} + #menubar-languages-toggle { position: relative; } @@ -243,6 +250,11 @@ html:not(.js) .left-buttons button { cursor: pointer; color: var(--fg); } +@media only screen and (max-width:799px) { + .menu-title { + font-size: 1.4rem; + } +} .menu-bar, .menu-bar:visited, @@ -632,6 +644,11 @@ ul#searchresults li a span.teaser em { color: var(--sidebar-fg); } } +@media only screen and (min-width:1440px) { + #sidebar-toggle{ + display: none !important; + } +} @media only screen and (max-width:549px) { .sidebar { position: fixed; diff --git a/theme/index.hbs b/theme/index.hbs index 419bb6e7aa..683ea99c19 100644 --- a/theme/index.hbs +++ b/theme/index.hbs @@ -176,10 +176,12 @@ From 78232d3f36dc1ef3d59276fa79fa984ce9ea4362 Mon Sep 17 00:00:00 2001 From: Congon4tor Date: Fri, 3 Jan 2025 01:46:36 +0100 Subject: [PATCH 2/5] Add robots.txt --- src/robots.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/robots.txt diff --git a/src/robots.txt b/src/robots.txt new file mode 100644 index 0000000000..025b9346b4 --- /dev/null +++ b/src/robots.txt @@ -0,0 +1,4 @@ +Sitemap: https://www.hacktricks.wiki/sitemap.xml + +User-agent: * +Disallow: \ No newline at end of file From 098f393d35f6c3553b7cb8072609858896adebba Mon Sep 17 00:00:00 2001 From: Congon4tor Date: Fri, 3 Jan 2025 02:52:56 +0100 Subject: [PATCH 3/5] Add read time to all pages --- hacktricks-preprocessor.py | 8 +++++++- src/README.md | 6 ------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/hacktricks-preprocessor.py b/hacktricks-preprocessor.py index 37f5491011..d65d55a3fb 100644 --- a/hacktricks-preprocessor.py +++ b/hacktricks-preprocessor.py @@ -67,6 +67,12 @@ def ref(matchobj): return result +def add_read_time(content): + regex = r'(# .*(?=\n))' + new_content = re.sub(regex, lambda x: x.group(0) + "\n\nReading time: {{ #reading_time }}", content) + return new_content + + def iterate_chapters(sections): if isinstance(sections, dict) and "PartTitle" in sections: # Not a chapter section return @@ -91,12 +97,12 @@ def iterate_chapters(sections): logger.debug(f"Context: {context}") - for chapter in iterate_chapters(book['sections']): logger.debug(f"Chapter: {chapter['path']}") current_chapter = chapter regex = r'{{[\s]*#ref[\s]*}}(?:\n)?([^\\\n]*)(?:\n)?{{[\s]*#endref[\s]*}}' new_content = re.sub(regex, ref, chapter['content']) + new_content = add_read_time(new_content) chapter['content'] = new_content content = json.dumps(book) diff --git a/src/README.md b/src/README.md index 01b146fd1b..58f0348214 100644 --- a/src/README.md +++ b/src/README.md @@ -1,7 +1,5 @@ # HackTricks Cloud -Reading time: {{ #reading_time }} - {{#include ./banners/hacktricks-training.md}}
@@ -34,7 +32,3 @@ _Hacktricks logos & motion designed by_ [_@ppiernacho_](https://www.instagram.co ![HackTricks Cloud Github Stats](https://repobeats.axiom.co/api/embed/1dfdbb0435f74afa9803cd863f01daac17cda336.svg) {{#include ./banners/hacktricks-training.md}} - - - - From 804758840b1d7ee861f8dd20fcedac489b61ecbd Mon Sep 17 00:00:00 2001 From: Congon4tor Date: Fri, 3 Jan 2025 03:30:47 +0100 Subject: [PATCH 4/5] Fix page index with links --- theme/pagetoc.js | 96 ++++++++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 44 deletions(-) diff --git a/theme/pagetoc.js b/theme/pagetoc.js index 5962db9f38..a51ea29ae8 100644 --- a/theme/pagetoc.js +++ b/theme/pagetoc.js @@ -1,68 +1,76 @@ -let scrollTimeout; +let scrollTimeout const listenActive = () => { - const elems = document.querySelector(".pagetoc").children; - [...elems].forEach(el => { + const elems = document.querySelector(".pagetoc").children + ;[...elems].forEach((el) => { el.addEventListener("click", (event) => { - clearTimeout(scrollTimeout); - [...elems].forEach(el => el.classList.remove("active")); - el.classList.add("active"); + clearTimeout(scrollTimeout) + ;[...elems].forEach((el) => el.classList.remove("active")) + el.classList.add("active") // Prevent scroll updates for a short period scrollTimeout = setTimeout(() => { - scrollTimeout = null; - }, 100); // Adjust timing as needed - }); - }); -}; + scrollTimeout = null + }, 100) // Adjust timing as needed + }) + }) +} -const getPagetoc = () => document.querySelector(".pagetoc") || autoCreatePagetoc(); +const getPagetoc = () => + document.querySelector(".pagetoc") || autoCreatePagetoc() const autoCreatePagetoc = () => { - const main = document.querySelector("#content > main"); + const main = document.querySelector("#content > main") const content = Object.assign(document.createElement("div"), { - className: "content-wrap" - }); - content.append(...main.childNodes); - main.prepend(content); - main.insertAdjacentHTML("afterbegin", '
'); - return document.querySelector(".pagetoc"); -}; + className: "content-wrap", + }) + content.append(...main.childNodes) + main.prepend(content) + main.insertAdjacentHTML( + "afterbegin", + '
' + ) + return document.querySelector(".pagetoc") +} const updateFunction = () => { - if (scrollTimeout) return; // Skip updates if within the cooldown period from a click - const headers = [...document.getElementsByClassName("header")]; - const scrolledY = window.scrollY; - let lastHeader = null; + if (scrollTimeout) return // Skip updates if within the cooldown period from a click + const headers = [...document.getElementsByClassName("header")] + const scrolledY = window.scrollY + let lastHeader = null // Find the last header that is above the current scroll position for (let i = headers.length - 1; i >= 0; i--) { if (scrolledY >= headers[i].offsetTop) { - lastHeader = headers[i]; - break; + lastHeader = headers[i] + break } } - const pagetocLinks = [...document.querySelector(".pagetoc").children]; - pagetocLinks.forEach(link => link.classList.remove("active")); + const pagetocLinks = [...document.querySelector(".pagetoc").children] + pagetocLinks.forEach((link) => link.classList.remove("active")) if (lastHeader) { - const activeLink = pagetocLinks.find(link => lastHeader.href === link.href); - if (activeLink) activeLink.classList.add("active"); + const activeLink = pagetocLinks.find( + (link) => lastHeader.href === link.href + ) + if (activeLink) activeLink.classList.add("active") } -}; +} -window.addEventListener('load', () => { - const pagetoc = getPagetoc(); - const headers = [...document.getElementsByClassName("header")]; - headers.forEach(header => { +window.addEventListener("load", () => { + const pagetoc = getPagetoc() + const headers = [...document.getElementsByClassName("header")] + headers.forEach((header) => { const link = Object.assign(document.createElement("a"), { textContent: header.text, href: header.href, - className: `pagetoc-${header.parentElement.tagName}` - }); - pagetoc.appendChild(link); - }); - updateFunction(); - listenActive(); - window.addEventListener("scroll", updateFunction); -}); - + className: `pagetoc-${header.parentElement.tagName}`, + }) + if (header.parentElement.querySelectorAll("a").length === 2) { + link.textContent = header.parentElement.querySelectorAll("a")[1].text + } + pagetoc.appendChild(link) + }) + updateFunction() + listenActive() + window.addEventListener("scroll", updateFunction) +}) From e4141fd3c7b59ef868e0e3b34199cf0d72205b37 Mon Sep 17 00:00:00 2001 From: SirBroccoli Date: Fri, 3 Jan 2025 11:42:03 +0100 Subject: [PATCH 5/5] Update translator.py --- scripts/translator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/translator.py b/scripts/translator.py index 12d3f92b2c..d112e9fd45 100644 --- a/scripts/translator.py +++ b/scripts/translator.py @@ -226,7 +226,7 @@ def copy_dirs(source_path, dest_path): print(f"Copied .gitbook folder from {source_folder} to {destination_folder}") def copy_files(source_path, dest_path): - file_names = ["src/SUMMARY.md", "hacktricks-preprocessor.py", "book.toml", ".gitignore"] + file_names = ["src/SUMMARY.md", "hacktricks-preprocessor.py", "book.toml", ".gitignore", "src/robots.txt"] for file_name in file_names: source_filepath = os.path.join(source_path, file_name) dest_filepath = os.path.join(dest_path, file_name)