Skip to content

Commit

Permalink
fix: fix the 3.0/2.1 version docs edit this page link error (#1146)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreys-cat authored Sep 27, 2024
1 parent e365d67 commit 240c0e7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
17 changes: 16 additions & 1 deletion src/constant/download.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1439,4 +1439,19 @@ export const RUN_ANYWHERE = [
description: 'Deploy Doris on AWS with CloudFormation templates',
link: 'https://doris.apache.org/docs/install/cluster-deployment/doris-on-aws',
},
];
];


export const DOWNLOAD_PDFS = [{
version: '3.0',
filename: 'Apache Doris 中文手册 (v3.0).pdf',
link: 'https://cdn.selectdb.com/static/Apache_Doris_v3_0_4412376f6e.pdf'
}, {
version: '2.1',
filename: 'Apache Doris 中文手册 (v2.1).pdf',
link: 'https://cdn.selectdb.com/static/Apache_Doris_v2_1_c8bc030188.pdf'
}, {
version: '2.0',
filename: 'Apache Doris 中文手册 (v2.0).pdf',
link: 'https://cdn.selectdb.com/static/Apache_Doris_v2_0_0b89998444.pdf'
}];
12 changes: 6 additions & 6 deletions src/theme/DocItem/Layout/pathTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ const transformPathWithoutZhCN = (pathname: string): string => {
return `${pathname.replace(/^\/docs\/(?:2\.1|2\.0|1\.2|dev)/, '').replace('/docs','').replace(/\/$/, '')}.md`;
} else {
const pathWithoutDocs = pathname.replace('/docs', '');
if (pathname.includes('/2.1')) {
return `/versioned_docs/version-2.1${pathWithoutDocs.replace('/2.1', '')}.md`;
if (pathname.includes('/3.0')) {
return `/versioned_docs/version-2.1${pathWithoutDocs.replace('/3.0', '')}.md`;
} else if (pathname.includes('/2.0')) {
return `/versioned_docs/version-2.0${pathWithoutDocs.replace('/2.0', '')}.md`;
} else if (pathname.includes('/1.2')) {
return `/versioned_docs/version-1.2${pathWithoutDocs.replace('/1.2', '')}.md`;
} else if (pathname.includes('/dev')) {
return `/docs${pathWithoutDocs.replace('/dev', '')}.md`;
} else {
return `/versioned_docs/version-3.0${pathWithoutDocs}.md`;
return `/versioned_docs/version-2.1${pathWithoutDocs}.md`;
}
}
};
Expand All @@ -30,16 +30,16 @@ const transformPathWithZhCN = (pathname: string): string => {
} else if (pathname.includes('/releasenotes')) {
return `/common_docs_zh/releasenotes/${pathname.replace(/^\/zh-CN\/docs(?:\/(?:2\.1|2\.0|1\.2|dev))?\/releasenotes\//,'')}.md`;
} else if (pathname.includes('/docs')) {
if (pathname.includes('/2.1')) {
return `/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1${pathname.replace('/zh-CN/docs/2.1', '')}.md`;
if (pathname.includes('/3.0')) {
return `/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0${pathname.replace('/zh-CN/docs/3.0', '')}.md`;
} else if (pathname.includes('/2.0')) {
return `/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0${pathname.replace('/zh-CN/docs/2.0', '')}.md`;
} else if (pathname.includes('/1.2')) {
return `/i18n/zh-CN/docusaurus-plugin-content-docs/version-1.2${pathname.replace('/zh-CN/docs/1.2', '')}.md`;
} else if (pathname.includes('/dev')) {
return `/i18n/zh-CN/docusaurus-plugin-content-docs/current${pathname.replace('/zh-CN/docs/dev', '')}.md`;
} else {
return `/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0${pathname.replace('/zh-CN/docs', '')}.md`;;
return `/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1${pathname.replace('/zh-CN/docs', '')}.md`;;
}
} else {
return pathname;
Expand Down
28 changes: 25 additions & 3 deletions src/theme/DocSidebar/Desktop/Content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import DownloadPdfActive from '@site/static/images/download-pdf-active.svg';
import DocSidebarItems from '@theme/DocSidebarItems';
import styles from './styles.module.css';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import { DOWNLOAD_PDFS } from '@site/src/constant/download.data';
// import { getLatestVersion } from '../../../../../docusaurus.config';
// import { useActivePluginAndVersion } from '@docusaurus/plugin-content-docs/client';
// import { useGlobalData } from '@docusaurus/useGlobalData';
Expand All @@ -26,6 +27,20 @@ function useShowAnnouncementBar() {
return isActive && showAnnouncementBar;
}

function downloadFile(url, filename) {
var xml = new XMLHttpRequest();
xml.open('GET', url, true);
xml.responseType = 'blob';
xml.onload = function () {
var url = window.URL.createObjectURL(xml.response);
var a = document.createElement('a');
a.href = url;
a.download = filename;
a.click();
};
xml.send();
}

export default function DocSidebarDesktopContent({ path, sidebar, className }) {
const showAnnouncementBar = useShowAnnouncementBar();
const { siteConfig } = useDocusaurusContext()
Expand Down Expand Up @@ -68,9 +83,16 @@ export default function DocSidebarDesktopContent({ path, sidebar, className }) {
<ul className={clsx(ThemeClassNames.docs.docSidebarMenu, 'menu__list')}>
{showVersion && <div className={styles.currentVersion}>
{isEN ? 'Version:' : '当前版本:'} {currentVersion}
{/* <div onMouseLeave={() => setIshover(false)} onMouseEnter={() => setIshover(true)} className="cursor-pointer">
{isHover ? <DownloadPdfActive /> : <DownloadPdf />}
</div> */}
{
['3.0', '2.0', '2.1'].includes(currentVersion) && (
<div onMouseLeave={() => setIshover(false)} onMouseEnter={() => setIshover(true)} className="cursor-pointer" onClick={() => {
const pdfInfo = DOWNLOAD_PDFS.find(item => item.version === currentVersion);
downloadFile(pdfInfo.link, pdfInfo.filename);
}}>
{isHover ? <DownloadPdfActive /> : <DownloadPdf />}
</div>
)
}
</div>}
<DocSidebarItems items={sidebar} activePath={path} level={1} />
</ul>
Expand Down

0 comments on commit 240c0e7

Please sign in to comment.