hatch-surf/node_modules/next/dist/esm/shared/lib/segment.js
Riley Zhang df378d33ef
Some checks failed
CI / go (push) Waiting to run
CI / docker (push) Waiting to run
CI / lint-go (push) Waiting to run
CI / lint-docs (push) Waiting to run
CI / check-paperclip (push) Waiting to run
Deploy static site / Deploy to GitHub Pages (push) Has been cancelled
Deploy static site / Deploy via Docker to hatch.surf (push) Has been cancelled
Merge GitHub main into Gitea repo (allow unrelated histories)
Resolved conflicts by taking GitHub versions for:
- .dockerignore, .gitignore, Dockerfile, README.md, docker-compose.yml

Kept deploy.sh updated to:
- Pull from GitHub (primary source)
- Push to Gitea (push-mirror)
- Build from site/ directory (GitHub structure)

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-06-25 05:20:46 +02:00

52 lines
2.3 KiB
JavaScript

export function getSegmentValue(segment) {
return Array.isArray(segment) ? segment[1] : segment;
}
export function isGroupSegment(segment) {
// Use array[0] for performant purpose
return segment[0] === '(' && segment.endsWith(')');
}
export function isParallelRouteSegment(segment) {
return segment.startsWith('@') && segment !== '@children';
}
export function addSearchParamsIfPageSegment(segment, searchParams) {
const isPageSegment = segment.includes(PAGE_SEGMENT_KEY);
if (isPageSegment) {
const stringifiedQuery = JSON.stringify(searchParams);
return stringifiedQuery !== '{}' ? PAGE_SEGMENT_KEY + '?' + stringifiedQuery : PAGE_SEGMENT_KEY;
}
return segment;
}
export function computeSelectedLayoutSegment(segments, parallelRouteKey) {
if (!segments || segments.length === 0) {
return null;
}
// For 'children', use first segment; for other parallel routes, use last segment
const rawSegment = parallelRouteKey === 'children' ? segments[0] : segments[segments.length - 1];
// If the default slot is showing, return null since it's not technically "selected" (it's a fallback)
// Returning an internal value like `__DEFAULT__` would be confusing
return rawSegment === DEFAULT_SEGMENT_KEY ? null : rawSegment;
}
/** Get the canonical parameters from the current level to the leaf node. */ export function getSelectedLayoutSegmentPath(tree, parallelRouteKey, first = true, segmentPath = []) {
let node;
if (first) {
// Use the provided parallel route key on the first parallel route
node = tree[1][parallelRouteKey];
} else {
// After first parallel route prefer children, if there's no children pick the first parallel route.
const parallelRoutes = tree[1];
node = parallelRoutes.children ?? Object.values(parallelRoutes)[0];
}
if (!node) return segmentPath;
const segment = node[0];
let segmentValue = getSegmentValue(segment);
if (!segmentValue || segmentValue.startsWith(PAGE_SEGMENT_KEY)) {
return segmentPath;
}
segmentPath.push(segmentValue);
return getSelectedLayoutSegmentPath(node, parallelRouteKey, false, segmentPath);
}
export const PAGE_SEGMENT_KEY = '__PAGE__';
export const DEFAULT_SEGMENT_KEY = '__DEFAULT__';
export const NOT_FOUND_SEGMENT_KEY = '/_not-found';
//# sourceMappingURL=segment.js.map