Skip to content

Commit

Permalink
Merge pull request #1241 from near/develop
Browse files Browse the repository at this point in the history
2x weekly promotion of develop to main
  • Loading branch information
gagdiez authored Jul 4, 2024
2 parents 5992043 + d9e9cea commit 369b98e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
10 changes: 0 additions & 10 deletions src/pages/documentation.tsx

This file was deleted.

41 changes: 41 additions & 0 deletions src/pages/documentation/[[...slug]].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { useEffect } from 'react';
import { useDefaultLayout } from '@/hooks/useLayout';
import type { NextPageWithLayout } from '@/utils/types';
import { useRouter } from 'next/router';

const Documentation: NextPageWithLayout = () => {
const router = useRouter();
const { slug } = router.query;
const currentPath = Array.isArray(slug) ? `/${slug.join('/')}` : '';

const path = currentPath.replace(/\/documentation/g, '');

useEffect(() => {
const handleIframeMessage = (event: MessageEvent) => {
if (event.data.type === 'urlChange' && event.data.url && event.data.url !== path) {
const url = event.data.url.replace(/\/documentation/g, '');

const newUrl = `/documentation${url}`;
if (window.location.pathname !== newUrl) {
window.history.pushState({}, '', newUrl);
}
}
};

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

return (
<iframe
style={{ flexGrow: 'inherit', width: '100%', height: '100vh' }}
src={`https://docs.near.org${path}`}
></iframe>
);
};

Documentation.getLayout = useDefaultLayout;

export default Documentation;

0 comments on commit 369b98e

Please sign in to comment.