dont use [...path] routing since it breaks building statically
This commit is contained in:
@@ -8,14 +8,14 @@ export function getApiUrl(path: string): string {
|
||||
* @param path - The warren path (e.g. `a3f79579-9155-4492-a579-b0253c8d3bf8/my-directory/`)
|
||||
* @returns A prettier path `a3f79579-9155-4492-a579-b0253c8d3bf8/my-directory` -> `my-warren/my-directory`
|
||||
*/
|
||||
export function routeWithWarrenName(path: string): string {
|
||||
const warrens = useWarrenStore().warrens;
|
||||
export function routeWithWarrenName(warrenId: string, path: string): string {
|
||||
const warrenStore = useWarrenStore();
|
||||
|
||||
const id = path.split('/')[0];
|
||||
|
||||
if (!(id in warrens)) {
|
||||
if (!(warrenId in warrenStore.warrens)) {
|
||||
return path;
|
||||
}
|
||||
|
||||
return path.replace(id, warrens[id].name);
|
||||
const warrenName = warrenStore.warrens[warrenId].name;
|
||||
|
||||
return `${warrenName}${path}`;
|
||||
}
|
||||
|
||||
@@ -1,53 +1,9 @@
|
||||
import type { BreadcrumbData } from '~/types';
|
||||
|
||||
export function getBreadcrumbs(path: string): BreadcrumbData[] {
|
||||
const { warrens } = useWarrenStore();
|
||||
|
||||
const crumbs = path
|
||||
.split('/')
|
||||
.filter((v) => v.length > 0)
|
||||
.map((v) => ({
|
||||
name: v,
|
||||
href: '#',
|
||||
}));
|
||||
|
||||
crumbs.unshift({ name: '/', href: '/' });
|
||||
|
||||
for (let i = 1; i < crumbs.length; i++) {
|
||||
crumbs[i].name = decodeURI(crumbs[i].name);
|
||||
crumbs[i].href =
|
||||
'/' +
|
||||
path
|
||||
.split('/')
|
||||
.slice(1, i + 1)
|
||||
.join('/');
|
||||
}
|
||||
|
||||
if (
|
||||
crumbs.length >= 3 &&
|
||||
crumbs[1].href === '/warrens' &&
|
||||
crumbs[2].name in warrens
|
||||
) {
|
||||
crumbs[2].name = warrens[crumbs[2].name].name;
|
||||
}
|
||||
|
||||
return crumbs;
|
||||
}
|
||||
|
||||
export function preventDefault(event: Event) {
|
||||
event.preventDefault();
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
export function joinPaths(base: string, other: string): string {
|
||||
if (!base.endsWith('/')) {
|
||||
base += '/';
|
||||
}
|
||||
|
||||
return base + other;
|
||||
}
|
||||
|
||||
export function splitOnce(
|
||||
str: string,
|
||||
search: string
|
||||
|
||||
Reference in New Issue
Block a user