Skip to content

Commit 38ae32d

Browse files
iitzIrFaniitzIrFan
and
iitzIrFan
authored
Broken links fixed and runned tests to conform it (#7451)
* Broken links fixed and runned tests to conform it * Delete packages/docs/package.json * feat(docs): add initial package.json for qwik-docs site * Update package.json * Update package.json --------- Co-authored-by: iitzIrFan <[email protected]>
1 parent d7c30b7 commit 38ae32d

File tree

2 files changed

+255
-8
lines changed

2 files changed

+255
-8
lines changed

packages/docs/src/components/on-this-page/on-this-page.tsx

+34-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1+
import { $, component$, useContext, useOnDocument, useSignal, useStyles$ } from '@builder.io/qwik';
12
import { useContent, useLocation } from '@builder.io/qwik-city';
2-
import { component$, useContext, $, useStyles$, useOnDocument, useSignal } from '@builder.io/qwik';
3+
import { GlobalStore } from '../../context';
4+
import { AlertIcon } from '../svgs/alert-icon';
35
import { ChatIcon } from '../svgs/chat-icon';
6+
import { EditIcon } from '../svgs/edit-icon';
47
import { GithubLogo } from '../svgs/github-logo';
58
import { TwitterLogo } from '../svgs/twitter-logo';
69
import styles from './on-this-page.css?inline';
7-
import { EditIcon } from '../svgs/edit-icon';
8-
import { GlobalStore } from '../../context';
9-
import { AlertIcon } from '../svgs/alert-icon';
1010

1111
const QWIK_GROUP = [
1212
'components',
1313
'concepts',
1414
'faq',
1515
'getting-started',
16-
'think-qwik',
16+
'index',
1717
'deprecated-features',
1818
];
1919

@@ -35,23 +35,25 @@ const QWIKCITY_GROUP = [
3535
'api',
3636
'caching',
3737
'endpoints',
38-
'env-variables',
39-
'guides',
38+
'error-handling',
4039
'html-attributes',
4140
'layout',
4241
'middleware',
4342
'pages',
4443
'project-structure',
4544
'qwikcity',
45+
're-exporting-loaders',
4646
'route-loader',
4747
'routing',
4848
'server$',
49-
'troubleshooting',
5049
'validator',
5150
];
51+
5252
const QWIKCITY_ADVANCED_GROUP = [
53+
'complex-forms',
5354
'content-security-policy',
5455
'menu',
56+
'plugins',
5557
'request-handling',
5658
'routing',
5759
'sitemaps',
@@ -64,7 +66,13 @@ const makeEditPageUrl = (url: string): string => {
6466
if (segments[0] !== 'docs') {
6567
return url;
6668
}
69+
6770
let group = '';
71+
if (segments.length === 1) {
72+
// Handle root /docs path - it maps to the qwik overview page
73+
return 'docs/(qwik)';
74+
}
75+
6876
if (segments[1] == 'advanced') {
6977
if (QWIK_ADVANCED_GROUP.includes(segments[2])) {
7078
group = '(qwik)';
@@ -81,6 +89,24 @@ const makeEditPageUrl = (url: string): string => {
8189
segments.splice(1, 0, group);
8290
}
8391

92+
// Handle special cases for components and concepts which have a different structure
93+
if (segments.includes('components') || segments.includes('concepts')) {
94+
// Check if this is a subpage under components or concepts
95+
const componentIndex = segments.indexOf('components');
96+
const conceptIndex = segments.indexOf('concepts');
97+
const index = componentIndex !== -1 ? componentIndex : conceptIndex;
98+
99+
// If there's a subpage (like components/overview or concepts/resumable)
100+
if (index !== -1 && index + 1 >= segments.length) {
101+
// These are directory paths without subpaths, map to their overview pages
102+
if (componentIndex !== -1) {
103+
return 'docs/(qwik)/components/overview';
104+
} else if (conceptIndex !== -1) {
105+
return 'docs/(qwik)/concepts/think-qwik';
106+
}
107+
}
108+
}
109+
84110
return segments.join('/');
85111
};
86112

packages/docs/test-urls.js

+221
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
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

Comments
 (0)