diff --git a/src/components/blog/index.jsx b/src/components/blog/index.jsx index a655cdc..d71001d 100644 --- a/src/components/blog/index.jsx +++ b/src/components/blog/index.jsx @@ -121,7 +121,8 @@ const Blog = ({ loading, blog, googleAnalytics }) => { console.error(error); } - window.open(article.link, '_blank'); + typeof window !== 'undefined' && + window.open(article.link, '_blank'); }} >
diff --git a/src/components/project/index.jsx b/src/components/project/index.jsx index 3f9397d..30641d4 100644 --- a/src/components/project/index.jsx +++ b/src/components/project/index.jsx @@ -72,7 +72,7 @@ const Project = ({ repo, loading, github, googleAnalytics }) => { console.error(error); } - window.open(item.html_url, '_blank'); + typeof window !== 'undefined' && window.open(item.html_url, '_blank'); }} >
diff --git a/src/helpers/utils.jsx b/src/helpers/utils.jsx index 3d53a06..79dc21a 100644 --- a/src/helpers/utils.jsx +++ b/src/helpers/utils.jsx @@ -17,7 +17,8 @@ export const getInitialTheme = (themeConfig) => { } if (themeConfig.respectPrefersColorScheme && !themeConfig.disableSwitch) { - return window.matchMedia('(prefers-color-scheme: dark)').matches + return typeof window !== 'undefined' && + window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : themeConfig.defaultTheme; } @@ -57,8 +58,10 @@ export const ga = { // initialize google analytic initialize: (id) => { try { - window.gtag('js', new Date()); - window.gtag('config', id); + if (typeof window !== 'undefined') { + window.gtag('js', new Date()); + window.gtag('config', id); + } } catch (error) { console.error(error); } @@ -66,7 +69,7 @@ export const ga = { // log specific events happening event: ({ action, params }) => { try { - window.gtag('event', action, params); + typeof window !== 'undefined' && window.gtag('event', action, params); } catch (error) { console.error(error); }