Skip to content

Commit 4bea26b

Browse files
committed
Clean up the font setup to make sure .font-sans works consistently
1 parent 3bd68ba commit 4bea26b

File tree

7 files changed

+46
-17
lines changed

7 files changed

+46
-17
lines changed

src/app/conf/2023/layout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Header } from "../_components/header"
44
import { Footer } from "../_components/footer"
55
import { GraphQLConf, HostedByGraphQLFoundation } from "@/icons"
66
import NextLink from "next/link"
7+
import { OldFontsStyleTag } from "../../fonts/old-fonts"
78

89
export const metadata = {
910
description:
@@ -33,6 +34,7 @@ export default function ConfLayout({
3334
const hover = "#c026d3"
3435
return (
3536
<>
37+
<OldFontsStyleTag />
3638
<style>{`
3739
.text-primary,
3840
.hover\\:text-primary:hover {

src/app/conf/2024/layout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Header } from "../_components/header"
44
import { Footer } from "../_components/footer"
55
import { GraphQLConf, HostedByGraphQLFoundation } from "@/icons"
66
import NextLink from "next/link"
7+
import { OldFontsStyleTag } from "../../fonts/old-fonts"
78

89
export const metadata = {
910
description:
@@ -30,6 +31,7 @@ export default function Layout({
3031
}): ReactElement {
3132
return (
3233
<>
34+
<OldFontsStyleTag />
3335
<Header
3436
logo={
3537
<NextLink

src/app/conf/2025/layout.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Header } from "../_components/header"
44
import { Footer } from "../_components/footer"
55
import { GraphQLConf, HostedByGraphQLFoundation } from "@/icons"
66
import NextLink from "next/link"
7-
import { hostGrotesk } from "../../fonts"
7+
import { NewFontsStyleTag } from "../../fonts"
88

99
export const metadata = {
1010
description:
@@ -31,15 +31,7 @@ export default function Layout({
3131
}): ReactElement {
3232
return (
3333
<>
34-
<style
35-
dangerouslySetInnerHTML={{
36-
__html: /* css */ `
37-
html.fonts {
38-
--font-sans: ${hostGrotesk.style.fontFamily};
39-
font-family: var(--font-sans);
40-
}`,
41-
}}
42-
/>
34+
<NewFontsStyleTag />
4335
<Header
4436
logo={
4537
<NextLink

src/app/fonts/index.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import localFont from "next/font/local"
2+
3+
export const hostGrotesk = localFont({
4+
src: [
5+
{ path: "./HostGrotesk-VariableFont_wght.woff2" },
6+
{ path: "./HostGrotesk-Italic-VariableFont_wght.woff2", style: "italic" },
7+
],
8+
weight: "300 800",
9+
})
10+
11+
const newFontsStyles = /* css */ `
12+
html {
13+
--font-sans: ${hostGrotesk.style.fontFamily};
14+
}`
15+
16+
export const NewFontsStyleTag = () => {
17+
return <style dangerouslySetInnerHTML={{ __html: newFontsStyles }} />
18+
}

src/app/fonts/old-fonts.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Roboto_Flex } from "next/font/google"
2+
3+
export const robotoFlex = Roboto_Flex({
4+
subsets: ["latin"],
5+
})
6+
7+
const oldFontsStyles = /* css */ `
8+
html {
9+
--font-sans: ${robotoFlex.style.fontFamily};
10+
}`
11+
12+
export const OldFontsStyleTag = () => {
13+
return <style dangerouslySetInnerHTML={{ __html: oldFontsStyles }} />
14+
}

src/app/layout.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import { ReactElement, ReactNode } from "react"
22
import { Metadata } from "next"
3-
import { Roboto_Flex } from "next/font/google"
43
import GoogleAnalytics from "@/app/ga"
54
import "../globals.css"
65

7-
const font = Roboto_Flex({
8-
subsets: ["latin"],
9-
})
10-
116
export const metadata: Metadata = {
127
twitter: {
138
site: "@graphql",
@@ -28,8 +23,7 @@ export default function RootLayout({
2823
children: ReactNode
2924
}): ReactElement {
3025
return (
31-
// eslint-disable-next-line tailwindcss/no-custom-classname
32-
<html lang="en" className={`fonts scroll-smooth ${font.className}`}>
26+
<html lang="en" className="scroll-smooth">
3327
<head>
3428
<style>{`html { scroll-padding-top: 5rem }`}</style>
3529
</head>

tailwind.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Config } from "tailwindcss"
22
import typography from "@tailwindcss/typography"
3+
import { fontFamily } from "tailwindcss/defaultTheme"
34

45
const config: Config = {
56
content: ["./src/**/*.{js,ts,jsx,tsx,mdx}", "./theme.config.tsx"],
@@ -9,6 +10,12 @@ const config: Config = {
910
padding: "1rem",
1011
},
1112
extend: {
13+
fontFamily: {
14+
sans: [
15+
`var(--font-sans, ${fontFamily.sans.slice(0, 3).join(", ")})`,
16+
...fontFamily.sans,
17+
],
18+
},
1219
colors: {
1320
primary: "#e10098",
1421
"conf-black": "#0e031c",

0 commit comments

Comments
 (0)