Skip to content

Commit

Permalink
Improve build speed (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
viphan007 authored Sep 17, 2024
1 parent 48805fb commit c006419
Show file tree
Hide file tree
Showing 12 changed files with 264 additions and 326 deletions.
1 change: 0 additions & 1 deletion gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ if (env.errors) {
'gatsby-transformer-sharp',
'gatsby-transformer-remark',
'gatsby-plugin-root-import',
'gatsby-transformer-inline-svg',
{
resolve: `gatsby-source-contentful`,
options: {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"gatsby-plugin-well-known": "^1.0.0",
"gatsby-source-contentful": "^8.13.2",
"gatsby-source-filesystem": "^5.0.0",
"gatsby-transformer-inline-svg": "^1.1.0",
"gatsby-transformer-remark": "^6.9.0",
"gatsby-transformer-sharp": "^5.12.3",
"gl-matrix": "^3.4.3",
Expand Down Expand Up @@ -95,7 +94,7 @@
"jest": "^29.7.0",
"p-whilst": "^2.0.0",
"prettier": "^1.15.2",
"puppeteer": "^21.7.0",
"puppeteer": "^23.3.1",
"stylelint": "^14.16.1",
"stylelint-config-property-sort-order-smacss": "^9.1.0",
"stylelint-config-recommended": "^9.0.0",
Expand Down
8 changes: 5 additions & 3 deletions src/components/Contentful/ContentfulLayoutFooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ const ContentfulLayoutFooter = props => {
return (
<Footer
logo={logo}
logoTitle={logo.title}
logoUrl={logo.logo.file.url}
logoSvg={logo.logo.svg}
menus={menuItems}
copyright={copyright}
previewMode={previewMode}
Expand Down Expand Up @@ -45,6 +42,11 @@ const parsePreviewData = data => {
url: data.logo.logo?.url,
},
},
logoDarkMode: {
file: {
url: data.logo.logoDarkMode?.url,
},
},
}
: undefined,
},
Expand Down
8 changes: 7 additions & 1 deletion src/components/Contentful/ContentfulLayoutHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const parsePreviewData = data => {
}
})
menuItems = !isEmpty(menuItems) ? menuItems : undefined

const dataUpdate = {
moduleConfig: {
previewMode: true,
Expand All @@ -64,7 +65,12 @@ const parsePreviewData = data => {
title: data.logo.title,
logo: {
file: {
url: data.logo.logo.url,
url: data.logo.logo?.url,
},
},
logoDarkMode: {
file: {
url: data.logo.logoDarkMode?.url,
},
},
}
Expand Down
28 changes: 14 additions & 14 deletions src/components/Footer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PropTypes from 'prop-types'
import React, { useEffect, useState } from 'react'
import React, { useContext, useEffect, useState } from 'react'
import styled from 'styled-components'
import ContextClientSide from '../Context/ContextClientSide'
import { contentfulModuleToComponent } from '../lib/utils/moduleToComponent'
import Link from './Link'
import Wrapper from './ContentWrapper'
Expand All @@ -10,7 +11,10 @@ import { GB_BLOCKED_PATHS } from '../lib/config.mjs'
import { useIsUKBlocked } from '../hooks/useIsUKBlocked'

const StyledFooter = props => {
const { menus, copyright, logoTitle, logoUrl, logoSvg, previewMode } = props
const { menus, copyright, logo, previewMode } = props

const { darkMode: darkModeContextValue } = useContext(ContextClientSide)
const { isDarkMode } = darkModeContextValue || {}

const [filteredMenus, setFilteredMenus] = useState(menus)

Expand All @@ -27,6 +31,9 @@ const StyledFooter = props => {
setFilteredMenus(filteredMenus)
}, [isUKBlocked, menus])

const footerLogo =
isDarkMode && logo?.logoDarkMode ? logo.logoDarkMode : logo?.logo

return (
<FooterContainer>
<Wrapper
Expand All @@ -36,18 +43,11 @@ const StyledFooter = props => {
<FooterInner>
<LogoContainer>
<Link to="/" aria-label="Go to the home page">
<LogoWrapper>
{logoSvg?.content ? (
<div
className="logoMetamaskSvg"
dangerouslySetInnerHTML={{
__html: logoSvg?.content,
}}
/>
) : (
<Logo src={logoUrl} alt={logoTitle} />
)}
</LogoWrapper>
{footerLogo?.file ? (
<LogoWrapper>
<Logo src={footerLogo.file.url} alt={footerLogo.title} />
</LogoWrapper>
) : null}
</Link>
</LogoContainer>
<ColumnWrapper columns={filteredMenus?.length}>
Expand Down
62 changes: 22 additions & 40 deletions src/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,7 @@ import { useCountry } from '../hooks/useCountry'

const StyledHeader = props => {
const {
logo: {
title: titleLogo,
logo: {
file: { url: srcLogo },
svg: svgLogo,
},
widthLogo,
},
logo,
logoMobile,
menus,
downloadButton,
Expand Down Expand Up @@ -167,6 +160,13 @@ const StyledHeader = props => {
}
}, [isUKBlocked, country, pathname, locale, menus])

const desktopLogo =
isDarkMode && logo?.logoDarkMode ? logo.logoDarkMode : logo?.logo
const mobileLogo =
isDarkMode && logoMobile?.logoDarkMode
? logoMobile.logoDarkMode
: logoMobile?.logo

return (
<HeaderElement ref={headerRef} className={classnames({ sticky: isSticky })}>
<Announcement>
Expand All @@ -178,46 +178,28 @@ const StyledHeader = props => {
<HeaderContainer>
<LogoContainer>
<Link to="/" aria-label="Go to home page">
{srcLogo ? (
{desktopLogo?.file ? (
<LogoWrapper
className={classnames({
'hidden-mobile': logoMobile,
})}
>
{svgLogo?.content ? (
<div
className="logoMetamaskSvg"
dangerouslySetInnerHTML={{
__html: svgLogo?.content,
}}
/>
) : (
<Logo
src={srcLogo}
alt={titleLogo}
$widthCustom={widthLogo}
/>
)}
<Logo
src={desktopLogo.file.url}
alt={desktopLogo.title}
$widthCustom={desktopLogo.widthLogo}
/>
</LogoWrapper>
) : null}
{logoMobile ? (
{mobileLogo?.file ? (
<LogoWrapper className={classnames('hidden-desktop')}>
{logoMobile.logo.svg?.content ? (
<div
className="logoMetamaskSvg"
dangerouslySetInnerHTML={{
__html: logoMobile.logo.svg?.content,
}}
/>
) : (
<Logo
src={logoMobile.logo.file.url}
alt={logoMobile.title}
$widthCustom={logoMobile.widthLogo}
width={logoMobile.logo.gatsbyImageData.width}
height={logoMobile.logo.gatsbyImageData.height}
/>
)}
<Logo
src={mobileLogo.file.url}
alt={mobileLogo.title}
$widthCustom={mobileLogo.widthLogo}
width={mobileLogo.gatsbyImageData?.width}
height={mobileLogo.gatsbyImageData?.height}
/>
</LogoWrapper>
) : null}
</Link>
Expand Down
19 changes: 11 additions & 8 deletions src/components/Link.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import PropTypes from 'prop-types'
import React, { useContext } from 'react'
import React, { useContext, useEffect, useState } from 'react'
import { DEFAULT_LOCALE_CODE } from '../lib/config.mjs'
import ContextClientSide from '../Context/ContextClientSide'
import Context from '../Context/ContextPage'
Expand All @@ -18,11 +18,12 @@ const DefaultLink = props => {
const { localization } = useContext(ContextClientSide)
const { localizedPages } = useContext(Context)
const { locale } = localization || {}
if (!to) {
const [href, setHref] = useState(to)

if (!href) {
return <div {...rest}>{children}</div>
}

let href = to
const isAnchorLink = href.startsWith('#')
if (isAnchorLink) {
newTab = false
Expand All @@ -36,12 +37,14 @@ const DefaultLink = props => {
rel: newTab ? 'noopener' : null,
}

if (localizedPages && localizedPages.includes(href)) {
const localeCode = locale?.code
if (localeCode && localeCode !== DEFAULT_LOCALE_CODE) {
href = `/${localeCode}${to}`
useEffect(() => {
if (localizedPages && localizedPages.includes(href)) {
const localeCode = locale?.code
if (localeCode && localeCode !== DEFAULT_LOCALE_CODE) {
setHref(`/${localeCode}${to}`)
}
}
}
}, [to, localizedPages, locale])

return isInternal ? (
<Link
Expand Down
10 changes: 3 additions & 7 deletions src/components/PortfolioPage/Layout/PortfolioFooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,12 @@ const PortfolioFooter = props => {
<ContentInner>
<LeftColumn>
<LeftColumnInner>
{logo?.logo?.svg?.content ? (
<div
dangerouslySetInnerHTML={{ __html: logo.logo.svg.content }}
/>
) : (
{logo ? (
<img
src={previewMode ? logo?.logo?.url : logo?.file?.url}
src={previewMode ? logo.logo?.url : logo.logo?.file?.url}
alt={logo.title}
/>
)}
) : null}
<PortfolioLinkWrapper>
<PortfolioLink to={logo.link} newTab={logo.newTab}>
{logo.title}
Expand Down
15 changes: 3 additions & 12 deletions src/components/PortfolioPage/Layout/PortfolioHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,9 @@ const PortfolioHeader = props => {
<LogoWrapper>
<Link to="/" aria-label="Go to Homepage">
<ButtonShadow as="div" short>
{logo?.svg?.content ? (
<LogoSvgWrapper
dangerouslySetInnerHTML={{
__html: logo.svg.content,
}}
/>
) : (
<Logo
src={previewMode ? logo?.url : logo?.file?.url}
alt={title}
/>
)}
{logo ? (
<Logo src={previewMode ? logo.url : logo.file?.url} alt={title} />
) : null}
</ButtonShadow>
</Link>
</LogoWrapper>
Expand Down
12 changes: 0 additions & 12 deletions src/components/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1241,10 +1241,6 @@ figcaption {
}
}

.logoMetamaskSvg {
width: 100%;
}

body {
transition: background 0.3s ease;

Expand Down Expand Up @@ -1327,14 +1323,6 @@ body.dark-mode {
background-color: #393e46;
}

.logoMetamaskSvg {
svg {
path:nth-child(1) {
fill: #fff;
}
}
}

.logoSvg {
svg {
path {
Expand Down
14 changes: 0 additions & 14 deletions src/fragments/ContentfulContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,13 +719,6 @@ export const ContentfulLogoFields = graphql`
logo {
title
description
svg {
content # SVG content optimized with SVGO
originalContent # Original SVG content
dataURI # Optimized SVG as compact dataURI
absolutePath #
relativePath #
}
file {
url
}
Expand All @@ -734,13 +727,6 @@ export const ContentfulLogoFields = graphql`
logoDarkMode {
title
description
svg {
content # SVG content optimized with SVGO
originalContent # Original SVG content
dataURI # Optimized SVG as compact dataURI
absolutePath #
relativePath #
}
file {
url
}
Expand Down
Loading

0 comments on commit c006419

Please sign in to comment.