handleError for SvelteKit 3: ids only for unknown errors, compact 404 log line; error page suggestions prefer the real parent over the section
All checks were successful
Deploy production / deploy (push) Successful in 1m10s

This commit is contained in:
2026-10-25 13:15:41 +00:00
parent 92d6da959d
commit 20ad42b247
5 changed files with 35 additions and 22 deletions

View File

@@ -27,6 +27,10 @@ describe('suggestPages', () => {
expect(hrefs('/trackers/helth')).not.toContain('/trackers/health');
expect(hrefs('/trackers/helth', true)).toContain('/trackers/health');
});
it('ranks the tracker above the section it lives in', () => {
expect(hrefs('/trackers/carz')[0]).toBe('/trackers/cars');
expect(hrefs('/trackers/doesnotexist')).not.toContain('/trackers');
});
it('returns nothing for the home page or noise', () => {
expect(hrefs('/')).toEqual([]);
expect(hrefs('/zzqxj')).toEqual([]);

View File

@@ -122,8 +122,10 @@ export function suggestPages(pathname: string, isOwner: boolean, limit = 3): Sug
let score = 0;
for (const s of segments) score = Math.max(score, similarity(s, name), similarity(s, slug));
// Generic section names only count when spelled out: they match too much otherwise.
if (d.kind === 'page') score *= 0.8;
if (d.href !== '/' && path.startsWith(`${d.href}/`))
if (d.kind === 'page') score = path.startsWith(`${d.href}/`) ? 0 : score * 0.8;
// The closest real parent (/trackers/cars for /trackers/cars/nope); sections like
// /trackers are already in the navigation tiles.
if (d.kind !== 'page' && path.startsWith(`${d.href}/`))
score = Math.max(score, 0.9 + d.href.length / 1000);
return { d, score };
})