Files
authentik/website/docusaurus-theme/components/VersionBadge.tsx
Jens L. 27bd6d6e92 website/docs: fix build (#19148)
* ensure we never throw errors in the browser

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* cleaner

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* rework

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* fix misleading variable

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* Tidy behavior.

---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Co-authored-by: Teffen Ellis <teffen@goauthentik.io>
2026-01-01 18:30:27 +00:00

61 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import {
assertVersionSupported,
VersionValidationError,
} from "@goauthentik/docusaurus-theme/releases/version";
import React from "react";
import { coerce } from "semver";
export interface AuthentikVersionProps {
semver: string;
docID: string;
}
/**
* Badge indicating semantic versioning of authentik required for a feature or integration.
*/
export const VersionBadge: React.FC<AuthentikVersionProps> = ({ semver, docID }) => {
const parsed = coerce(semver);
if (!parsed) {
throw new VersionValidationError(`Could not parse semver version: ${semver}`);
}
try {
assertVersionSupported(parsed);
} catch (error) {
if (!(error instanceof VersionValidationError)) {
throw error;
}
const message = `Outdated Markdown frontmatter for document \`${docID}\`: To fix this error, remove \`authentik_version: ${semver}\` from the Markdown frontmatter`;
console.warn(`\n\n⚠ ${message}:\n\n`, error.message, error.stack, "\n");
if (process.env.NODE_ENV === "production") {
console.debug("⚠️ Omitting outdated version badge in production build");
return null;
}
const versionError = new Error(message, {
cause: error,
});
throw versionError;
}
return (
<span
title={`Available in authentik ${parsed.format()} and later`}
aria-description="Version badge"
role="img"
className="badge badge--version"
>
authentik:&nbsp;{parsed.format()}+
</span>
);
};
export default VersionBadge;