From 9bc53d050e6ab320dd367c749e2280cd385abf0a Mon Sep 17 00:00:00 2001 From: HesterG Date: Fri, 9 Jun 2023 06:57:18 +0000 Subject: [PATCH] Use mdxa to point to versioned links (#27) Close #17 mdxa is another component that is safe to eject ![Screen Shot 2023-06-08 at 09.56.29](/attachments/b5af1044-9e3f-4776-91a1-ed6f69e2e3a7) And right now some links are using `master` as the branch(link will be redirect to `main`), so checked for that as well. Update: Change `master` to `main` in upstream, so also removed check for `master` https://github.com/go-gitea/gitea/pull/25126 # After For example: ![Screen Shot 2023-06-08 at 09.52.05](/attachments/5033b2ca-b51d-47da-ba20-a420e7613626) ![Screen Shot 2023-06-08 at 09.52.33](/attachments/6e7c75f5-01ab-40b4-a57c-df8edb81f677) ![Screen Shot 2023-06-08 at 09.52.47](/attachments/185eb828-6346-48a9-96cc-2beb6353410c) ![Screen Shot 2023-06-08 at 09.53.50](/attachments/f6c57dc1-d452-47f0-b4fc-f3766008ab57) Reviewed-on: https://gitea.com/gitea/gitea-docusaurus/pulls/27 Reviewed-by: Lunny Xiao Co-authored-by: HesterG Co-committed-by: HesterG --- src/theme/MDXComponents/A.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/theme/MDXComponents/A.js diff --git a/src/theme/MDXComponents/A.js b/src/theme/MDXComponents/A.js new file mode 100644 index 00000000..0abc0317 --- /dev/null +++ b/src/theme/MDXComponents/A.js @@ -0,0 +1,14 @@ +import React from 'react'; +import Link from '@docusaurus/Link'; +import {useDoc} from '@docusaurus/theme-common/internal'; + +export default function MDXA(props) { + // {assets, contentTitle, frontMatter, metadata, toc} + const {metadata} = useDoc(); + let newProps = {...props}; + if (metadata.version !== 'current' && (props.href.startsWith('https://github.com/go-gitea/gitea/blob/main'))) { + const versionedHref = props.href.replace('main', `release/v${metadata.version}`); + newProps = {...props, href: versionedHref}; + } + return ; +}