diff --git a/src/components/Button.js b/src/components/Button.js index f235ce5..414762d 100644 --- a/src/components/Button.js +++ b/src/components/Button.js @@ -9,6 +9,7 @@ import { Link } from "gatsby"; import AnchorLink from 'react-anchor-link-smooth-scroll-v2' import rippleFn from "../libs/ripple"; import classNames from "classnames"; +import { getPathName } from "../libs/utils"; const ButtonInner = ({ icon, text, className }) => (
@@ -17,15 +18,9 @@ const ButtonInner = ({ icon, text, className }) => (
); -const GetPathName = () => { - if (typeof window !== "undefined") - return window.location.pathname; - return ""; -} - const Button = ({ href="", icon, text, onClick, className }) => { - if (href.startsWith(GetPathName() + "#")) - href = href.substring(GetPathName().length); + if (href.startsWith(getPathName() + "#")) + href = href.substring(getPathName().length); return href.startsWith("http") ? ( diff --git a/src/components/CustomLink.js b/src/components/CustomLink.js index 1e419d3..44e3231 100644 --- a/src/components/CustomLink.js +++ b/src/components/CustomLink.js @@ -9,16 +9,11 @@ import { Link } from "gatsby"; import AnchorLink from 'react-anchor-link-smooth-scroll-v2' import rippleFn from "../libs/ripple"; import classnames from "classnames"; - -const GetPathName = () => { - if (typeof window !== "undefined") - return window.location.pathname; - return ""; -} +import { getPathName } from "../libs/utils"; const CustomLink = ({ style, href, children, className, ripple }) => { - if (href.startsWith(GetPathName() + "#")) - href = href.substring(GetPathName().length); + if (href.startsWith(getPathName() + "#")) + href = href.substring(getPathName().length); return href.startsWith("http") ? ( typeof window !== "undefined" +import { isBrowser } from "./utils"; +import { colorSchemeMedia } from "./utils"; const configureDarkMode = () => { diff --git a/src/libs/utils.js b/src/libs/utils.js new file mode 100644 index 0000000..1da5485 --- /dev/null +++ b/src/libs/utils.js @@ -0,0 +1,17 @@ +/** + * @license + * Copyright © 2022 Skyline Team and Contributors (https://github.com/skyline-emu/) + * SPDX-License-Identifier: BSD-3-Clause + */ + +export const colorSchemeMedia = "(prefers-color-scheme: dark)"; +export const isBrowser = () => typeof window !== "undefined" +export const getPathName = () => { + + if (isBrowser()) { + return window.location.pathname; + } else { + return ""; + } + +}