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

Add typescript with gatsbt recipe #14

Merged
merged 4 commits into from
Sep 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

> Podast and articles about womens artists

## Tooling

- Pages generated with [Gatsby](https://www.gatsbyjs.com/).
- [Prismic](https://prismic.io/) for the content.
- Hosted on Netlify, you [can check the website](https://artaufeminin.fr).

## Getting started

```
Expand Down
12 changes: 7 additions & 5 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ module.exports = {
options: {
postCssPlugins: [
require("postcss-easy-import")(),
require("postcss-custom-properties")({ preserve: false }),
require("postcss-custom-properties")({
preserve: false,
}),
require("postcss-color-function")(),
],
},
Expand Down Expand Up @@ -97,10 +99,9 @@ module.exports = {
defaultLang: "fr-fr", // optional, but recommended
pages: [
{
// optional
type: "Blog_post", // TypeName from prismic
match: "/article/:uid", // pages will be generated under this pattern
component: require.resolve("./src/templates/article.js"),
type: "Blog_post", // optional
match: "/article/:uid", // TypeName from prismic
component: require.resolve("./src/templates/article.tsx"), // pages will be generated under this pattern
},
],
sharpKeys: [
Expand All @@ -109,5 +110,6 @@ module.exports = {
],
},
},
"gatsby-plugin-typescript",
],
}
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"url": "https://github.com/ImedAdel/gatsby-london/issues"
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "^4.0.1",
"date-fns": "^2.16.1",
"gatsby": "^2.21.21",
"gatsby-image": "^2.0.41",
"gatsby-plugin-manifest": "^2.1.1",
Expand All @@ -18,6 +21,7 @@
"gatsby-plugin-react-helmet": "^3.0.12",
"gatsby-plugin-sharp": "^2.0.36",
"gatsby-plugin-sitemap": "^2.4.2",
"gatsby-plugin-typescript": "^2.4.18",
"gatsby-remark-copy-linked-files": "^2.0.12",
"gatsby-remark-images": "^2.0.6",
"gatsby-remark-prismjs": "^3.2.9",
Expand All @@ -34,6 +38,7 @@
"react-dom": "^16.8.6",
"react-helmet": "^5.2.1",
"typeface-merriweather": "0.0.72",
"typescript": "^4.0.2",
"url-join": "^4.0.0"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function articleCard(props) {
>
<Link to={`article/${slug}`} className="post-card-link">
<div className="post-card-content">
<h2 className="post-card-title">{RichText.render(title)}</h2>
<h2 className="post-card-title">{RichText.asText(title)}</h2>
</div>
</Link>
</article>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function Author() {
fixed={data.avatar.childImageSharp.fixed}
alt={author}
imgStyle={{
borderRadius: `50%`,
borderRadius: `100%`,
}}
/>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/footer.js → src/components/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ export default function footer(props) {
paddingRight: 0,
}}
>
{platforms.map(platform => {
{platforms.map((platform, index) => {
return (
<li>
<li key={index}>
<a href={platform.url}>{platform.name}</a>
</li>
)
Expand Down
11 changes: 8 additions & 3 deletions src/components/layout.js → src/components/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import React from "react"
import React, { ReactNode } from "react"
import { Link } from "gatsby"
import Footer from "./footer"

import "../utils/normalize.css"
import "../utils/css/screen.css"
import "../utils/css/styles.css"

const Layout = props => {
interface LayoutProps {
title: string
children: ReactNode
}

function Layout(props: LayoutProps) {
const { title, children } = props
const [toggleNav, setToggleNav] = React.useState(false)

Expand Down
File renamed without changes.
32 changes: 0 additions & 32 deletions src/pages/404.js

This file was deleted.

29 changes: 29 additions & 0 deletions src/pages/404.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, { ReactElement } from "react"
import { graphql } from "gatsby"

import Layout from "../components/layout"
import SEO from "../components/seo"

interface Props {}

export default function NotFoundPage({ data }: Props): ReactElement {
const siteTitle = data.site.siteMetadata.title

return (
<Layout title={siteTitle}>
<SEO title="404: Not Found" />
<h1>Ohoh. Il n'y a rien à voir ici.</h1>
<p>La page que vous demandez n'existe pas.</p>
</Layout>
)
}

export const pageQuery = graphql`
query {
site {
siteMetadata {
title
}
}
}
`
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
25 changes: 16 additions & 9 deletions src/templates/article.js → src/templates/article.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
import React from "react"
import { graphql } from "gatsby"
import { RichText } from "prismic-reactjs"
import { formatDistanceToNow } from "date-fns"
import { fr } from "date-fns/locale"

import Layout from "../components/layout"
import SEO from "../components/seo"
import Author from "../components/blog/author"

export default function Article(props) {
const siteTitle = props.data.site.siteMetadata.title
const doc = props.data.prismic.allBlog_posts.edges.slice(0, 1).pop()

if (!doc) return null

const siteTitle = props.data.site.siteMetadata.title
const title = RichText.asText(doc.node.title)
const description = RichText.asText(doc.node.description)

const datePublished = formatDistanceToNow(new Date(doc.node.date), {
addSuffix: true,
locale: fr,
})

return (
<Layout title={siteTitle}>
<SEO title="Article" />
<SEO title={title} description={description} />

<article className={`post-content`}>
<header className="post-content-header">
<h1 className="post-content-title">
{RichText.asText(doc.node.title)}
</h1>
<h1 className="post-content-title">{title}</h1>
</header>

<p class="post-content-excerpt">
<div className="post-content-excerpt">
{RichText.render(doc.node.description)}
</p>
</div>

{doc.node.image && (
<div className="post-content-image">
Expand All @@ -39,7 +46,7 @@ export default function Article(props) {

<div className="post-content-body">
{RichText.render(doc.node.content)}
<p>{doc.node.date}</p>
<p>Article publié {datePublished}</p>
</div>

<footer className="post-content-footer">
Expand Down
2 changes: 1 addition & 1 deletion src/utils/css/components/buttons.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ button,
cursor: pointer;
font-family: var(--font-sans-serif);
font-size: 1.4rem;
font-weight: var(--font-normal);
font-weight: var(--font-bold);
line-height: var(--height);
text-align: center;
text-decoration: none;
Expand Down