document.addEventListener('DOMContentLoaded', function () { // 1. Label the two nav elements distinctly const navs = document.querySelectorAll('nav'); if (navs[0]) navs[0].setAttribute('aria-label', 'Primary navigation'); if (navs[1]) navs[1].setAttribute('aria-label', 'Mobile navigation'); // 2. Fix menu toggle button const toggle = document.querySelector('a[href="#feastmobilemenu"]'); if (toggle) { toggle.setAttribute('role', 'button'); toggle.setAttribute('aria-label', 'Open navigation menu'); toggle.setAttribute('aria-expanded', 'false'); toggle.addEventListener('click', function () { const expanded = this.getAttribute('aria-expanded') === 'true'; this.setAttribute('aria-expanded', String(!expanded)); this.setAttribute('aria-label', expanded ? 'Open navigation menu' : 'Close navigation menu' ); }); } // 3. Fix search icon link const searchIcon = document.querySelector('a[href="#feastmobilemenu"] ~ a'); if (searchIcon) searchIcon.setAttribute('aria-label', 'Search'); // 4. Fix empty alt on category images inside links document.querySelectorAll('a img[alt=""]').forEach(function (img) { const linkText = img.closest('a'); if (linkText) { const caption = linkText.querySelector('p, span, figcaption'); if (caption) img.setAttribute('alt', caption.textContent.trim()); } }); // 5. Fix author photo alt const authorImg = document.querySelector('img[alt="feastwithsafiya"]'); if (authorImg) authorImg.setAttribute('alt', 'Safiya, author of Feast with Safiya'); // 6. Inject skip link at top of body const skip = document.createElement('a'); skip.href = '#main-content'; skip.className = 'a11y-skip-link'; skip.textContent = 'Skip to main content'; document.body.insertBefore(skip, document.body.firstChild); // 7. Label the main content landmark if not already set const main = document.querySelector('main, #main, .site-main, article'); if (main && !main.id) main.id = 'main-content'; });