Spaces:
Running
Running
File size: 5,405 Bytes
53873ca |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
// Website Validation Script
const validateWebsite = {
// Critical paths that must exist and be accessible
criticalPaths: [
'/',
'/projects',
'/papers',
'/proposals',
'/docs'
],
// Project paths
projectPaths: [
'/projects/automedical',
'/projects/analytics',
'/projects/autoglaucoma'
],
// Paper paths
paperPaths: [
'/papers/fermed-vlm',
'/papers/archive/research',
'/papers/archive/publications'
],
// Proposal paths
proposalPaths: [
'/proposals/nhs/main',
'/proposals/nhs/detailed',
'/proposals/nhs/formal'
],
// Documentation paths
docPaths: [
'/docs/main',
'/docs/api',
'/docs/deployment'
],
// Validate all links
async validateLinks() {
const results = {
working: [],
redirects: [],
broken: []
};
const allPaths = [
...this.criticalPaths,
...this.projectPaths,
...this.paperPaths,
...this.proposalPaths,
...this.docPaths
];
for (const path of allPaths) {
try {
const response = await fetch(path);
if (response.ok) {
if (response.redirected) {
results.redirects.push({
path,
redirectTo: response.url
});
} else {
results.working.push(path);
}
} else {
results.broken.push({
path,
status: response.status
});
}
} catch (error) {
results.broken.push({
path,
error: error.message
});
}
}
return results;
},
// Validate navigation consistency
validateNavigation() {
const results = {
consistent: true,
errors: []
};
// Check if all pages have navigation
document.querySelectorAll('nav').forEach(nav => {
const links = nav.querySelectorAll('a');
const requiredLinks = ['Home', 'Projects', 'Papers', 'Proposals', 'Documentation'];
const missingLinks = requiredLinks.filter(required =>
![...links].some(link =>
link.textContent.trim().toLowerCase() === required.toLowerCase()
)
);
if (missingLinks.length > 0) {
results.consistent = false;
results.errors.push({
page: window.location.pathname,
missingLinks
});
}
});
return results;
},
// Validate breadcrumbs
validateBreadcrumbs() {
const results = {
valid: true,
errors: []
};
document.querySelectorAll('.breadcrumb').forEach(breadcrumb => {
const links = breadcrumb.querySelectorAll('a');
const currentPath = window.location.pathname;
const pathParts = currentPath.split('/').filter(Boolean);
// First link should always be Home
if (links[0]?.getAttribute('href') !== '/') {
results.valid = false;
results.errors.push({
page: currentPath,
error: 'Missing home link in breadcrumb'
});
}
// Check if breadcrumb matches current path
pathParts.forEach((part, index) => {
const link = links[index + 1];
if (!link || !link.getAttribute('href').includes(part)) {
results.valid = false;
results.errors.push({
page: currentPath,
error: `Invalid breadcrumb path at level ${index + 1}`
});
}
});
});
return results;
},
// Generate validation report
async generateReport() {
const linkResults = await this.validateLinks();
const navResults = this.validateNavigation();
const breadcrumbResults = this.validateBreadcrumbs();
return {
timestamp: new Date().toISOString(),
links: {
total: linkResults.working.length + linkResults.redirects.length + linkResults.broken.length,
working: linkResults.working.length,
redirects: linkResults.redirects.length,
broken: linkResults.broken.length,
details: linkResults
},
navigation: {
consistent: navResults.consistent,
errors: navResults.errors
},
breadcrumbs: {
valid: breadcrumbResults.valid,
errors: breadcrumbResults.errors
}
};
}
};
// Export for use in Node.js environments
if (typeof module !== 'undefined' && module.exports) {
module.exports = validateWebsite;
}
// For browser use
if (typeof window !== 'undefined') {
window.validateWebsite = validateWebsite;
} |