Files
authentik/website/docusaurus-theme/components/Glossary/utils.ts
Dominic R 96eb8dda0f website: Glossary (#16007)
* 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>
2025-12-02 21:36:51 -05:00

37 lines
1.3 KiB
TypeScript

/** Humanize a tag by replacing separators and capitalizing words. */
export function formatTag(tag: string): string {
return tag.replace(/[-_]/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
}
/** Tuple entries of group key and items. */
export type Grouped<T> = ReadonlyArray<readonly [string, T[]]>;
/** Group items by tag, assigning a default when none provided. */
export function groupByTag<T extends { tags?: ReadonlyArray<string> }>(
items: ReadonlyArray<T>,
defaultTag = "General",
): Grouped<T> {
const groups: Record<string, T[]> = {};
items.forEach((item) => {
const tags = item.tags && item.tags.length ? item.tags : [defaultTag];
tags.forEach((tag) => {
if (!groups[tag]) groups[tag] = [];
groups[tag].push(item);
});
});
return Object.entries(groups).sort(([a], [b]) => a.localeCompare(b));
}
/** Group items by the first letter of their `term` property. */
export function groupByFirstLetter<T extends { term: string }>(
items: ReadonlyArray<T>,
): Grouped<T> {
const groups: Record<string, T[]> = {};
items.forEach((item) => {
const first = item.term.charAt(0).toUpperCase();
if (!groups[first]) groups[first] = [];
groups[first].push(item);
});
return Object.entries(groups).sort(([a], [b]) => a.localeCompare(b));
}