PageSourceSearch

https://helamalmo.com/src/utils/navigation-helpers.js

js helamalmo.com collected 2026-10-09 01:47:26 UTC 3,003 bytes, 84 lines download raw bytes

1export function findNode(nodes, url) {
2    const sortedNodes = [...nodes].sort((a, b) => {
3        const aIsUtility = a.id === 'top-menu' || a.id === 'footer-menu';
4        const bIsUtility = b.id === 'top-menu' || b.id === 'footer-menu';
5        if (aIsUtility && !bIsUtility) return 1;
6        if (!aIsUtility && bIsUtility) return -1;
7        return 0;
8    });
9
10    for (const node of sortedNodes) {
11        if (node.url === url) return node;
12        if (node.children) {
13            const found = findNode(node.children, url);
14            if (found) return found;
15        }
16    }
17    return null;
18}
19
20export function getBreadcrumbs(nodes, url, path = []) {
21    // Sort nodes to prioritize main content over utility menus
22    const sortedNodes = [...nodes].sort((a, b) => {
23        const aIsUtility = a.id === 'top-menu' || a.id === 'footer-menu';
24        const bIsUtility = b.id === 'top-menu' || b.id === 'footer-menu';
25        if (aIsUtility && !bIsUtility) return 1;
26        if (!aIsUtility && bIsUtility) return -1;
27        return 0;
28    });
29
30    for (const node of sortedNodes) {
31        // Create a new path array for the current branch. We store the full node to access children in UI.
32        const currentPath = [...path, node];
33
34        if (node.url === url) {
35            return currentPath;
36        }
37
38        if (node.children) {
39            const found = getBreadcrumbs(node.children, url, currentPath);
40            if (found) return found;
41        }
42    }
43    return null;
44}
45
46export function isCardVisible(card, navData) {
47    if (!card || !card.url) return true;
48    if (card.externalUrl || card.url.startsWith('http') || card.url === '#') return true;
49    if (navData) {
50        const node = findNode(navData, card.url);
51        if (node && (node.hidden || node.inactive || node.published === false)) {
52            return false;
53        }
54    }
55    return true;
56}
57
58function normalizeKey(str = '') {
59    return (str || '')
60        .toLowerCase()
61        .replace(/ö/g, 'o')
62        .replace(/ä/g, 'a')
63        .replace(/Ã¥/g, 'a')
64        .replace(/[^a-z0-9]/g, '');
65}
66
67export function resolveCardUrl(card) {
68    if (!card) return '';
69    if (card.url) return card.url;
70    if (card.externalUrl) return card.externalUrl;
71    const idKey = normalizeKey(card.id);
72    const titleKey = normalizeKey(card.title);
73    
74    if (idKey === 'motesplatser' || titleKey === 'motesplatser') return '/motesplatser';
75    if (idKey === 'verksamheter' || titleKey === 'verksamheter') return '/verksamheter';
76    if (idKey === 'kontakt' || titleKey === 'kontakt') return '/kontakt';
77    if (idKey === 'familjen' || titleKey === 'familjen') return '/familjen';
78    if (idKey === 'engageradig' || titleKey === 'engageradig') return '/engageradig';
79    if (idKey === 'butik' || titleKey === 'butik') return '/butik';
80    if (idKey === 'omoss' || titleKey === 'omoss') return '/familjen/omoss';
81    if (idKey === 'aktuellt' || titleKey === 'aktuellt') return '/familjen/aktuellt';
82    
83    return '';
84}

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.