mirror of
https://github.com/goauthentik/authentik.git
synced 2026-06-18 11:29:26 +03:00
db3fb0bf2e
Cherry-pick #16430 to version-2025.8 (with conflicts)
This cherry-pick has conflicts that need manual resolution.
Original PR: #16430
Original commit: 6d81aea5aa
Co-authored-by: Teffen Ellis <592134+GirlBossRush@users.noreply.github.com>
80 lines
2.3 KiB
JavaScript
80 lines
2.3 KiB
JavaScript
/* eslint-disable no-console */
|
|
/**
|
|
* @file Docusaurus releases plugin.
|
|
*
|
|
* @import { LoadContext, Plugin } from "@docusaurus/types"
|
|
* @import { AKReleasesPluginEnvironment } from "./node.mjs"
|
|
*/
|
|
|
|
import * as fs from "node:fs/promises";
|
|
import * as path from "node:path";
|
|
|
|
import { collectReleaseFiles, prepareReleaseEnvironment } from "./node.mjs";
|
|
|
|
const PLUGIN_NAME = "ak-releases-plugin";
|
|
const RELEASES_FILENAME = "releases.gen.json";
|
|
|
|
/**
|
|
* @typedef {object} AKReleasesPluginOptions
|
|
* @property {string} docsDirectory The path to the documentation directory.
|
|
* @property {AKReleasesPluginEnvironment} [environment] Optional environment variables overrides.
|
|
*/
|
|
|
|
/**
|
|
* @typedef {object} AKReleasesPluginData
|
|
* @property {string} publicPath URL to the plugin's public directory.
|
|
* @property {string[]} releases Available versions of the documentation.
|
|
* @property {AKReleasesPluginEnvironment} env Environment variables
|
|
*/
|
|
|
|
/**
|
|
* @param {LoadContext} loadContext
|
|
* @param {AKReleasesPluginOptions} options
|
|
* @returns {Promise<Plugin<AKReleasesPluginData>>}
|
|
*/
|
|
async function akReleasesPlugin(loadContext, options) {
|
|
return {
|
|
name: PLUGIN_NAME,
|
|
|
|
async loadContent() {
|
|
console.log(`🚀 ${PLUGIN_NAME} loaded`);
|
|
|
|
const environment = {
|
|
...prepareReleaseEnvironment(),
|
|
...options.environment,
|
|
};
|
|
|
|
const releases = collectReleaseFiles(options.docsDirectory).map(
|
|
(release) => release.name,
|
|
);
|
|
|
|
const outputPath = path.join(loadContext.siteDir, "static", RELEASES_FILENAME);
|
|
|
|
await fs.mkdir(path.dirname(outputPath), { recursive: true });
|
|
await fs.writeFile(outputPath, JSON.stringify(releases, null, 2), "utf-8");
|
|
console.log(`✅ ${RELEASES_FILENAME} generated`);
|
|
|
|
/**
|
|
* @type {AKReleasesPluginData}
|
|
*/
|
|
const content = {
|
|
releases,
|
|
publicPath: path.join("/", RELEASES_FILENAME),
|
|
env: environment,
|
|
};
|
|
|
|
content.publicPath;
|
|
|
|
return content;
|
|
},
|
|
|
|
contentLoaded({ content, actions }) {
|
|
const { setGlobalData } = actions;
|
|
|
|
setGlobalData(content);
|
|
},
|
|
};
|
|
}
|
|
|
|
export default akReleasesPlugin;
|