diff --git a/docusaurus.config.ts b/docusaurus.config.ts index 6a1af5a..be44ed6 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -29,6 +29,19 @@ const config: Config = { plugins: [ require.resolve('docusaurus-lunr-search'), + async function simpleWikiLink(context, options) { + return { + name: "simple-wiki-link-plugin", + async contentLoaded({actions}) { + const {addRoute} = actions; + addRoute({ + path: "/swl/:slug", + component: "@site/src/components/SimpleWikiLink", + exact: true, + }); + }, + }; + }, ], presets: [ @@ -41,8 +54,23 @@ const config: Config = { includeCurrentVersion: isDev, versions: { '1.16.x': { - banner: 'unmaintained' - } + banner: 'none' + }, + '1.17.x': { + banner: 'none' + }, + '1.18.x': { + banner: 'none' + }, + '1.19.x': { + banner: 'none' + }, + '1.20.x': { + banner: 'none' + }, + '1.21.x': { + banner: 'none' + }, } }, blog: { diff --git a/src/components/SimpleWikiLink/index.tsx b/src/components/SimpleWikiLink/index.tsx new file mode 100644 index 0000000..400588e --- /dev/null +++ b/src/components/SimpleWikiLink/index.tsx @@ -0,0 +1,75 @@ +import React, {useEffect} from "react"; +import {useParams} from "react-router-dom"; +import {useAllDocsData} from "@docusaurus/plugin-content-docs/client"; +import Layout from '@theme/Layout'; +import clsx from "clsx"; +import Heading from "@theme/Heading"; + +interface RouteParams { + slug: string; +} + +const SimpleWikiLink = () => { + const {slug: slugToSearch} = useParams(); + const allDocsData = useAllDocsData(); + + useEffect(() => { + if (!slugToSearch || !allDocsData) { + console.error("No 'slug' provided in query parameters or docs data unavailable."); + return; + } + + let docPath = null; + for (const docData of Object.values(allDocsData)) { + const sortedVersions = [...docData.versions].sort((a, b) => + a.name.localeCompare(b.name) + ); + + for (let i = sortedVersions.length - 1; i >= 0; i--) { + const version = sortedVersions[i]; + const matchingDoc = version.docs.find((doc) => { + const originalSlug = doc.id.startsWith("wiki/mods/") + ? doc.id.replace("wiki/mods/", "") + : null; + + if (!originalSlug) return false; + + const slug = originalSlug.endsWith("/index") + ? originalSlug.replace("/index", "") + : originalSlug; + + return slug === slugToSearch; + }); + + if (matchingDoc) { + docPath = matchingDoc.path; + break; + } + } + } + + console.log(`Found docPath: ${docPath}`); + if (docPath) { + window.location.href = docPath; + } else { + console.error("No 'slug' provided in query parameters."); + } + }, [slugToSearch, allDocsData]); + + return ( + +
+
+
+ + Searching wiki page for {slugToSearch}... + +

If you don't get redirected, I'm sorry. Search for yourself <3

+
+
+
+
+ ); +}; + +export default SimpleWikiLink;