11 lines
614 B
TypeScript
11 lines
614 B
TypeScript
/** The node-path URL scheme: the focused path is carried in the `?n=id.id`
|
|
* query. Defined once here so the route middleware and `useNodeNav` (which
|
|
* builds the links) read and write the exact same shape. */
|
|
|
|
/** Parse the `n` query value into a path of node ids ([] = the voyage root). */
|
|
export const parseNodePath = (n: unknown): string[] =>
|
|
typeof n === "string" && n ? n.split(".").filter(Boolean) : []
|
|
|
|
/** Serialize a path back to the `n` query value (undefined = root, no param). */
|
|
export const serializeNodePath = (path: string[]): string | undefined =>
|
|
path.length ? path.join(".") : undefined
|