mirror of
https://github.com/goauthentik/authentik
synced 2026-04-27 18:07:15 +02:00
* new first steps docs * moved email config up to match Docker * first draft * moved sections and retitled some * more content, tweaks * dewis edits * added Dewi ideas, more content, tweaks * more content, green tips, other fixes * Optimised images with calibre/image-actions * Optimised images with calibre/image-actions * Optimised images with calibre/image-actions * conflicts? * dominic's eedits, more content * another fine Dominic edit * more dewi and dominic edits, links * a bunch of things Signed-off-by: Jens Langhammer <jens@goauthentik.io> * tweaks * thanks Teffen * new styles, more content * few more dominic edits, tweaks * formatting fights on tips * fix some alignments Signed-off-by: Jens Langhammer <jens@goauthentik.io> * changes from Jens * work on bindings docs that was needed for the first steps docs * links, more tweaks * more edits, more TODOs done * add mermaid diagram, more links, more content * fix sidebar, tweaks * tweak * more link fixing * fix heading size * more dewi and dominic edits * more dewi and dominic edits * teffen enhancements yay and more bindings rearchitecting * added note about stage bindings being the only type of binding that you can bind to yeehaw --------- Signed-off-by: Tana M Berry <tanamarieberry@yahoo.com> Signed-off-by: Jens Langhammer <jens@goauthentik.io> Co-authored-by: authentik-automation[bot] <135050075+authentik-automation[bot]@users.noreply.github.com> Co-authored-by: Dewi Roberts <dewi@goauthentik.io> Co-authored-by: Jens Langhammer <jens@goauthentik.io>
145 lines
4.3 KiB
TypeScript
145 lines
4.3 KiB
TypeScript
/**
|
|
* @file Swizzled DocItemContent component.
|
|
*
|
|
* This component is a swizzled version of the original DocItemContent component.
|
|
*
|
|
* Similar to Docusaurus' default `DocItemContent`, this component renders
|
|
* the content of a documentation page. However, it also adds support for
|
|
* support badges, and Authentik version badges.
|
|
*/
|
|
|
|
import "./styles.css";
|
|
|
|
import { SupportBadge } from "#components/SupportBadge.tsx";
|
|
import { VersionBadge } from "#components/VersionBadge.tsx";
|
|
|
|
import { useSyntheticTitle } from "#hooks/title.ts";
|
|
import { PreReleaseAdmonition } from "#theme/DocItem/Content/PreReleaseAdmonition.tsx";
|
|
|
|
import { useDoc } from "@docusaurus/plugin-content-docs/client";
|
|
import { ThemeClassNames } from "@docusaurus/theme-common";
|
|
import type { Props } from "@theme/DocItem/Content";
|
|
import Heading from "@theme/Heading";
|
|
import MDXContent from "@theme/MDXContent";
|
|
import clsx from "clsx";
|
|
import React, { JSX, useEffect } from "react";
|
|
|
|
class MarkdownLintError extends Error {
|
|
constructor(message: string) {
|
|
super(message);
|
|
this.name = "MarkdownLintError";
|
|
}
|
|
}
|
|
|
|
function useBadgeLinterEffect() {
|
|
const { frontMatter, metadata } = useDoc();
|
|
const { hide_title } = frontMatter;
|
|
const { id } = metadata;
|
|
|
|
useEffect(() => {
|
|
if (hide_title) {
|
|
console.debug(`Skipping badge linting for ${id} because \`hide_title\` is set`);
|
|
return;
|
|
}
|
|
|
|
const invalidBadges = document.querySelectorAll(`.theme-doc-markdown > header + .badge,
|
|
.theme-doc-markdown .markdown > .badge
|
|
`);
|
|
|
|
const badgeCount = invalidBadges.length;
|
|
|
|
if (!badgeCount) return;
|
|
|
|
const badgeContent = Array.from(invalidBadges, (badge) => `"${badge.textContent}"`);
|
|
|
|
const message = `${id}: ${badgeCount} Badge(s) defined in Markdown content instead of the frontmatter:\n ${badgeContent.join("\n")}`;
|
|
|
|
console.error(message);
|
|
|
|
console.error(`Found ${badgeCount} invalid badges on ${id}`, invalidBadges);
|
|
|
|
throw new MarkdownLintError(message);
|
|
}, [hide_title, id]);
|
|
}
|
|
|
|
interface BadgesProps {
|
|
badges: JSX.Element[];
|
|
}
|
|
|
|
const BadgeGroup: React.FC<BadgesProps> = ({ badges }) => {
|
|
if (!badges.length) return null;
|
|
|
|
return (
|
|
<p className="badge-group">
|
|
{badges.map((badge, index) => (
|
|
<React.Fragment key={index}>{badge}</React.Fragment>
|
|
))}
|
|
</p>
|
|
);
|
|
};
|
|
|
|
const DocItemContent: React.FC<Props> = ({ children }) => {
|
|
const syntheticTitle = useSyntheticTitle();
|
|
const { frontMatter, metadata, contentTitle } = useDoc();
|
|
const { id } = metadata;
|
|
const {
|
|
// ---
|
|
support_level,
|
|
authentik_version,
|
|
authentik_enterprise,
|
|
authentik_preview,
|
|
} = frontMatter;
|
|
|
|
const preReleaseDoc = frontMatter.beta && metadata.id.startsWith("releases");
|
|
|
|
useBadgeLinterEffect();
|
|
|
|
const badges: JSX.Element[] = [];
|
|
|
|
if (authentik_version) {
|
|
badges.push(<VersionBadge semver={authentik_version} docID={id} />);
|
|
}
|
|
|
|
if (support_level) {
|
|
badges.push(<SupportBadge level={support_level} />);
|
|
}
|
|
|
|
if (authentik_preview) {
|
|
badges.push(<span className="badge badge--preview">Preview</span>);
|
|
}
|
|
|
|
if (authentik_enterprise) {
|
|
badges.push(<span className="badge badge--primary">Enterprise</span>);
|
|
}
|
|
|
|
if (badges.length && !syntheticTitle) {
|
|
throw new MarkdownLintError(
|
|
`${id}: ${badges.length} Badge(s) found with a missing synthetic title. Remove the page heading and set it via the frontmatter.`,
|
|
);
|
|
}
|
|
|
|
if (frontMatter.title && contentTitle && frontMatter.title === contentTitle) {
|
|
throw new MarkdownLintError(
|
|
`${id}: Synthetic title "${frontMatter.title}" and content title "${contentTitle}" are the same. Remove the first heading and let the frontmatter set the title.`,
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className={clsx(ThemeClassNames.docs.docMarkdown, "markdown")}>
|
|
{syntheticTitle ? (
|
|
<header>
|
|
<Heading as="h1">{syntheticTitle}</Heading>
|
|
|
|
<BadgeGroup badges={badges} />
|
|
</header>
|
|
) : null}
|
|
|
|
{preReleaseDoc ? <PreReleaseAdmonition /> : null}
|
|
|
|
<MDXContent>{children}</MDXContent>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default DocItemContent;
|