mirror of
https://github.com/goauthentik/authentik.git
synced 2026-06-18 11:29:26 +03:00
db3fb0bf2e
Cherry-pick #16430 to version-2025.8 (with conflicts)
This cherry-pick has conflicts that need manual resolution.
Original PR: #16430
Original commit: 6d81aea5aa
Co-authored-by: Teffen Ellis <592134+GirlBossRush@users.noreply.github.com>
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { RedirectEntry } from "@goauthentik/docusaurus-theme/redirects";
|
|
import type { AKRedirectsPluginData } from "@goauthentik/docusaurus-theme/redirects/plugin";
|
|
|
|
import { usePluginData } from "@docusaurus/useGlobalData";
|
|
|
|
/**
|
|
* Hook to retrieve redirects provided by the client-side redirects plugin.
|
|
*/
|
|
export function useRedirectEntries(): RedirectEntry[] | null {
|
|
const pluginData = usePluginData("ak-redirects-plugin", undefined) as
|
|
| AKRedirectsPluginData
|
|
| undefined;
|
|
|
|
if (!pluginData || !pluginData.redirects) {
|
|
return null;
|
|
}
|
|
|
|
return pluginData.redirects;
|
|
}
|
|
|
|
/**
|
|
* Given a URL-like object, return the pathname (i.e. suffix), and the combination query string, hash, etc (i.e. prefix).
|
|
*/
|
|
export function pluckPathnameAffixes(
|
|
url: Pick<URL, "pathname" | "href" | "origin">,
|
|
): [prefix: string, suffix: string] {
|
|
const [, fullPathname = ""] = url.href.split(window.location.origin);
|
|
|
|
if (!fullPathname) return ["", ""];
|
|
|
|
const suffix = fullPathname.slice(url.pathname.length);
|
|
|
|
return [url.pathname, suffix];
|
|
}
|