-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: scoping of breadcrumb links, add unified function that resolves …
…urls for site
- Loading branch information
1 parent
5583c9c
commit 5bfefd2
Showing
10 changed files
with
143 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
type ResolveUrlOptions = { | ||
/** | ||
* If provided, the baseUrl will be prepended to the resulting path | ||
* | ||
* Sample: "http://localhost:3000" | ||
* @default: "/" | ||
*/ | ||
baseUrl?: string; | ||
|
||
/** | ||
* path with leading / | ||
* | ||
* Sample: "/test/to/my/page" | ||
*/ | ||
path: string; | ||
|
||
scope: { | ||
language: string; | ||
} | null; | ||
|
||
/** | ||
* If provided, the anchor will be appended to the resulting URL | ||
* | ||
* Sample: "my-anchor" | ||
*/ | ||
anchor?: string; | ||
}; | ||
|
||
/** | ||
* Resolves a path, scope and a baseUrl to a real URL which can be navigated to. | ||
* | ||
* @return {string} The resolved URL: /{scope.language}/test/to/my/page#my-anchor | ||
*/ | ||
export const resolveUrl = ({ baseUrl = "/", path, scope, anchor }: ResolveUrlOptions) => { | ||
let safeScope = ""; | ||
if (scope != null) { | ||
safeScope = scope.language; | ||
} | ||
let anchorPostfix = ""; | ||
if (anchor) { | ||
anchorPostfix = `#${anchor}`; | ||
} | ||
return `${baseUrl}${safeScope}${path}${anchorPostfix}`; | ||
}; |