create frontend directory
This commit is contained in:
39
frontend/utils/index.ts
Normal file
39
frontend/utils/index.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import type { BreadcrumbData } from '~/types';
|
||||
|
||||
export function getBreadcrumbs(path: string): BreadcrumbData[] {
|
||||
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('/');
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user