Skip to content

Commit

Permalink
push route fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
corlard3y committed Sep 20, 2024
1 parent 285d9c8 commit 70eec5e
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 68 deletions.
19 changes: 11 additions & 8 deletions src/segments/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useLocation } from '@docusaurus/router';
import { useTranslation } from 'react-i18next';
import { BsTwitterX } from 'react-icons/bs';
import styled from 'styled-components';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';

// Internal Components
import {
Expand Down Expand Up @@ -38,6 +39,8 @@ function Footer() {
const { t } = useTranslation();
const isMobile = useMediaQuery(device.mobileL);
const isTablet = useMediaQuery(device.tablet);
const { siteConfig } = useDocusaurusContext();
const baseURL = siteConfig?.baseUrl.slice(0, -1) || '';

// for navigation
const history = useHistory();
Expand All @@ -57,7 +60,7 @@ function Footer() {
if (href.includes('http')) {
window.location.href = href;
} else {
history.push(href);
history.push(baseURL + href);
}
scrollToTop();
}
Expand All @@ -66,20 +69,20 @@ function Footer() {
if (href.includes('http')) {
window.open(href, target);
} else {
window.open(`${window.location.origin}${href}`, target);
window.open(`${window.location.origin}${baseURL + href}`, target);
}
// scrollToTop();
}
} else if (id) {
if (location?.pathname !== '/' && id) {
history.push('/');
if (location?.pathname !== baseURL + '/' && id) {
history.push(baseURL + '/');
setTimeout(() => {
document.getElementById(id).scrollIntoView({ behavior: 'smooth' });
}, 1500);
document.getElementById(id)?.scrollIntoView({ behavior: 'smooth' });
}, 300);
}

if (location?.pathname === '/') {
document.getElementById(id).scrollIntoView({ behavior: 'smooth' });
if (location?.pathname === baseURL + '/') {
document.getElementById(id)?.scrollIntoView({ behavior: 'smooth' });
}
} else return;
};
Expand Down
57 changes: 7 additions & 50 deletions src/segments/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
Span,
} from '@site/src/css/SharedStyling';
import useMediaQuery from '@site/src/hooks/useMediaQuery';
import { getPublicAssetPath } from '../utils/useRouteHelper';

// Import Assets
import { AiOutlineClose } from 'react-icons/ai';
Expand Down Expand Up @@ -70,7 +69,7 @@ function Header() {
const [scrollDirection, setScrollDirection] = useState(null);
const location = useLocation();
const { siteConfig } = useDocusaurusContext();
const baseUrl = siteConfig?.baseUrl.slice(0, -1);
const baseURL = siteConfig?.baseUrl.slice(0, -1) || '';
// const [isAlertVisible, setIsAlertVisible] = useState(true);

// for navigation
Expand Down Expand Up @@ -161,75 +160,33 @@ function Header() {
if (href.includes('http')) {
window.location.href = href;
} else {
history.push(baseUrl + href);
history.push(baseURL + href);
}
}
} else {
// check if url is internal and if so append the base url
if (href.includes('http')) {
window.open(href, target);
} else {
window.open(`${window.location.origin}${baseUrl + href}`, target);
window.open(`${window.location.origin}${baseURL + href}`, target);
}
}
} else if (id) {
if (showMobileMenu) toggleMobileMenu();

if (location?.pathname !== '/' && id) {
// history.push('/');
if (location?.pathname !== baseURL + '/' && id) {
history.push(baseURL + '/');
setTimeout(() => {
document.getElementById(id)?.scrollIntoView({ behavior: 'smooth' });
}, 500);
}, 200);
}

if (location?.pathname === '/') {
if (location?.pathname === baseURL + '/') {
document.getElementById(id)?.scrollIntoView({ behavior: 'smooth' });
}
} else return;
};

// const HeaderSpace = ({ item, index }) => {
// const openLink = async (e, href, id, target) => {
// e.stopPropagation();

// if (href) {
// if (target && target !== '_blank') {
// if (target === '_self') {
// // check if url is external
// if (href.includes('http')) {
// window.location.href = href;
// } else {
// history.push(href);
// }
// }
// } else {
// // check if url is internal and if so append the base url
// if (href.includes('http')) {
// window.open(href, target);
// } else {
// window.open(`${window.location.origin}${href}`, target);
// }
// }
// } else if (id) {
// if (showMobileMenu) toggleMobileMenu();

// // gsap.to(window, {
// // duration: 0.75,
// // scrollTo: { y: `#${id}` },
// // });
// if (location.pathname !== '/' && id) {
// history.push('/');
// setTimeout(() => {
// document.getElementById(id).scrollIntoView({ behavior: 'smooth' });
// }, 1500);
// }

// if (location.pathname === '/') {
// document.getElementById(id).scrollIntoView({ behavior: 'smooth' });
// }
// } else return;
// };

return (
<HeaderItem onClick={(e) => openLink(e, item.href, item.id, item.target)}>
{item.srcrefoff && (
Expand Down
14 changes: 10 additions & 4 deletions src/theme/Navbar/Content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import styled from 'styled-components';
import { HeaderList } from '../../../config/HeaderList';
import styles from './styles.module.css';
import useBaseUrl from '@docusaurus/useBaseUrl';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';

const defaultMobileMenuState = {
0: false,
Expand Down Expand Up @@ -84,10 +85,15 @@ export default function NavbarContent() {
const history = useHistory();
const location = useLocation();
const pathname = location?.pathname;
const { siteConfig } = useDocusaurusContext();
const baseURL = siteConfig?.baseUrl.slice(0, -1) || '';

const mobileSidebar = useNavbarMobileSidebar();
const items = useNavbarItems();
const [rightItems] = splitNavbarItems(items);

// eslint has to disabled for this line cause the leftItems is required
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [leftItems, rightItems] = splitNavbarItems(items);
const searchBarItem = items.find((item) => item.type === 'search');

const isLaptopM = useMediaQuery(device.laptopM);
Expand Down Expand Up @@ -126,15 +132,15 @@ export default function NavbarContent() {
if (href.includes('http')) {
window.location.href = href;
} else {
history.push(href);
history.push(baseURL + href);
}
}
} else {
// check if url is internal and if so append the base url
if (href.includes('http')) {
window.open(href, target);
} else {
window.open(`${window.location.origin}${href}`, target);
window.open(`${window.location.origin}${baseURL + href}`, target);
}
}
} else if (id) {
Expand Down Expand Up @@ -225,7 +231,7 @@ export default function NavbarContent() {

{/* Change Header from docs to blog if required */}
{!isLaptopM &&
(pathname.startsWith('/docs') ? (
(pathname.startsWith(baseURL + '/docs') ? (
<NavItem to={useBaseUrl('/docs')} aria-label='Push Docs'>
Docs
</NavItem>
Expand Down
6 changes: 4 additions & 2 deletions src/theme/NotFound/Content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ import styled from 'styled-components';

// Internal Components
import Footer from '../../../segments/Footer';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';

export default function NotFoundContent({ className }: Props): JSX.Element {
const location = useLocation();
const { siteConfig } = useDocusaurusContext();
const baseURL = siteConfig?.baseUrl.slice(0, -1);

// Determine if the pathname starts with '/docs'
const isDocsPage = location?.pathname.startsWith('/docs');
const isDocsPage = location?.pathname.startsWith(baseURL + '/docs');

return (
<PageContainer isDocsPage={isDocsPage!}>
Expand Down Expand Up @@ -61,7 +64,6 @@ export default function NotFoundContent({ className }: Props): JSX.Element {
</Content>
</Section>


{isDocsPage && <Footer />}
</PageContainer>
);
Expand Down
6 changes: 5 additions & 1 deletion src/theme/NotFound/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ import { PageMetadata } from '@docusaurus/theme-common';
import Layout from '@theme/Layout';
import NotFoundContent from '@theme/NotFound/Content';
import { useLocation } from '@docusaurus/router';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';

export default function Index(): JSX.Element {
const location = useLocation();
const pathname = location?.pathname;
const { siteConfig } = useDocusaurusContext();

const baseURL = siteConfig?.baseUrl.slice(0, -1);

const title = translate({
id: 'theme.NotFound.title',
Expand All @@ -30,7 +33,8 @@ export default function Index(): JSX.Element {

<Layout
showNavbar={
!pathname.startsWith('/docs') && !pathname.startsWith('/blog')
!pathname.startsWith(baseURL + '/docs') &&
!pathname.startsWith(baseURL + '/blog')
? 'website'
: 'docusaurus'
}
Expand Down
6 changes: 3 additions & 3 deletions src/theme/Root.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ export default function Root({ children }) {
},
];

const isPreview = siteConfig?.baseUrl.slice(0, -1);
const baseURL = siteConfig?.baseUrl.slice(0, -1);

// return superimposed class names if conditions are met
function returnAdditionalClasses(conditions) {
let result = '';
for (var i = 0; i < conditions.length; i++) {
const item = conditions[i];
const pathname = isPreview + item?.pathname;
const pathname = baseURL + item?.pathname;

if (locationPathExists(pathname, item.condition)) {
result = item.classname;
Expand All @@ -63,7 +63,7 @@ export default function Root({ children }) {

// enable disable default config
function excludeDefaultConfigAt(pathname, condition) {
const fullPathname = isPreview + pathname;
const fullPathname = baseURL + pathname;
return !locationPathExists(fullPathname, condition);
}

Expand Down

0 comments on commit 70eec5e

Please sign in to comment.