forked from solidjs/solid-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.ts
More file actions
24 lines (20 loc) · 764 Bytes
/
helpers.ts
File metadata and controls
24 lines (20 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { useLocation, useMatch } from "@solidjs/router";
import { useCurrentRouteMetaData } from "~/utils/route-metadata-helper";
import { SUPPORTED_LOCALES } from "./config";
export function getCurrentLocale() {
const match = useMatch(() => "/:locale?/*", {
locale: SUPPORTED_LOCALES,
});
return match()?.params.project ?? null;
}
export function getEntryFileName() {
const pathname = useLocation().pathname;
const currentRouteMetaData = useCurrentRouteMetaData();
if (currentRouteMetaData.isProjectRoot) {
return `${pathname}/index.mdx`.replace("//", "/");
} else {
// Trim trailing slash
return (pathname.endsWith("/") ? pathname.slice(0, -1) : pathname) + ".mdx";
}
}
export const isExternalURL = (url: string) => /^https?:\/\//.test(url);