|
| 1 | +// Test script to verify all edit URLs are working |
| 2 | +const fs = require('fs'); |
| 3 | +const path = require('path'); |
| 4 | +const https = require('https'); |
| 5 | + |
| 6 | +// Import the arrays from on-this-page.tsx (these are simplified copies for testing) |
| 7 | +const QWIK_GROUP = [ |
| 8 | + 'components', |
| 9 | + 'concepts', |
| 10 | + 'faq', |
| 11 | + 'getting-started', |
| 12 | + 'index', |
| 13 | + 'deprecated-features', |
| 14 | +]; |
| 15 | + |
| 16 | +const QWIK_ADVANCED_GROUP = [ |
| 17 | + 'containers', |
| 18 | + 'custom-build-dir', |
| 19 | + 'dollar', |
| 20 | + 'eslint', |
| 21 | + 'library', |
| 22 | + 'optimizer', |
| 23 | + 'modules-prefetching', |
| 24 | + 'qrl', |
| 25 | + 'qwikloader', |
| 26 | + 'vite', |
| 27 | +]; |
| 28 | + |
| 29 | +const QWIKCITY_GROUP = [ |
| 30 | + 'action', |
| 31 | + 'api', |
| 32 | + 'caching', |
| 33 | + 'endpoints', |
| 34 | + 'error-handling', |
| 35 | + 'html-attributes', |
| 36 | + 'layout', |
| 37 | + 'middleware', |
| 38 | + 'pages', |
| 39 | + 'project-structure', |
| 40 | + 'qwikcity', |
| 41 | + 're-exporting-loaders', |
| 42 | + 'route-loader', |
| 43 | + 'routing', |
| 44 | + 'server$', |
| 45 | + 'validator', |
| 46 | +]; |
| 47 | + |
| 48 | +const QWIKCITY_ADVANCED_GROUP = [ |
| 49 | + 'complex-forms', |
| 50 | + 'content-security-policy', |
| 51 | + 'menu', |
| 52 | + 'plugins', |
| 53 | + 'request-handling', |
| 54 | + 'routing', |
| 55 | + 'sitemaps', |
| 56 | + 'speculative-module-fetching', |
| 57 | + 'static-assets', |
| 58 | +]; |
| 59 | + |
| 60 | +// Function to transform URL path (simplified version of makeEditPageUrl) |
| 61 | +function makeEditPageUrl(url) { |
| 62 | + const segments = url.split('/').filter((part) => part !== ''); |
| 63 | + if (segments[0] !== 'docs') { |
| 64 | + return url; |
| 65 | + } |
| 66 | + |
| 67 | + let group = ''; |
| 68 | + if (segments.length === 1) { |
| 69 | + // Handle root /docs path - it maps to the qwik overview page |
| 70 | + return 'docs/(qwik)'; |
| 71 | + } |
| 72 | + |
| 73 | + if (segments[1] === 'advanced') { |
| 74 | + if (QWIK_ADVANCED_GROUP.includes(segments[2])) { |
| 75 | + group = '(qwik)'; |
| 76 | + } else if (QWIKCITY_ADVANCED_GROUP.includes(segments[2])) { |
| 77 | + group = '(qwikcity)'; |
| 78 | + } |
| 79 | + } else if (QWIK_GROUP.includes(segments[1])) { |
| 80 | + group = '(qwik)'; |
| 81 | + } else if (QWIKCITY_GROUP.includes(segments[1])) { |
| 82 | + group = '(qwikcity)'; |
| 83 | + } |
| 84 | + |
| 85 | + if (group) { |
| 86 | + segments.splice(1, 0, group); |
| 87 | + } |
| 88 | + |
| 89 | + // Handle special cases for components and concepts which have a different structure |
| 90 | + if (segments.includes('components') || segments.includes('concepts')) { |
| 91 | + // Check if this is a subpage under components or concepts |
| 92 | + const componentIndex = segments.indexOf('components'); |
| 93 | + const conceptIndex = segments.indexOf('concepts'); |
| 94 | + const index = componentIndex !== -1 ? componentIndex : conceptIndex; |
| 95 | + |
| 96 | + // If there's a subpage (like components/overview or concepts/resumable) |
| 97 | + if (index !== -1 && index + 1 >= segments.length) { |
| 98 | + // These are directory paths without subpaths, map to their overview pages |
| 99 | + if (componentIndex !== -1) { |
| 100 | + return 'docs/(qwik)/components/overview'; |
| 101 | + } else if (conceptIndex !== -1) { |
| 102 | + return 'docs/(qwik)/concepts/think-qwik'; |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + return segments.join('/'); |
| 108 | +} |
| 109 | + |
| 110 | +// Check if a URL exists |
| 111 | +function checkUrl(url) { |
| 112 | + return new Promise((resolve) => { |
| 113 | + const options = { |
| 114 | + method: 'HEAD', |
| 115 | + host: 'github.com', |
| 116 | + path: url.replace('https://github.com', ''), |
| 117 | + timeout: 5000, |
| 118 | + }; |
| 119 | + |
| 120 | + const req = https.request(options, (res) => { |
| 121 | + resolve({ |
| 122 | + url, |
| 123 | + status: res.statusCode, |
| 124 | + ok: res.statusCode < 400, |
| 125 | + }); |
| 126 | + }); |
| 127 | + |
| 128 | + req.on('error', (err) => { |
| 129 | + resolve({ |
| 130 | + url, |
| 131 | + status: 0, |
| 132 | + ok: false, |
| 133 | + error: err.message, |
| 134 | + }); |
| 135 | + }); |
| 136 | + |
| 137 | + req.on('timeout', () => { |
| 138 | + req.destroy(); |
| 139 | + resolve({ |
| 140 | + url, |
| 141 | + status: 0, |
| 142 | + ok: false, |
| 143 | + error: 'Timeout', |
| 144 | + }); |
| 145 | + }); |
| 146 | + |
| 147 | + req.end(); |
| 148 | + }); |
| 149 | +} |
| 150 | + |
| 151 | +// Generate paths for testing |
| 152 | +async function testAllPaths() { |
| 153 | + console.log('Testing URL paths for documentation pages...'); |
| 154 | + |
| 155 | + // Generate test paths |
| 156 | + const testPaths = []; |
| 157 | + |
| 158 | + // Test QWIK_GROUP paths |
| 159 | + for (const path of QWIK_GROUP) { |
| 160 | + if (path === 'index') { |
| 161 | + // Special case for index |
| 162 | + testPaths.push('/docs'); |
| 163 | + } else { |
| 164 | + testPaths.push(`/docs/${path}`); |
| 165 | + } |
| 166 | + } |
| 167 | + |
| 168 | + // Test QWIK_ADVANCED_GROUP paths |
| 169 | + for (const path of QWIK_ADVANCED_GROUP) { |
| 170 | + testPaths.push(`/docs/advanced/${path}`); |
| 171 | + } |
| 172 | + |
| 173 | + // Test QWIKCITY_GROUP paths |
| 174 | + for (const path of QWIKCITY_GROUP) { |
| 175 | + testPaths.push(`/docs/${path}`); |
| 176 | + } |
| 177 | + |
| 178 | + // Test QWIKCITY_ADVANCED_GROUP paths |
| 179 | + for (const path of QWIKCITY_ADVANCED_GROUP) { |
| 180 | + testPaths.push(`/docs/advanced/${path}`); |
| 181 | + } |
| 182 | + |
| 183 | + // Test each path |
| 184 | + let failCount = 0; |
| 185 | + let successCount = 0; |
| 186 | + let failedPaths = []; |
| 187 | + |
| 188 | + console.log(`Testing ${testPaths.length} URLs...`); |
| 189 | + |
| 190 | + for (const testPath of testPaths) { |
| 191 | + const editPath = makeEditPageUrl(testPath); |
| 192 | + const editUrl = `https://github.com/QwikDev/qwik/blob/main/packages/docs/src/routes/${editPath}/index.mdx`; |
| 193 | + |
| 194 | + try { |
| 195 | + const result = await checkUrl(editUrl); |
| 196 | + if (result.ok) { |
| 197 | + console.log(`✅ ${editUrl}`); |
| 198 | + successCount++; |
| 199 | + } else { |
| 200 | + console.error(`❌ ${editUrl} (Status: ${result.status})`); |
| 201 | + failCount++; |
| 202 | + failedPaths.push(testPath); |
| 203 | + } |
| 204 | + } catch (error) { |
| 205 | + console.error(`❌ Error checking ${editUrl}: ${error.message}`); |
| 206 | + failCount++; |
| 207 | + failedPaths.push(testPath); |
| 208 | + } |
| 209 | + } |
| 210 | + |
| 211 | + console.log(`\nTest complete: ${successCount} successful, ${failCount} failed`); |
| 212 | + if (failCount > 0) { |
| 213 | + console.log('\nFailed paths:'); |
| 214 | + failedPaths.forEach((path) => { |
| 215 | + console.log(`- ${path}`); |
| 216 | + }); |
| 217 | + } |
| 218 | +} |
| 219 | + |
| 220 | +// Run the tests |
| 221 | +testAllPaths(); |
0 commit comments