Skip to content

Commit

Permalink
feat: modify new page router
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongyunWan committed Nov 19, 2024
1 parent 81937f2 commit 978d501
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 66 deletions.
128 changes: 71 additions & 57 deletions .umirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,91 +9,105 @@ export default defineConfig({
favicon:
'https://gw.alipayobjects.com/zos/bmw-prod/6290edfc-e134-4074-a550-079eeba9926d.svg',
routes: [
{ path: '/', component: '@/pages/index' },
{ path: '/product', component: '@/pages/product', title: 'product.title' },
{
path: '/learn',
component: '@/pages/product_learn',
title: 'product.title',
},
{
path: '/analytics',
component: '@/pages/product_analytics',
title: 'product.title',
},
{ path: '/case', component: '@/pages/case', title: 'case.title' },
{
path: '/ecosystem',
component: '@/pages/ecosystem',
title: 'ecosystem.title',
},
{ path: '/doc', component: '@/pages/doc', title: 'doc.title' },
{ path: '/blog', component: '@/pages/blog', title: 'blog.title' },
// { path: '/', component: '@/pages/index' },
// { path: '/product', component: '@/pages/product', title: 'product.title' },
// {
// path: '/learn',
// component: '@/pages/product_learn',
// title: 'product.title',
// },
// {
// path: '/analytics',
// component: '@/pages/product_analytics',
// title: 'product.title',
// },
// { path: '/case', component: '@/pages/case', title: 'case.title' },
// {
// path: '/ecosystem',
// component: '@/pages/ecosystem',
// title: 'ecosystem.title',
// },
// { path: '/doc', component: '@/pages/doc', title: 'doc.title' },
// { path: '/blog', component: '@/pages/blog', title: 'blog.title' },
// {
// path: '/download',
// component: '@/pages/download',
// title: 'download.title',
// },
// {
// path: '/overview',
// component: '@/pages/overview',
// title: 'product.title',
// },
// {
// path: '/platform',
// component: '@/pages/platform',
// title: 'platform.title',
// },
// {
// path: '/db',
// component: '@/pages/platform',
// title: 'db.title',
// },
// {
// path: '/docs/*',
// component: '@/pages/docs',
// title: 'docs.title',
// },
// {
// path: '/docs',
// component: '@/pages/docs',
// title: 'docs.title',
// },
// new pages
{
path: '/download',
component: '@/pages/download',
title: 'download.title',
path: '/',
component: '@/pages/new-pages/Home',
},
{
path: '/overview',
component: '@/pages/overview',
path: '/product',
component: '@/pages/new-pages/Product',
title: 'product.title',
},
{
path: '/platform',
component: '@/pages/platform',
title: 'platform.title',
},
{
path: '/db',
component: '@/pages/platform',
title: 'db.title',
path: '/case',
component: '@/pages/new-pages/Case',
title: 'case.title',
},
{
path: '/docs/*',
component: '@/pages/docs',
title: 'docs.title',
path: '/partners',
component: '@/pages/new-pages/Partners',
},
{
path: '/docs',
component: '@/pages/docs',
component: '@/pages/new-pages/Docs',
title: 'docs.title',
},
// new pages
{
path: '/new',
component: '@/pages/new-pages/Home',
},
{
path: '/new/product',
component: '@/pages/new-pages/Product',
},
{
path: '/new/case',
component: '@/pages/new-pages/Case',
},
{
path: '/new/partners',
component: '@/pages/new-pages/Partners',
path: '/docs/*',
component: '@/pages/new-pages/Docs',
title: 'docs.title',
},
{
path: '/new/download',
path: '/download',
component: '@/pages/new-pages/Download',
title: 'download.title',
},
{
path: '/new/blog/list',
path: '/blog/list',
component: '@/pages/new-pages/Blog/list',
title: 'blog.title',
},
{
path: '/new/blog/info',
path: '/blog/info',
component: '@/pages/new-pages/Blog/info',
},
{
path: '/new/activity/list',
path: '/activity/list',
component: '@/pages/new-pages/Activity/list',
},
{
path: '/new/activity/info',
path: '/activity/info',
component: '@/pages/new-pages/Activity/info',
},
],
Expand Down
15 changes: 8 additions & 7 deletions src/components/NewHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export const NewHeader = ({ isStick }: { isStick?: boolean }) => {
subMenu: [
{
label: '博客',
path: '/new/blog/list',
path: '/blog/list',
},
{
label: '视频',
Expand All @@ -185,7 +185,7 @@ export const NewHeader = ({ isStick }: { isStick?: boolean }) => {
},
{
label: '活动',
path: '/new/activity/list',
path: '/activity/list',
},
],
},
Expand All @@ -200,7 +200,7 @@ export const NewHeader = ({ isStick }: { isStick?: boolean }) => {
},
{
label: '下载中心',
path: '/new/download',
path: '/download',
},
{
label: '白皮书与行业报告',
Expand Down Expand Up @@ -268,23 +268,24 @@ export const NewHeader = ({ isStick }: { isStick?: boolean }) => {
{
key: 'product',
label: intl.formatMessage({ id: 'header.product' }),
path: '/new/product',
path: '/product',
onMouseMove: () => onHover('subMenuProduct', 'move'),
onMouseLeave: () => onHover('subMenuProduct', 'leave'),
},
{
key: 'case',
label: '客户案例',
path: '/new/case',
path: '/case',
},
{
key: 'partners',
label: '合作伙伴',
path: '/new/partners',
path: '/partners',
},
{
key: 'docs',
label: '文档',
path: '/docs',
},

{
Expand Down Expand Up @@ -325,7 +326,7 @@ export const NewHeader = ({ isStick }: { isStick?: boolean }) => {
<div className={styles.header} id="Head">
<div className={styles.headerBox}>
<div className={styles.headerLeft}>
<a href={goLinkAt('/new')} rel="noopener noreferrer">
<a href={goLinkAt('/')} rel="noopener noreferrer">
<img
className={styles.log}
src="https://mdn.alipayobjects.com/huamei_p63okt/afts/img/V8XITL_lpf4AAAAAAAAAAAAADh8WAQFr/original"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const ActivityCard = () => {
return (
<div
className={styles.activityCard}
onClick={() => history.push(historyPushLinkAt('/new/activity/info'))}
onClick={() => history.push(historyPushLinkAt('/activity/info'))}
>
<div className={styles.activityImg}>
<div className={styles.activityTag}>报名中</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const BlogItem = () => {
return (
<div
className={styles.blogItem}
onClick={() => history.push(historyPushLinkAt('/new/blog/info'))}
onClick={() => history.push(historyPushLinkAt('/blog/info'))}
>
<img src="" alt="" className={styles.blogItemImg} />
<div className={styles.blogItemContent}>
Expand Down
81 changes: 81 additions & 0 deletions src/pages/new-pages/Docs/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* file: Tugraph Docs
* author: Allen
*/

import React, { useRef, useEffect, useState } from 'react';
import { setLocale, useLocation } from 'umi';
import { NewLayout } from '@/components/NewLayout';
import { getSearch } from '@/util';
import { DEFAULT_LOCAL } from '@/constant';

const Docs: React.FC = () => {
const location = useLocation();
const { search } = location;

const removePrefixFromPath = (path: string, prefix: string) => {
if (path.startsWith(prefix)) {
return path.slice(prefix.length);
}
return path;
};

const [iframeUrl, setIframeUrl] = useState<string>(() => {
if (['/docs', '/docs/'].includes(location.pathname)) {
window.history.pushState({}, '', '/docs/zh/4.5.0/guide');
return '/zh/4.5.0/guide';
}

return removePrefixFromPath(location.pathname + location.hash, '/docs');
});

console.log('iframeUrl:', iframeUrl);

const [solidIframeUrl] = useState<string>(() => {
return `https://zhongyunwan.github.io/tugraph-db${iframeUrl}`;
});

const iframeRef = useRef<HTMLIFrameElement>(null);

useEffect(() => {
/** switch language */
setLocale(getSearch(search)?.lang || DEFAULT_LOCAL, false);

const handleReceiveMessage = (event: MessageEvent) => {
if (event?.data?.path) {
const formatPath = removePrefixFromPath(
event?.data?.path,
'/tugraph-db',
);
setIframeUrl(formatPath);
window.history.pushState({}, '', '/docs' + formatPath);
}
};

window.addEventListener('message', handleReceiveMessage);

return () => {
window.removeEventListener('message', handleReceiveMessage);
};
}, []);

return (
<NewLayout
content={
<iframe
ref={iframeRef}
src={solidIframeUrl}
title="Docusaurus Docs"
style={{
width: '100%',
height: 'calc(100vh - 66px)',
marginTop: '66px',
border: 'none',
}}
/>
}
/>
);
};

export default Docs;

0 comments on commit 978d501

Please sign in to comment.