Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert gatsby-theme-ui-blog to TypeScript #711

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions packages/gatsby-theme-ui-blog/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = options => ({
resolve: 'gatsby-theme-blog-core',
options,
},
'gatsby-plugin-typescript',
'gatsby-theme-ui-layout',
'gatsby-plugin-theme-ui',
],
Expand Down
7 changes: 5 additions & 2 deletions packages/gatsby-theme-ui-blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@
"react-dom": "^16.8.0"
},
"devDependencies": {
"@types/react-helmet": "^5.0.15",
"gatsby": "^2.13.73",
"gatsby-plugin-typescript": "^2.1.27",
"react": "^16.9.0",
"react-dom": "^16.9.0"
},
"dependencies": {
"@emotion/core": "^10.0.0",
"@mdx-js/react": "^1.0.0",
"@theme-ui/core": "^0.3.1",
"@theme-ui/mdx": "^0.3.0",
"@theme-ui/preset-base": "^0.3.0",
"gatsby-plugin-react-helmet": "^3.1.3",
"gatsby-plugin-theme-ui": "^0.3.0",
"gatsby-theme-blog-core": "^1.0.2",
"gatsby-theme-ui-layout": "^0.3.0",
"react-helmet": "^5.2.1",
"theme-ui": "^0.3.1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should still have theme-ui in dependencies.

It's imported in

.

And then we don't need core and mdx.

Dependencies could look like this

  "dependencies": {
    "@emotion/core": "^10.0.0",
    "@mdx-js/react": "^1.0.0",
    "@theme-ui/preset-base": "^0.4.0-alpha.0",
    "gatsby-plugin-react-helmet": "^3.1.3",
    "gatsby-plugin-theme-ui": "^0.4.0-alpha.1",
    "gatsby-theme-blog-core": "^1.0.2",
    "gatsby-theme-ui-layout": "^0.4.0-alpha.0",
    "react-helmet": "^5.2.1",
    "theme-ui": "^0.4.0-alpha.1"
  },

"react-helmet": "^5.2.1"
},
"repository": "system-ui/theme-ui",
"license": "MIT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,24 @@ import { jsx } from 'theme-ui'
import { MDXRenderer } from 'gatsby-plugin-mdx'
import Post from '../../post'

export default props => {
interface BlogPost {
id: string
excerpt: string
body: string
slug: string
title: string
date: string
tags: string[]
keywords: string[]
}

interface Props {
data: {
blogPost: BlogPost
}
}

export default (props: Props) => {
const { body } = props.data.blogPost
const children = jsx(MDXRenderer, { children: body })

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { jsx } from 'theme-ui'
import Posts from '../../posts'

export interface PostNode {
id: string
excerpt: string
slug: string
title: string
date: string
tags: string[]
}

interface AllBlogPost {
edges: {
node: PostNode
}[]
}

interface Props {
data: {
allBlogPost: AllBlogPost
}
}

export default (props: Props) => {
const posts = props.data.allBlogPost.edges.map(e => e.node)

return jsx(Posts, {
...props,
posts,
})
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import React from 'react'
import { Helmet } from 'react-helmet'

export default ({ lang = 'en-us', title, excerpt, ...props }) => (
export interface HeadProps {
lang?: string
title?: string
excerpt?: string
}

const Head: React.FC<HeadProps> = ({
lang = 'en-us',
title,
excerpt,
...props
}) => (
<Helmet
{...props}
htmlAttributes={{
Expand All @@ -11,3 +22,5 @@ export default ({ lang = 'en-us', title, excerpt, ...props }) => (
{excerpt && <meta name="description" content={excerpt} />}
</Helmet>
)

export default Head
10 changes: 0 additions & 10 deletions packages/gatsby-theme-ui-blog/src/layout.js

This file was deleted.

11 changes: 11 additions & 0 deletions packages/gatsby-theme-ui-blog/src/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react'
import Head, { HeadProps } from './head'

const Layout: React.FC<HeadProps> = props => (
<>
<Head {...props} />
{props.children}
</>
)

export default Layout
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
/** @jsx jsx */
import { jsx, Styled } from 'theme-ui'
import { jsx } from '@theme-ui/core'
import { Styled } from '@theme-ui/mdx'
import { Layout } from 'gatsby-theme-ui-layout'

export default ({
interface PostProps {
title?: string
date?: string
excerpt?: string
keywords?: string[]
tags?: string[]
}

const Post: React.FC<PostProps> = ({
title,
date,
excerpt,
Expand All @@ -19,3 +28,5 @@ export default ({
</Layout>
</Styled.root>
)

export default Post
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/** @jsx jsx */
import { jsx, Styled } from 'theme-ui'
import { jsx } from '@theme-ui/core'
import { Styled } from '@theme-ui/mdx'
import { Link } from 'gatsby'
import { Layout } from 'gatsby-theme-ui-layout'
import { PostNode } from './gatsby-theme-blog-core/components/posts'

export default ({ posts, ...props }) => (
interface PostsProps {
posts: PostNode[]
}

const Posts: React.FC<PostsProps> = ({ posts, ...props }) => (
<Styled.root>
<Layout {...props}>
<ul>
Expand All @@ -16,3 +22,5 @@ export default ({ posts, ...props }) => (
</Layout>
</Styled.root>
)

export default Posts
3 changes: 3 additions & 0 deletions packages/gatsby-theme-ui-blog/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../core/tsconfig"
}
Comment on lines +1 to +3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lands in user's node_modules. I think we can't reference core's tsconfig there.

Suggested change
{
"extends": "../core/tsconfig"
}
{
"compilerOptions": {
"resolveJsonModule": true,
"esModuleInterop": true,
"moduleResolution": "node",
"strict": true,
"jsx": "preserve"
}
}

Loading