document.addEventListener("DOMContentLoaded", function () {
// Get all category links
const categoryLinks = document.querySelectorAll(".tg-post-categories > a");
const categoriesToHide = new Set();
// Iterate through all categories and identify parents
categoryLinks.forEach((link) => {
const href = link.getAttribute("href");
// Extract category hierarchy after "/category/"
const categoryPath = href.split("/category/")[1]?.split("/");
if (categoryPath && categoryPath.length > 1) {
// Mark parent categories for hiding
for (let i = 0; i < categoryPath.length - 1; i++) {
const parentCategoryPath = `/category/${categoryPath.slice(0, i + 1).join("/")}/`;
categoriesToHide.add(parentCategoryPath);
}
}
});
// Hide parent categories if their children are displayed
categoryLinks.forEach((link) => {
const href = link.getAttribute("href");
if (categoriesToHide.has(href)) {
link.style.display = "none";
}
});
});