PageSourceSearch

https://githubplanet.dev/front/js/home-route.js

js githubplanet.dev collected 2026-10-04 23:35:35 UTC 1,396 bytes, 48 lines download raw bytes

1export const DEFAULT_SHOWCASE_SLUG = 'typescript';
2
3function normalizePath(pathname) {
4    const withoutTrailingSlash = pathname.replace(/\/+$/, '');
5    return withoutTrailingSlash || '/';
6}
7
8function stripLocale(pathname) {
9    return pathname.replace(/^\/(?:en|english)(?=\/|$)/, '') || '/';
10}
11
12export function resolveHomeRoute(pathname, search = '') {
13    const normalizedPath = stripLocale(normalizePath(pathname));
14    const query = new URLSearchParams(search);
15    const querySlug = query.get('showcase')?.trim().toLowerCase() || null;
16
17    if (normalizedPath === '/exhibition') {
18        return { mode: 'exhibition', showcaseSlug: null };
19    }
20
21    if (normalizedPath === '/demo') {
22        return {
23            mode: 'demo',
24            showcaseSlug: querySlug || DEFAULT_SHOWCASE_SLUG
25        };
26    }
27
28    if (normalizedPath === '/showcase') {
29        return {
30            mode: 'showcase',
31            showcaseSlug: querySlug || DEFAULT_SHOWCASE_SLUG
32        };
33    }
34
35    if (normalizedPath.startsWith('/showcase/')) {
36        const slug = normalizedPath.slice('/showcase/'.length).split('/')[0].trim().toLowerCase();
37        return {
38            mode: 'showcase',
39            showcaseSlug: slug || DEFAULT_SHOWCASE_SLUG
40        };
41    }
42
43    if (querySlug) {
44        return { mode: 'showcase', showcaseSlug: querySlug };
45    }
46
47    return { mode: 'normal', showcaseSlug: null };
48}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.