Skip to content

Commit

Permalink
Merge pull request #462 from jsconfjp/refactor/fixes
Browse files Browse the repository at this point in the history
Refactor/fixes
  • Loading branch information
yosuke-furukawa authored Oct 19, 2024
2 parents 4553f8c + 33d6fe0 commit bfa5d1a
Show file tree
Hide file tree
Showing 16 changed files with 166 additions and 148 deletions.
1 change: 0 additions & 1 deletion 2024/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.exports = {
},
plugins: [
`gatsby-plugin-typescript`,
`gatsby-plugin-react-helmet`,
`gatsby-plugin-styled-components`,
`gatsby-plugin-zopfli`,
`gatsby-plugin-brotli`,
Expand Down
25 changes: 5 additions & 20 deletions 2024/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion 2024/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"gatsby": "^5.13.4",
"gatsby-plugin-image": "^3.13.1",
"gatsby-plugin-manifest": "^5.13.1",
"gatsby-plugin-react-helmet": "^6.13.1",
"gatsby-plugin-sharp": "^5.13.1",
"gatsby-source-filesystem": "^5.13.1",
"gatsby-transformer-sharp": "^5.13.1",
Expand Down
15 changes: 12 additions & 3 deletions 2024/src/components/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React, { useCallback } from "react"
import styled, { ThemeProvider } from "styled-components"
import styled, {
StyleSheetManager,
ThemeProvider,
WebTarget,
} from "styled-components"
import { useStaticQuery, graphql } from "gatsby"
import { useTranslation } from "react-i18next"

Expand Down Expand Up @@ -69,6 +73,11 @@ const BackToTopButton = styled.button`
background-color: ${({ theme }) => theme.colors.primary};
`

function shouldForwardProp(_propName: string, _target: WebTarget) {
// See: https://styled-components.com/docs/faqs#what-do-i-need-to-do-to-migrate-to-v6
return true
}

export function Layout({ children, background }: Props) {
const { t, i18n } = useTranslation()
const onChangeLanguage = useCallback(
Expand Down Expand Up @@ -97,7 +106,7 @@ export function Layout({ children, background }: Props) {

return (
<ThemeProvider theme={theme}>
<>
<StyleSheetManager shouldForwardProp={shouldForwardProp}>
<GlobalStyle />
<OnlyMobile>
<HeaderMobile
Expand Down Expand Up @@ -130,7 +139,7 @@ export function Layout({ children, background }: Props) {
</BackToTopBox>
</MainBox>
<Footer />
</>
</StyleSheetManager>
</ThemeProvider>
)
}
11 changes: 3 additions & 8 deletions 2024/src/components/LinkButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ const ExternalSecondaryBox = styled(ExternalBox)`

export type Props = {
color?: "primary" | "secondary"
size: "inline" | "normal" | "large"
size?: "inline" | "normal" | "large"
to: string
disabled: boolean
onClick?: MouseEventHandler
children: React.ReactNode
}

export function LinkButton(props: Props) {
const { color, to, size, onClick, children } = props
const { color, to, onClick, children } = props
const size = props.size ?? "normal"

if (!to?.startsWith("http")) {
if (color === "primary") {
Expand Down Expand Up @@ -131,8 +131,3 @@ export function LinkButton(props: Props) {
)
}
}

LinkButton.defaultProps = {
disabled: false,
size: "normal",
}
10 changes: 3 additions & 7 deletions 2024/src/components/Logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ import React from "react"
import logo from "../images/logo.svg"

type Props = {
size: number
size?: number
}

export function Logo(props: Props) {
const { size } = props
export const Logo = (props: Props) => {
const size = props.size ?? 125

return <img width={size} height={size} src={logo} alt="JSConf JP" />
}

Logo.defaultProps = {
size: 125,
}
10 changes: 3 additions & 7 deletions 2024/src/components/Logo2023.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ import React from "react"
import logo2023 from "../images/logo-2023.png"

type Props = {
size: number
size?: number
}

export function Logo2023(props: Props) {
const { size } = props
export const Logo2023 = (props: Props) => {
const size = props.size ?? 125

return <img width={size} height={size} src={logo2023} alt="JSConf JP 2023" />
}

Logo2023.defaultProps = {
size: 125,
}
20 changes: 20 additions & 0 deletions 2024/src/components/OptionalLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React, { forwardRef } from "react"
import { Link, GatsbyLinkProps } from "gatsby"

export type OptionalLinkProps<TState> = Omit<
GatsbyLinkProps<TState>,
"to" | "align"
> & {
to?: string | null
}
export const OptionalLink = forwardRef<
HTMLAnchorElement,
OptionalLinkProps<any>
>((props, ref) => {
const { to, ...rest } = props
return to ? (
<Link ref={ref as any} to={to} {...rest} />
) : (
<a ref={ref as any} {...rest} />
)
})
98 changes: 34 additions & 64 deletions 2024/src/components/Seo.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import React from "react"
import Helmet from "react-helmet"
import { useStaticQuery, graphql } from "gatsby"
import { useTranslation } from "react-i18next"

type MetaProps = JSX.IntrinsicElements["meta"]

type Props = {
description?: string | null
lang: Languages
meta: MetaProps[]
lang?: Languages
meta?: MetaProps[]
title?: string | null
ogImage?: string
}

export function SEO({ description, ogImage, lang, meta, title }: Props) {
export function SEO({ description, ogImage, meta, title }: Props) {
meta ??= []
description ??= ""

const { site, logo } = useStaticQuery(graphql`
query {
site {
Expand All @@ -28,69 +31,36 @@ export function SEO({ description, ogImage, lang, meta, title }: Props) {
}
}
`)
const {
i18n: { language },
} = useTranslation()
const lang = language ?? "en"
const defaultOgImage = `${site.siteMetadata.siteUrl}${logo.publicURL}`
const metaTitle = title || site.siteMetadata.title
const metaDescription = description || site.siteMetadata.description
return (
<Helmet
htmlAttributes={{
lang,
}}
defaultTitle={site.siteMetadata.title}
title={title ?? undefined}
titleTemplate={`%s | ${site.siteMetadata.title}`}
meta={(
[
{
name: `viewport`,
content: `width=device-width`,
},
{
name: `description`,
content: metaDescription,
},
{
property: `og:title`,
content: metaTitle,
},
{
property: `og:description`,
content: metaDescription,
},
{
property: `og:image`,
content: ogImage
? `${site.siteMetadata.siteUrl}${ogImage}`
: defaultOgImage,
},
{
property: `og:type`,
content: `website`,
},
{
name: `twitter:card`,
content: `summary`,
},
{
name: `twitter:creator`,
content: site.siteMetadata.author,
},
{
name: `twitter:title`,
content: title,
},
{
name: `twitter:description`,
content: metaDescription,
},
] as MetaProps[]
).concat(meta)}
/>
<>
<html lang={lang} />
<title>
{title
? `${title} | ${site.siteMetadata.title}`
: site.siteMetadata.title}
</title>
<meta name="description" content={metaDescription} />
<meta name="og:description" content={metaDescription} />
<meta name="og:title" content={metaTitle} />
<meta name="og:type" content="website" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:creator" content={site.siteMetadata.author} />
<meta name="twitter:title" content={title ?? site.siteMetadata.title} />
<meta name="twitter:description" content={metaDescription} />
<meta name="viewport" content="width=device-width" />
<meta
name="og:image"
content={
ogImage ? `${site.siteMetadata.siteUrl}${ogImage}` : defaultOgImage
}
/>
</>
)
}

SEO.defaultProps = {
lang: `en`,
meta: [],
description: ``,
}
7 changes: 4 additions & 3 deletions 2024/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const SponsorBox = styled.div`
}
`

export const Head = () => <SEO />

export default function IndexPage() {
const { t, i18n } = useTranslation()
const {
Expand Down Expand Up @@ -261,7 +263,7 @@ export default function IndexPage() {
subTitle: t("callForSponsors"),
available: site.siteMetadata.sponsorFormUrl,
render: () =>
site.siteMetadata.sponsorFormUrl ? (
false ? (
<LinkButton
color="primary"
size="large"
Expand All @@ -270,7 +272,7 @@ export default function IndexPage() {
{t("becomeASponsor")}
</LinkButton>
) : (
<LinkButton size="large" disabled to={""}>
<LinkButton size="large" to={""}>
{t("comingSoon")}
</LinkButton>
),
Expand All @@ -295,7 +297,6 @@ export default function IndexPage() {
return (
<Layout>
<WavyBox>
<SEO lang={i18n.language as Languages} />
<Container>
<Centerize>
<Hero
Expand Down
Loading

0 comments on commit bfa5d1a

Please sign in to comment.