Skip to content
This repository was archived by the owner on Jul 19, 2022. It is now read-only.

Next.js migration #79

Draft
wants to merge 32 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e242791
Testing the grounds
Mar 4, 2020
7c6c2bf
Calculate page props
Mar 5, 2020
71ed4cd
Added more data
Mar 6, 2020
4a5677f
Tons of bug fixes
Mar 7, 2020
fe7bbc1
Link fixes
Mar 8, 2020
1887e37
Fixed link for locales
Mar 8, 2020
9c6d6f9
Fixed next/prev links in the navigation
Mar 8, 2020
0e0bb75
Remove the PageLink component
Mar 8, 2020
8c5e660
Updated the PageLabel component
Mar 8, 2020
d615661
Moved the index page to a dynamic page
Mar 8, 2020
129a3de
Added proper language support
Mar 8, 2020
d66486a
Fixed remaning issues with the core layout
Mar 8, 2020
de7dbe9
Bug fixes before adding the main content
Mar 8, 2020
8d6fa07
Added introduction page content
Mar 8, 2020
710b281
Removed unrequired data from the page
Mar 8, 2020
5deda65
Removed unrequired code
Mar 9, 2020
2be4d7c
Removed locale data from the ssg data of the page
Mar 9, 2020
ae598bf
Moved more data out of the page
Mar 9, 2020
da29c4e
Fixed lang hook
Mar 9, 2020
3793289
Calculate basePath instead of using the page
Mar 9, 2020
8ffe7e8
Added tshirt page
Mar 9, 2020
b40a46c
Added invalid rewrites
Mar 9, 2020
862cedd
Added data for the demographics page
Mar 9, 2020
de4fbb3
Moved api libs to the api folder
Mar 9, 2020
1918783
Fixed API imports
Mar 10, 2020
9f3d67b
Updated BlockExport to match the new queries
Mar 10, 2020
1ba80b4
Added queries for the demographics page
Mar 10, 2020
e2883c5
Removed dataPath from being required
Mar 10, 2020
a16cb10
Fixes
Mar 10, 2020
cf2f67a
Added components for the demographics page
Mar 10, 2020
955e2c4
Temporal change to avoid having multiple red logs in devtools
Mar 10, 2020
e9d7b64
Fixed some UX bugs
Mar 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Removed unrequired code
Luis Alvarez committed Mar 9, 2020
commit 5deda65ffb6e05de04c33546ec5746dadcac14b8
10 changes: 3 additions & 7 deletions src/core/Layout.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { PureComponent, useCallback, useEffect, useState } from 'react'
import propTypes from 'prop-types'
import { withRouter } from 'next/router'
import classNames from 'classnames'
import { ThemeProvider, createGlobalStyle } from 'styled-components'
import Pagination from './pages/Pagination'
@@ -132,12 +131,9 @@ class Layout extends PureComponent {
}

render() {
const { showPagination, location, pageContext, router } = this.props
const { showPagination, location, pageContext } = this.props
const { showSidebar } = this.state
const context = mergePageContext(
{ ...pageContext, ...this.state, currentPath: router.asPath },
location
)
const context = mergePageContext({ ...pageContext, ...this.state }, location)

return (
<PageContextProvider value={context}>
@@ -156,7 +152,7 @@ class Layout extends PureComponent {
}
}

export default withRouter(Layout)
export default Layout

const GlobalStyle = createGlobalStyle`
body {
6 changes: 3 additions & 3 deletions src/core/components/Head.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import Helmet from 'react-helmet'
import { usePageContext } from 'core/helpers/pageContext'
import { getPageSocialMeta, getPageMeta } from 'core/helpers/pageHelpers'
import { usePageSocialMeta, usePageMeta } from 'core/helpers/pageHelpers'
import { useI18n } from 'core/i18n/i18nContext'
import { useTools } from 'core/helpers/toolsContext'
import { websiteTitle } from 'core/constants.js'
@@ -17,8 +17,8 @@ const Head = () => {
overrides.title = `${websiteTitle}: ${toolName}`
}

const meta = getPageMeta(context, translate, overrides)
const socialMeta = getPageSocialMeta(context, translate, overrides)
const meta = usePageMeta(translate, overrides)
const socialMeta = usePageSocialMeta(translate, overrides)
const description = translate(`general.description`)

const mergedMeta = [
61 changes: 29 additions & 32 deletions src/core/helpers/pageHelpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { useRouter } from 'next/router'
import { getToolName } from 'core/helpers/tools'
import { websiteTitle } from 'core/constants.js'
import { usePageContext } from './pageContext'

const HOST = 'https://2019.stateofjs.com'
const WEBSITE_TITLE = websiteTitle

export const getTranslationValuesFromContext = (context, translate) => {
@@ -46,41 +49,40 @@ export const getPageLabel = (
* example:
* http://2018.stateofjs.com/images/captures/front-end_overview.png
*/
export const getPageImageUrl = context => {
const baseUrl = `${context.host}/images/`

let imageUrl
if (context.block !== undefined) {
imageUrl = `${baseUrl}captures/${context.block.id}.png`
// imageUrl = `${baseUrl}captures/${context.basePath
// .replace(/^\//, '')
// .replace(/\/$/, '')
// .replace(/\//g, '_')}_${context.block.id}.png`
} else {
imageUrl = `${baseUrl}stateofjs-socialmedia.png`
}

return imageUrl
export const getPageImageUrl = () => {
// const baseUrl = `${context.host}/images/`

// let imageUrl
// if (context.block !== undefined) {
// imageUrl = `${baseUrl}captures/${context.block.id}.png`
// // imageUrl = `${baseUrl}captures/${context.basePath
// // .replace(/^\//, '')
// // .replace(/\/$/, '')
// // .replace(/\//g, '_')}_${context.block.id}.png`
// } else {
// imageUrl = `${baseUrl}stateofjs-socialmedia.png`
// }

return `${HOST}/images/stateofjs-socialmedia.png`
}

export const getPageMeta = (context, translate, overrides = {}) => {
const url = `${context.host}${context.localePath}${context.basePath}`
const imageUrl = getPageImageUrl(context)
const isRoot = context.path === '/' || context.basePath === '/'
export const usePageMeta = (translate, overrides = {}) => {
const context = usePageContext()
const { query, asPath } = useRouter()
const imageUrl = getPageImageUrl()
const currentPath = query.lang ? asPath.replace(new RegExp(`^/${query.lang}`), '/') : asPath
const isRoot = currentPath === '/'

const meta = {
url,
return {
url: HOST + asPath,
title: isRoot ? WEBSITE_TITLE : getPageLabel(context, translate, { includeWebsite: true }),
imageUrl,
...overrides
}

return meta
}

export const getPageSocialMeta = (context, translate, overrides = {}) => {
const meta = getPageMeta(context, translate, overrides)

export const usePageSocialMeta = (translate, overrides = {}) => {
const meta = usePageMeta(translate, overrides)
const socialMeta = [
// facebook
{ property: 'og:type', content: 'article' },
@@ -107,14 +109,9 @@ export const mergePageContext = (pageContext, location) => {
const isDebugEnabled =
location && location.search ? location.search.indexOf('debug') !== -1 : false

let host = 'https://2019.stateofjs.com'
if (location && location.host && location.protocol) {
host = `${location.protocol}//${location.host}`
}

return {
...pageContext,
host,
host: HOST,
isCapturing,
isDebugEnabled
}
7 changes: 2 additions & 5 deletions src/core/pages/PageMeta.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import React from 'react'
import Helmet from 'react-helmet'
import { usePageContext } from '../helpers/pageContext'
import { useI18n } from '../i18n/i18nContext'
import { getPageSocialMeta } from '../helpers/pageHelpers'
import { usePageSocialMeta } from '../helpers/pageHelpers'

const PageMeta = ({ overrides = {} }) => {
const context = usePageContext()
const { translate } = useI18n()

const meta = getPageSocialMeta(context, translate, overrides)
const meta = usePageSocialMeta(translate, overrides)

return <Helmet meta={meta} />
}
9 changes: 4 additions & 5 deletions src/core/pages/PageMetaDebug.js
Original file line number Diff line number Diff line change
@@ -2,23 +2,20 @@ import React from 'react'
import { usePageContext } from '../helpers/pageContext'
import { useI18n } from '../i18n/i18nContext'
import Debug from '../components/Debug'
import { getPageSocialMeta } from '../helpers/pageHelpers'
import { usePageSocialMeta } from '../helpers/pageHelpers'
import { useTools } from 'core/helpers/toolsContext'
import { websiteTitle } from 'core/constants.js'

const PageMetaDebug = ({ overrides = {} }) => {
const context = usePageContext()
const { translate } = useI18n()
const { getToolName } = useTools()

if (!context.isDebugEnabled) return null

const toolName = getToolName(context)
if (toolName) {
overrides.title = `${websiteTitle}: ${toolName}`
}

const meta = getPageSocialMeta(context, translate, overrides)
const meta = usePageSocialMeta(translate, overrides)
const metaObject = meta.reduce((acc, meta) => {
const key = meta.property || meta.name

@@ -28,6 +25,8 @@ const PageMetaDebug = ({ overrides = {} }) => {
}
}, {})

if (!context.isDebugEnabled) return null

return <Debug title="Page meta" data={metaObject} />
}