Skip to content

Commit 8c69a78

Browse files
committed
Use built in gatsby head in favor of react-helmet
1 parent e3d127c commit 8c69a78

File tree

10 files changed

+49
-92
lines changed

10 files changed

+49
-92
lines changed

content/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: npm Documentation
2+
title: npm Docs
33
edit_on_github: false
44
---
55

gatsby-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ module.exports = {
5858
description: 'Documentation for the npm registry, website, and command-line interface',
5959
lang: 'en',
6060
imageUrl: 'https://user-images.githubusercontent.com/29712634/81721690-e2fb5d80-9445-11ea-8602-4b2294c964f3.png',
61+
repositoryUrl: 'https://github.com/npm/documentation',
6162
},
6263
flags: {
6364
DEV_SSR: !!process.env.DEV_SSR,
6465
},
6566
plugins: [
6667
'gatsby-plugin-styled-components',
67-
'gatsby-plugin-react-helmet',
6868
'gatsby-transformer-yaml',
6969
{
7070
resolve: 'gatsby-plugin-mdx',

gatsby-node.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
const {resolve, join, relative} = require('path')
1+
const {join, relative} = require('path')
22
const {Octokit: CoreOctokit} = require('@octokit/rest')
33
const {throttling} = require('@octokit/plugin-throttling')
44
const {retry} = require('@octokit/plugin-retry')
55

66
const CI = !!process.env.CI
7+
const CWD = process.cwd()
8+
const SRC = join(CWD, 'src')
79
const REPO_URL = 'https://github.com/npm/documentation'
810
const NWO = new URL(REPO_URL).pathname.slice(1)
911
const REPO_BRANCH = 'main'
10-
const CWD = process.cwd()
1112
const TEST_CONTRIBUTORS = [
1213
{
1314
author: {login: 'mona'},
@@ -66,7 +67,7 @@ exports.onCreateWebpackConfig = ({actions}) => {
6667
actions.setWebpackConfig({
6768
resolve: {
6869
alias: {
69-
'~': resolve(__dirname, 'src/'),
70+
'~': SRC,
7071
},
7172
extensions: ['.js'],
7273
},
@@ -172,7 +173,6 @@ const createPage = async (
172173
const context = {
173174
mdxId: id,
174175
tableOfContents: getTableOfConents(tableOfContents),
175-
repositoryUrl: REPO_URL,
176176
}
177177
// edit_on_github: false in frontmatter will not include editUrl and contributors
178178
// on the page. this is used for policy pages as well as some index pages that don't
@@ -184,7 +184,7 @@ const createPage = async (
184184

185185
actions.createPage({
186186
path: pageSlug,
187-
component: contentFilePath,
187+
component: `${join(SRC, 'head.js')}?__contentFilePath=${contentFilePath}`,
188188
context,
189189
})
190190

package-lock.json

Lines changed: 0 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
"gatsby-plugin-manifest": "^5.12.1",
4545
"gatsby-plugin-mdx": "^5.12.1",
4646
"gatsby-plugin-meta-redirect": "^1.1.1",
47-
"gatsby-plugin-react-helmet": "^6.12.0",
4847
"gatsby-plugin-styled-components": "^6.12.0",
4948
"gatsby-source-filesystem": "^5.12.0",
5049
"gatsby-transformer-yaml": "^5.12.0",
@@ -56,7 +55,6 @@
5655
"react-addons-text-content": "^0.0.4",
5756
"react-dom": "^18.2.0",
5857
"react-focus-on": "^3.9.1",
59-
"react-helmet": "^6.1.0",
6058
"styled-components": "^5.3.11",
6159
"styled-system": "^5.1.5"
6260
},

src/components/nav-items.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as getNav from '../util/get-nav'
77
import VisuallyHidden from './visually-hidden'
88
import headerNavItems from '../../content/header-nav.yml'
99
import usePage from '../hooks/use-page'
10+
import useSiteMetadata from '../hooks/use-site-metadata'
1011

1112
const NavItem = ({item, path, depth}) => {
1213
const href = getNav.getLocation(item.url)
@@ -53,10 +54,8 @@ const ExternalNavItem = ({title, ...props}) => (
5354
)
5455

5556
const Navigation = () => {
56-
const {
57-
location,
58-
pageContext: {repositoryUrl},
59-
} = usePage()
57+
const {location} = usePage()
58+
const {repositoryUrl} = useSiteMetadata()
6059
const path = getNav.getLocation(location.pathname)
6160
const items = getNav.getHierarchy(null, {path, hideVariants: true})
6261

src/head.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react'
2+
import useSiteMetdata from './hooks/use-site-metadata'
3+
4+
const buildTitle = (...parts) => [...new Set(parts.filter(Boolean))].join(' | ')
5+
6+
export const Head = ({pageContext: {frontmatter = {}}}) => {
7+
const siteMetadata = useSiteMetdata()
8+
9+
const title = buildTitle(frontmatter.title, siteMetadata.title)
10+
const description = frontmatter.description || siteMetadata.description
11+
12+
return (
13+
<>
14+
<title>{title}</title>
15+
<meta name="description" content={description} />
16+
<meta property="og:title" content={title} />
17+
<meta property="og:description" content={description} />
18+
<meta property="og:image" content={siteMetadata.imageUrl} />
19+
<meta property="twitter:card" content="summary_large_image" />
20+
<html lang={siteMetadata.lang} />
21+
</>
22+
)
23+
}
24+
25+
const PassThrough = ({children}) => children
26+
27+
export default PassThrough

src/hooks/use-site-metadata.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function useSiteMetadata() {
1010
description
1111
lang
1212
imageUrl
13+
repositoryUrl
1314
}
1415
}
1516
}

src/layout.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {SKIP_NAV} from './constants'
1010
import useSiteMetadata from './hooks/use-site-metadata'
1111
import usePage from './hooks/use-page'
1212

13-
export const HeroLayout = ({children}) => {
13+
const HeroLayout = ({children}) => {
1414
const {title, description} = useSiteMetadata()
1515

1616
return (
@@ -32,7 +32,7 @@ export const HeroLayout = ({children}) => {
3232
)
3333
}
3434

35-
export const DefaultLayout = ({children}) => {
35+
const DefaultLayout = ({children}) => {
3636
const {title, description} = usePage().frontmatter
3737
return (
3838
<Box
@@ -62,6 +62,6 @@ export const DefaultLayout = ({children}) => {
6262
)
6363
}
6464

65-
const getLayout = ({path}) => ({'/': HeroLayout})[path] ?? DefaultLayout
65+
const Layout = ({children}) => React.createElement(usePage().path === '/' ? HeroLayout : DefaultLayout, null, children)
6666

67-
export default getLayout
67+
export default Layout

src/page.js

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,12 @@ import React from 'react'
22
import {BaseStyles, themeGet, Box} from '@primer/react'
33
import styled, {createGlobalStyle} from 'styled-components'
44
import {SKIP_NAV} from './constants'
5-
import {Helmet} from 'react-helmet'
65
import Slugger from 'github-slugger'
76
import Header from './components/header'
87
import Sidebar from './components/sidebar'
98
import Link from './components/link'
10-
import useSiteMetdata from './hooks/use-site-metadata'
11-
import usePage, {PageProvider} from './hooks/use-page'
12-
import getLayout from './layout'
13-
14-
const Head = () => {
15-
const {frontmatter} = usePage()
16-
const siteMetadata = useSiteMetdata()
17-
18-
const title = [frontmatter.title, siteMetadata.title].filter(Boolean).join(' | ')
19-
const description = frontmatter.description || siteMetadata.description
20-
21-
return (
22-
<Helmet>
23-
<title>{title}</title>
24-
<meta name="description" content={description} />
25-
<meta property="og:title" content={title} />
26-
<meta property="og:description" content={description} />
27-
<meta property="og:image" content={siteMetadata.imageUrl} />
28-
<meta property="twitter:card" content="summary_large_image" />
29-
<html lang={siteMetadata.lang} />
30-
</Helmet>
31-
)
32-
}
9+
import {PageProvider} from './hooks/use-page'
10+
import Layout from './layout'
3311

3412
const SkipLinkBase = props => (
3513
<Link
@@ -46,6 +24,10 @@ const SkipLinkBase = props => (
4624
</Link>
4725
)
4826

27+
// The following rules are to ensure that the element
28+
// is visually hidden, unless it has focus. This is the recommended
29+
// way to hide content from:
30+
// https://webaim.org/techniques/css/invisiblecontent/#techniques
4931
export const SkipLink = styled(SkipLinkBase)`
5032
z-index: 20;
5133
width: auto;
@@ -54,11 +36,6 @@ export const SkipLink = styled(SkipLinkBase)`
5436
position: absolute;
5537
overflow: hidden;
5638
57-
// The following rules are to ensure that the element
58-
// is visually hidden, unless it has focus. This is the recommended
59-
// way to hide content from:
60-
// https://webaim.org/techniques/css/invisiblecontent/#techniques
61-
6239
&:not(:focus) {
6340
clip: rect(1px, 1px, 1px, 1px);
6441
clip-path: inset(50%);
@@ -90,13 +67,12 @@ const PageElement = ({element, props}) => {
9067
<SkipLink />
9168
<PageProvider value={page}>
9269
<Box sx={{display: 'flex', flexDirection: 'column', minHeight: '100vh'}}>
93-
<Head />
9470
<Header />
9571
<Box sx={{zIndex: 0, display: 'flex', flex: '1 1 auto', flexDirection: 'row'}} role="main">
9672
<Box sx={{display: ['none', null, null, 'block']}}>
9773
<Sidebar />
9874
</Box>
99-
{React.createElement(getLayout(page), {key: 'layout', ...props}, element)}
75+
<Layout>{element}</Layout>
10076
</Box>
10177
</Box>
10278
</PageProvider>

0 commit comments

Comments
 (0)