Skip to content

Commit

Permalink
Merge pull request #133 from HackTricks-wiki/robots-txt
Browse files Browse the repository at this point in the history
Add robots.txt
  • Loading branch information
carlospolop authored Jan 3, 2025
2 parents bdcf1cd + 8047588 commit 9cd4cd6
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 51 deletions.
8 changes: 7 additions & 1 deletion hacktricks-preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,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
Expand All @@ -93,12 +99,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)
Expand Down
6 changes: 0 additions & 6 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# HackTricks Cloud

Reading time: {{ #reading_time }}

{{#include ./banners/hacktricks-training.md}}

<figure><img src="images/cloud.gif" alt=""><figcaption></figcaption></figure>
Expand Down Expand Up @@ -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}}




4 changes: 4 additions & 0 deletions src/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Sitemap: https://www.hacktricks.wiki/sitemap.xml

User-agent: *
Disallow:
96 changes: 52 additions & 44 deletions theme/pagetoc.js
Original file line number Diff line number Diff line change
@@ -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", '<div class="sidetoc"><nav class="pagetoc"></nav></div>');
return document.querySelector(".pagetoc");
};
className: "content-wrap",
})
content.append(...main.childNodes)
main.prepend(content)
main.insertAdjacentHTML(
"afterbegin",
'<div class="sidetoc"><nav class="pagetoc"></nav></div>'
)
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)
})

0 comments on commit 9cd4cd6

Please sign in to comment.