mirror of
https://github.com/goauthentik/authentik.git
synced 2026-06-18 11:29:26 +03:00
96eb8dda0f
* website: Glossary fix minor issues wip Apply suggestion from @dominic-r Signed-off-by: Dominic R <dominic@sdko.org> anchor to param wip wip at least the lockfile changes now sure a-z first as tana asked idk why i switched in the first place wip wip lock lockfiles are hard wip please work no have? Revert "no have?" This reverts commit 743dbc1bc2900eedcc2c93af248e6afdec3688a3. * changed to sentence-case capitalization --------- Co-authored-by: Tana M Berry <tana@goauthentik.io>
87 lines
2.6 KiB
TypeScript
87 lines
2.6 KiB
TypeScript
import type { PropSidebarItem } from "@docusaurus/plugin-content-docs";
|
|
|
|
export interface GlossaryItem {
|
|
id?: string;
|
|
docId?: string;
|
|
href?: string;
|
|
type?: string;
|
|
label?: string;
|
|
}
|
|
|
|
/**
|
|
* Standardized term interface used by GlossaryHelper and DocCardList
|
|
*/
|
|
export interface GlossaryHelperTerm {
|
|
id: string;
|
|
term: string;
|
|
shortDefinition: string;
|
|
fullDefinition?: string;
|
|
tags?: string[];
|
|
isAuthentikSpecific?: boolean;
|
|
}
|
|
|
|
/**
|
|
* Determines if the current path is within the glossary section
|
|
*/
|
|
export function isGlossaryPath(pathname: string): boolean {
|
|
return /\/glossary(\/|$)/.test(pathname);
|
|
}
|
|
|
|
/**
|
|
* Determines if a sidebar item is a glossary-related item that should be filtered out
|
|
*/
|
|
export function isGlossaryItem(item: PropSidebarItem | GlossaryItem): boolean {
|
|
// Check if it's a link type with docId starting with 'glossary'
|
|
if (item.type === "link" && "docId" in item && item.docId?.startsWith("glossary")) {
|
|
return true;
|
|
}
|
|
|
|
// Check if it's a link type with href containing '/glossary/terms/'
|
|
if (item.type === "link" && "href" in item && item.href?.includes("/glossary/terms/")) {
|
|
return true;
|
|
}
|
|
|
|
// Check if it's a category with label 'terms' (for sidebar filtering)
|
|
if (item.type === "category" && "label" in item && item.label === "terms") {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Filters out glossary items from a list of sidebar items
|
|
*/
|
|
export function filterGlossaryItems<T extends PropSidebarItem | GlossaryItem>(items: T[]): T[] {
|
|
return items.filter((item) => !isGlossaryItem(item));
|
|
}
|
|
|
|
/**
|
|
* Safely extracts string value from potentially undefined/mixed-type object property
|
|
*/
|
|
export function safeStringExtract(value: unknown, fallback: string = ""): string {
|
|
return typeof value === "string" && value.trim().length > 0 ? value : fallback;
|
|
}
|
|
|
|
/**
|
|
* Safely extracts string array from potentially undefined/mixed-type object property
|
|
*/
|
|
export function safeStringArrayExtract(value: unknown): string[] {
|
|
return Array.isArray(value)
|
|
? value.filter((tag): tag is string => typeof tag === "string")
|
|
: [];
|
|
}
|
|
|
|
/**
|
|
* Safely extracts boolean value from potentially undefined/mixed-type object property
|
|
*/
|
|
export function safeBooleanExtract(value: unknown, fallback: boolean = false): boolean {
|
|
return typeof value === "boolean" ? value : fallback;
|
|
}
|
|
|
|
/**
|
|
* Extracts all available tags from a collection of terms
|
|
*/
|
|
export const extractAvailableTags = (terms: readonly GlossaryHelperTerm[]): string[] =>
|
|
Array.from(new Set(terms.flatMap((t) => t.tags ?? []))).toSorted();
|