|
| 1 | +// Archiver Section Navigation - Right Side Panel |
| 2 | +(function() { |
| 3 | + // Only run on archiver pages, but NOT on the introduction/index page |
| 4 | + if (!window.location.pathname.includes('/archiver/')) return; |
| 5 | + |
| 6 | + // Skip the introduction page |
| 7 | + const path = window.location.pathname; |
| 8 | + if (path.endsWith('/archiver/') || path.endsWith('/archiver')) return; |
| 9 | + |
| 10 | + const navItems = [ |
| 11 | + { title: 'Getting Started', items: [ |
| 12 | + { name: 'Introduction', href: 'index.md' }, |
| 13 | + { name: 'User Notice', href: 'user-notice.md' }, |
| 14 | + { name: 'Enable Archiver', href: 'enable-archiver.md' }, |
| 15 | + ]}, |
| 16 | + { title: 'Administration', items: [ |
| 17 | + { name: 'Admin Roles & Permissions', href: 'admin-roles-permissions.md' }, |
| 18 | + { name: 'User Roles & Permissions', href: 'user-roles-permissions.md' }, |
| 19 | + { name: 'System Requirements', href: 'system-requirements.md' }, |
| 20 | + ]}, |
| 21 | + { title: 'Storage Connections', items: [ |
| 22 | + { name: 'Linking Storages', href: 'connect-storage.md' }, |
| 23 | + { name: 'Google Drive', href: 'connect-gdrive.md' }, |
| 24 | + { name: 'Box', href: 'connect-box.md' }, |
| 25 | + { name: 'Dropbox', href: 'connect-dropbox.md' }, |
| 26 | + { name: 'SFTP', href: 'connect-sftp.md' }, |
| 27 | + { name: 'SFTP Security Upgrade', href: 'sftp-security-upgrade.md' }, |
| 28 | + { name: 'Smarsh', href: 'connect-smarsh.md' }, |
| 29 | + ]}, |
| 30 | + { title: 'Settings & Monitoring', items: [ |
| 31 | + { name: 'Sync Options', href: 'sync-options.md' }, |
| 32 | + { name: 'Archive Logs', href: 'archive-logs.md' }, |
| 33 | + { name: 'Retry Mechanism', href: 'retry-mechanism.md' }, |
| 34 | + { name: 'Archive Status', href: 'archive-status.md' }, |
| 35 | + { name: 'Notifications', href: 'notifications.md' }, |
| 36 | + ]}, |
| 37 | + { title: 'Help', items: [ |
| 38 | + { name: 'General Questions', href: 'questions.md' }, |
| 39 | + ]}, |
| 40 | + ]; |
| 41 | + |
| 42 | + function getCurrentPage() { |
| 43 | + const path = window.location.pathname; |
| 44 | + const parts = path.split('/'); |
| 45 | + let page = parts[parts.length - 1] || parts[parts.length - 2]; |
| 46 | + if (page === '' || page === 'archiver') page = 'index.md'; |
| 47 | + if (!page.endsWith('.md')) page += '.md'; |
| 48 | + // Handle trailing slash |
| 49 | + if (page === '.md') page = 'index.md'; |
| 50 | + return page.replace(/\/$/, ''); |
| 51 | + } |
| 52 | + |
| 53 | + function buildNav() { |
| 54 | + const currentPage = getCurrentPage(); |
| 55 | + |
| 56 | + // Get the base path for archiver section |
| 57 | + const pathParts = window.location.pathname.split('/'); |
| 58 | + const archiverIndex = pathParts.indexOf('archiver'); |
| 59 | + const basePath = pathParts.slice(0, archiverIndex + 1).join('/') + '/'; |
| 60 | + |
| 61 | + let html = '<div class="archiver-section-nav">'; |
| 62 | + html += '<h4>In This Section</h4>'; |
| 63 | + |
| 64 | + navItems.forEach(group => { |
| 65 | + html += `<div class="nav-group-title">${group.title}</div>`; |
| 66 | + html += '<ul class="nav-group">'; |
| 67 | + group.items.forEach(item => { |
| 68 | + const itemPage = item.href.replace('.md', ''); |
| 69 | + const isActive = currentPage === item.href || |
| 70 | + currentPage === itemPage || |
| 71 | + currentPage.replace('.md', '') === itemPage || |
| 72 | + (itemPage === 'index' && (currentPage === '' || currentPage === 'index')); |
| 73 | + const activeClass = isActive ? ' class="active"' : ''; |
| 74 | + // Use absolute path from archiver base |
| 75 | + const href = itemPage === 'index' ? basePath : basePath + itemPage + '/'; |
| 76 | + html += `<li><a href="${href}"${activeClass}>${item.name}</a></li>`; |
| 77 | + }); |
| 78 | + html += '</ul>'; |
| 79 | + }); |
| 80 | + |
| 81 | + html += '</div>'; |
| 82 | + return html; |
| 83 | + } |
| 84 | + |
| 85 | + function injectNav() { |
| 86 | + if (!document.querySelector('.archiver-section-nav')) { |
| 87 | + // Insert at body level for fixed positioning |
| 88 | + document.body.insertAdjacentHTML('beforeend', buildNav()); |
| 89 | + // Add class to body for content margin adjustment |
| 90 | + document.body.classList.add('has-archiver-nav'); |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + function removeNav() { |
| 95 | + const nav = document.querySelector('.archiver-section-nav'); |
| 96 | + if (nav) { |
| 97 | + nav.remove(); |
| 98 | + document.body.classList.remove('has-archiver-nav'); |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + // Run on DOM ready |
| 103 | + if (document.readyState === 'loading') { |
| 104 | + document.addEventListener('DOMContentLoaded', injectNav); |
| 105 | + } else { |
| 106 | + injectNav(); |
| 107 | + } |
| 108 | + |
| 109 | + // Handle navigation for instant loading (MkDocs Material) |
| 110 | + function shouldShowNav() { |
| 111 | + const path = window.location.pathname; |
| 112 | + if (!path.includes('/archiver/')) return false; |
| 113 | + if (path.endsWith('/archiver/') || path.endsWith('/archiver')) return false; |
| 114 | + return true; |
| 115 | + } |
| 116 | + |
| 117 | + function updateNav() { |
| 118 | + const existingNav = document.querySelector('.archiver-section-nav'); |
| 119 | + if (shouldShowNav()) { |
| 120 | + if (!existingNav) { |
| 121 | + injectNav(); |
| 122 | + } else { |
| 123 | + // Update active state |
| 124 | + const currentPage = getCurrentPage(); |
| 125 | + existingNav.querySelectorAll('a').forEach(link => { |
| 126 | + const href = link.getAttribute('href'); |
| 127 | + const linkPage = href.split('/').filter(Boolean).pop(); |
| 128 | + const isActive = currentPage.replace('.md', '') === linkPage || |
| 129 | + (linkPage === 'archiver' && currentPage === 'index'); |
| 130 | + link.classList.toggle('active', isActive); |
| 131 | + }); |
| 132 | + } |
| 133 | + } else if (existingNav) { |
| 134 | + removeNav(); |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + document.addEventListener('DOMContentLoaded', function() { |
| 139 | + // Watch for URL changes (instant navigation) |
| 140 | + let lastPath = window.location.pathname; |
| 141 | + const observer = new MutationObserver(function() { |
| 142 | + if (window.location.pathname !== lastPath) { |
| 143 | + lastPath = window.location.pathname; |
| 144 | + setTimeout(updateNav, 100); |
| 145 | + } |
| 146 | + }); |
| 147 | + observer.observe(document.body, { childList: true, subtree: true }); |
| 148 | + }); |
| 149 | +})(); |
| 150 | + |
0 commit comments