diff --git a/packages/docusaurus-config/lib/navbar.js b/packages/docusaurus-config/lib/navbar.js new file mode 100644 index 0000000000..c2b6355209 --- /dev/null +++ b/packages/docusaurus-config/lib/navbar.js @@ -0,0 +1,110 @@ +/** + * @file Docusaurus navbar configuration for the authentik website. + * + * @import { NavbarItem } from "@docusaurus/theme-common"; + */ +import { DocusaurusURL, SocialURL } from "./routing.js"; + +/** + * The navbar items for the authentik website. + * + * @type {NavbarItem[]} + */ +export const SocialNavbarItems = /** @type {const} */ ([ + { + "href": SocialURL.GitHub, + "data-icon": "github", + "aria-label": "GitHub", + "position": "right", + }, + { + "href": SocialURL.Discord, + "data-icon": "discord", + "aria-label": "Discord", + "position": "right", + }, +]); + +/** + * The navbar items for the authentik website. + * + * @satisfies {NavbarItem[]} + */ +export const NavbarItemsTemplate = /** @type {const} */ ([ + { + to: "{{WWW_URL}}/features", + label: "Features", + position: "left", + target: "_self", + }, + { + to: "{{INTEGRATIONS_URL}}", + label: "Integrations", + target: "_self", + position: "left", + }, + { + to: "{{DOCS_URL}}", + + label: "Documentation", + position: "left", + target: "_self", + }, + { + to: "{{WWW_URL}}/pricing/", + label: "Pricing", + position: "left", + target: "_self", + }, + { + to: "{{WWW_URL}}/blog", + label: "Blog", + position: "left", + target: "_self", + }, + ...SocialNavbarItems, +]); + +/** + * @typedef {Object} NavbarItemOverrides + * + * @prop {string} WWW_URL The URL for the WWW environment. + * @prop {string} DOCS_URL The URL for the documentation. + * @prop {string} INTEGRATIONS_URL The URL for the integrations. + */ + +const DEFAULT_NAVBAR_REPLACEMENTS = /** @type {const} */ ({ + DOCS_URL: DocusaurusURL.Docs, + INTEGRATIONS_URL: DocusaurusURL.Integrations, + WWW_URL: DocusaurusURL.WWW, +}); + +/** + * Creates a navbar item array, replacing placeholders with the given replacements. + * + * @param {Partial} [overrides] + * @returns {NavbarItem[]} + */ +export function createNavbarItems(overrides) { + const replacements = { + ...DEFAULT_NAVBAR_REPLACEMENTS, + ...overrides, + }; + + return NavbarItemsTemplate.map((item) => { + if (typeof item.to !== "string") return item; + + return { + ...item, + to: item.to.replace( + /{{([^}]+)}}/g, + /** + * @param {keyof NavbarItemOverrides} key + */ + (_, key) => { + return replacements[key]; + }, + ), + }; + }); +} diff --git a/packages/docusaurus-config/lib/routing.js b/packages/docusaurus-config/lib/routing.js new file mode 100644 index 0000000000..e0794f5b4d --- /dev/null +++ b/packages/docusaurus-config/lib/routing.js @@ -0,0 +1,35 @@ +/** + * @file Docusaurus routing configuration. + */ + +/** + * @typedef {'production'|'development'} NodeEnvironment + */ + +const NodeEnvironment = /** @type {NodeEnvironment} */ (process.env.NODE_ENV || "development"); + +/** + * @satisfies {Record>} + */ +export const DocusaurusURLByEnvironment = /** @type {const} */ ({ + development: { + Docs: "http://localhost:3000", + Integrations: "http://localhost:3001", + WWW: "http://localhost:3002", + }, + production: { + Docs: "https://docs.goauthentik.io", + Integrations: "https://integrations.goauthentik.io", + WWW: "https://goauthentik.io", + }, +}); + +export const DocusaurusURL = DocusaurusURLByEnvironment[NodeEnvironment]; + +/** + * @satisfies {Record} + */ +export const SocialURL = /** @type {const} */ ({ + Discord: "https://goauthentik.io/discord", + GitHub: "https://github.com/goauthentik/authentik", +}); diff --git a/packages/docusaurus-config/package-lock.json b/packages/docusaurus-config/package-lock.json index 48f7121698..b8e90b0c16 100644 --- a/packages/docusaurus-config/package-lock.json +++ b/packages/docusaurus-config/package-lock.json @@ -1,12 +1,12 @@ { "name": "@goauthentik/docusaurus-config", - "version": "2.1.0", + "version": "2.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@goauthentik/docusaurus-config", - "version": "2.1.0", + "version": "2.1.1", "license": "MIT", "dependencies": { "deepmerge-ts": "^7.1.5", diff --git a/packages/docusaurus-config/package.json b/packages/docusaurus-config/package.json index 1af5a531f1..92c993437e 100644 --- a/packages/docusaurus-config/package.json +++ b/packages/docusaurus-config/package.json @@ -1,6 +1,6 @@ { "name": "@goauthentik/docusaurus-config", - "version": "2.1.0", + "version": "2.1.1", "description": "authentik's Docusaurus config", "license": "MIT", "scripts": {