tisonkun commented on code in PR #481:
URL: https://github.com/apache/pulsar-site/pull/481#discussion_r1143269164
##########
src/theme/DocPage/index.tsx:
##########
@@ -0,0 +1,74 @@
+import React from 'react';
+import clsx from 'clsx';
+import {HtmlClassNameProvider, PageMetadata, ThemeClassNames,} from
'@docusaurus/theme-common';
+import {
+ DocsSidebarProvider,
+ DocsVersionProvider,
+ docVersionSearchTag,
+ useDocRouteMetadata,
+} from '@docusaurus/theme-common/internal';
+import DocPageLayout from '@theme/DocPage/Layout';
+import NotFound from '@theme/NotFound';
+import SearchMetadata from '@theme/SearchMetadata';
+import type {Props} from '@theme/DocPage';
+import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
+import useBaseUrl from "@docusaurus/useBaseUrl";
+
+function createCanonicalHref(props: Props): string {
+ const {siteConfig} = useDocusaurusContext();
+ const {versionMetadata, location, match} = props;
+ if (versionMetadata.version === 'current') {
+ // 1. The NEXT version docs should not forward to the latest stable version
+ // 2. Other plugins-doc instance (contribute, release-note, ...) happens
to keep the link
+ return siteConfig.url + useBaseUrl(location.pathname);
+ }
+ const basename = location.pathname.replace(match.path, '');
+ return siteConfig.url + useBaseUrl(`/docs/${basename}`);
+}
+function DocPageMetadata(props: Props): JSX.Element {
+ const {versionMetadata} = props;
+ return (
+ <>
+ <SearchMetadata
+ version={versionMetadata.version}
+ tag={docVersionSearchTag(
+ versionMetadata.pluginId,
+ versionMetadata.version,
+ )}
+ />
+ <PageMetadata>
+ {versionMetadata.noIndex && (
Review Comment:
Actually, if we properly configure `noIndex`, we can exclude old versions
docs being indexed by the search engine.
The canonical link tweak can bring old links don't exist in latest version,
but as we set up redirections properly, it's not a big problem.
cc @vinayrajsn @momo-jun @dave2wave thoughts?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]