document.addEventListener("DOMContentLoaded", function() {
// Function to process meta elements
function processMeta(meta) {
var firstTag = meta.querySelector('.meta-tags a[rel="tag"]');
var catLink = meta.querySelector('a[rel="category tag"]');
if (firstTag && catLink) {
// 1. Swap the category text and link with the first tag[cite: 1]
catLink.textContent = firstTag.textContent;
catLink.setAttribute('href', firstTag.getAttribute('href'));
// 2. Hide extra categories if present[cite: 1]
meta.querySelectorAll('a[rel="category tag"]:not(:first-of-type)').forEach(function(extraCat) {
extraCat.style.display = 'none';
});
// 3. Hide the original tags container completely[cite: 1]
var metaTagsSpan = meta.querySelector('.meta-tags');
if (metaTagsSpan) {
metaTagsSpan.style.display = 'none';
}
// 4. Remove raw "Categories: " text nodes[cite: 1, 2]
meta.childNodes.forEach(function(node) {
if (node.nodeType === Node.TEXT_NODE && node.nodeValue.includes('Categories:')) {
node.nodeValue = ''; // Clear out "Categories: " text[cite: 2]
}
});
// 5. Hide the trailing vertical pipe separator[cite: 2]
var separators = meta.querySelectorAll('.fusion-inline-sep');
if (separators.length > 0) {
separators[separators.length - 1].style.display = 'none';
}
}
}
// 1. Run for latest_posts[cite: 1, 2]
document.querySelectorAll('.latest_posts .fusion-single-line-meta').forEach(processMeta);
// 2. Run specifically for latest_single_post (handles direct children or nested meta)
document.querySelectorAll('.latest_single_post .fusion-single-line-meta, .latest_single_post').forEach(function(container) {
if (container.classList.contains('fusion-single-line-meta')) {
processMeta(container);
} else {
var meta = container.querySelector('.fusion-single-line-meta');
if (meta) {
processMeta(meta);
}
}
});
});