refactor(starter): upgrade to new version of gatsby

This commit is contained in:
Alexander Shelepenok
2022-01-09 20:12:31 +00:00
parent 84bdc5899d
commit 67ebabbaac
397 changed files with 26665 additions and 34984 deletions

View File

@@ -1,27 +0,0 @@
// @flow strict
import React from 'react';
import { getContactHref } from '../../../utils';
import styles from './Author.module.scss';
import { useSiteMetadata } from '../../../hooks';
const Author = () => {
const { author } = useSiteMetadata();
return (
<div className={styles['author']}>
<p className={styles['author__bio']}>
{author.bio}
<a
className={styles['author__bio-twitter']}
href={getContactHref('twitter', author.contacts.twitter)}
rel="noopener noreferrer"
target="_blank"
>
<strong>{author.name}</strong> on Twitter
</a>
</p>
</div>
);
};
export default Author;

View File

@@ -1,5 +1,5 @@
@import '../../../assets/scss/variables';
@import '../../../assets/scss/mixins';
@import "../../../assets/scss/variables";
@import "../../../assets/scss/mixins";
.author {
border-top: 1px solid $color-gray-border;
@@ -22,5 +22,4 @@
margin-left: auto;
margin-right: auto;
}
}
}

View File

@@ -1,23 +0,0 @@
// @flow strict
import React from 'react';
import renderer from 'react-test-renderer';
import { useStaticQuery, StaticQuery } from 'gatsby';
import Author from './Author';
import siteMetadata from '../../../../jest/__fixtures__/site-metadata';
import type { RenderCallback } from '../../../types';
describe('Author', () => {
beforeEach(() => {
StaticQuery.mockImplementationOnce(
({ render }: RenderCallback) => (
render(siteMetadata)
),
useStaticQuery.mockReturnValue(siteMetadata)
);
});
it('renders correctly', () => {
const tree = renderer.create(<Author />).toJSON();
expect(tree).toMatchSnapshot();
});
});

View File

@@ -0,0 +1,25 @@
import React from "react";
import renderer from "react-test-renderer";
import { StaticQuery, useStaticQuery } from "gatsby";
import { Author } from "@/components/Post/Author";
import * as mocks from "@/mocks";
const mockedStaticQuery = StaticQuery as jest.Mock;
const mockedUseStaticQuery = useStaticQuery as jest.Mock;
describe("Author", () => {
console.log(mockedStaticQuery);
beforeEach(() => {
mockedStaticQuery.mockImplementationOnce(({ render }) =>
render(mocks.siteMetadata),
);
mockedUseStaticQuery.mockReturnValue(mocks.siteMetadata);
});
it("renders correctly", () => {
const tree = renderer.create(<Author />).toJSON();
expect(tree).toMatchSnapshot();
});
});

View File

@@ -0,0 +1,28 @@
import React from "react";
import { useSiteMetadata } from "@/hooks";
import { getContactHref } from "@/utils";
import styles from "./Author.module.scss";
const Author = () => {
const { author } = useSiteMetadata();
return (
<div className={styles.author}>
<p className={styles.author__bio}>
{author.bio}
<a
className={styles["author__bio-twitter"]}
href={getContactHref("twitter", author.contacts.twitter)}
rel="noopener noreferrer"
target="_blank"
>
<strong>{author.name}</strong> on Twitter
</a>
</p>
</div>
);
};
export default Author;

View File

@@ -7,7 +7,7 @@ exports[`Author renders correctly 1`] = `
<p
className="author__bio"
>
Test bio
Pellentesque odio nisi, euismod in, pharetra a, ultricies in, diam. Sed arcu.
<a
className="author__bio-twitter"
href="https://www.twitter.com/#"
@@ -15,7 +15,7 @@ exports[`Author renders correctly 1`] = `
target="_blank"
>
<strong>
Test name
John Doe
</strong>
on Twitter
</a>

View File

@@ -1,2 +0,0 @@
// @flow strict
export { default } from './Author';

View File

@@ -0,0 +1 @@
export { default as Author } from "./Author";

View File

@@ -1,28 +0,0 @@
// @flow strict
import React from 'react';
import renderer from 'react-test-renderer';
import { useStaticQuery, StaticQuery } from 'gatsby';
import Comments from './Comments';
import siteMetadata from '../../../../jest/__fixtures__/site-metadata';
import type { RenderCallback } from '../../../types';
describe('Comments', () => {
beforeEach(() => {
StaticQuery.mockImplementationOnce(
({ render }: RenderCallback) => (
render(siteMetadata)
),
useStaticQuery.mockReturnValue(siteMetadata)
);
});
const props = {
postTitle: 'test',
postSlug: '/test'
};
it('renders correctly', () => {
const tree = renderer.create(<Comments {...props} />).toJSON();
expect(tree).toMatchSnapshot();
});
});

View File

@@ -0,0 +1,29 @@
import React from "react";
import renderer from "react-test-renderer";
import { StaticQuery, useStaticQuery } from "gatsby";
import { Comments } from "@/components/Post/Comments";
import * as mocks from "@/mocks";
const mockedStaticQuery = StaticQuery as jest.Mock;
const mockedUseStaticQuery = useStaticQuery as jest.Mock;
describe("Comments", () => {
beforeEach(() => {
mockedStaticQuery.mockImplementationOnce(({ render }) =>
render(mocks.siteMetadata),
);
mockedUseStaticQuery.mockReturnValue(mocks.siteMetadata);
});
const props = {
postTitle: "test",
postSlug: "/test",
};
it("renders correctly", () => {
const tree = renderer.create(<Comments {...props} />).toJSON();
expect(tree).toMatchSnapshot();
});
});

View File

@@ -1,14 +1,14 @@
// @flow strict
import React from 'react';
import ReactDisqusComments from 'react-disqus-comments';
import { useSiteMetadata } from '../../../hooks';
import React from "react";
import ReactDisqusComments from "react-disqus-comments";
type Props = {
postTitle: string,
postSlug: string
};
import { useSiteMetadata } from "@/hooks";
const Comments = ({ postTitle, postSlug }: Props) => {
interface Props {
postTitle: string;
postSlug: string;
}
const Comments: React.FC<Props> = ({ postTitle, postSlug }: Props) => {
const { url, disqusShortname } = useSiteMetadata();
if (!disqusShortname) {

View File

@@ -1,2 +0,0 @@
// @flow strict
export { default } from './Comments';

View File

@@ -0,0 +1 @@
export { default as Comments } from "./Comments";

View File

@@ -1,17 +0,0 @@
// @flow strict
import React from 'react';
import styles from './Content.module.scss';
type Props = {
body: string,
title: string
};
const Content = ({ body, title }: Props) => (
<div className={styles['content']}>
<h1 className={styles['content__title']}>{title}</h1>
<div className={styles['content__body']} dangerouslySetInnerHTML={{ __html: body }} />
</div>
);
export default Content;

View File

@@ -1,21 +1,21 @@
@import '../../../assets/scss/variables';
@import '../../../assets/scss/mixins';
@import "../../../assets/scss/variables";
@import "../../../assets/scss/mixins";
.content {
margin: 0 auto;
max-width: $layout-post-single-width;
padding: 0 15px;
margin: 0 auto;
&__title {
font-size: $typographic-base-font-size * 2;
max-width: $layout-post-width;
font-weight: 600;
margin-left: auto;
margin-right: auto;
font-weight: 600;
max-width: $layout-post-width;
text-align: center;
@include line-height(1.65);
@include margin-top(1);
@include margin-bottom(0)
@include margin-bottom(0);
}
&__body {
@@ -24,38 +24,34 @@
& blockquote {
font-style: italic;
text-align: center;
margin-top: 0;
text-align: center;
@include padding(1, 0);
& p {
max-width: $layout-post-width;
font-size: $typographic-base-font-size * 1.6817;
margin-top: 0;
max-width: $layout-post-width;
@include margin-bottom(1);
@include line-height(1.5)
@include line-height(1.5);
}
}
}
& a {
text-decoration: underline
text-decoration: underline;
}
& * {
max-width: $layout-post-width;
margin-left: auto;
margin-right: auto
margin-right: auto;
max-width: $layout-post-width;
}
& img {
max-width: 100%;
}
}
}
@include breakpoint-md {
@@ -66,7 +62,7 @@
font-size: $typographic-base-font-size * 3;
@include line-height(2.25);
@include margin-top(2.25);
@include margin-bottom(1.5)
@include margin-bottom(1.5);
}
&__body {
@@ -77,11 +73,8 @@
& p {
font-size: $typographic-base-font-size * 1.125;
@include line-height(1.125);
@include margin-bottom(1.125)
@include margin-bottom(1.125);
}
}
}
}
}

View File

@@ -1,16 +0,0 @@
// @flow strict
import React from 'react';
import renderer from 'react-test-renderer';
import Content from './Content';
describe('Content', () => {
it('renders correctly', () => {
const props = {
title: 'test',
body: '<p>test</p>'
};
const tree = renderer.create(<Content {...props} />).toJSON();
expect(tree).toMatchSnapshot();
});
});

View File

@@ -0,0 +1,12 @@
import React from "react";
import renderer from "react-test-renderer";
import { Content } from "@/components/Post/Content";
describe("Content", () => {
it("renders correctly", () => {
const props = { title: "test", body: "<p>test</p>" };
const tree = renderer.create(<Content {...props} />).toJSON();
expect(tree).toMatchSnapshot();
});
});

View File

@@ -0,0 +1,20 @@
import React from "react";
import styles from "./Content.module.scss";
interface Props {
title: string;
body: string;
}
const Content: React.FC<Props> = ({ body, title }: Props) => (
<div className={styles.content}>
<h1 className={styles.content__title}>{title}</h1>
<div
className={styles.content__body}
dangerouslySetInnerHTML={{ __html: body }}
/>
</div>
);
export default Content;

View File

@@ -1,2 +0,0 @@
// @flow strict
export { default } from './Content';

View File

@@ -0,0 +1 @@
export { default as Content } from "./Content";

View File

@@ -1,15 +0,0 @@
// @flow strict
import React from 'react';
import styles from './Meta.module.scss';
type Props = {
date: string
};
const Meta = ({ date }: Props) => (
<div className={styles['meta']}>
<p className={styles['meta__date']}>Published {new Date(date).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' })}</p>
</div>
);
export default Meta;

View File

@@ -1,9 +1,8 @@
@import '../../../assets/scss/variables';
@import '../../../assets/scss/mixins';
@import "../../../assets/scss/variables";
@import "../../../assets/scss/mixins";
.meta {
&__date {
font-style: italic;
}
}
}

View File

@@ -1,15 +0,0 @@
// @flow strict
import React from 'react';
import renderer from 'react-test-renderer';
import Meta from './Meta';
describe('Meta', () => {
it('renders correctly', () => {
const props = {
date: '2016-09-01'
};
const tree = renderer.create(<Meta {...props} />).toJSON();
expect(tree).toMatchSnapshot();
});
});

View File

@@ -0,0 +1,13 @@
import React from "react";
import renderer from "react-test-renderer";
import { Meta } from "@/components/Post/Meta";
describe("Meta", () => {
it("renders correctly", () => {
const props = { date: "2016-09-01" };
const tree = renderer.create(<Meta {...props} />).toJSON();
expect(tree).toMatchSnapshot();
});
});

View File

@@ -0,0 +1,22 @@
import React from "react";
import styles from "./Meta.module.scss";
interface Props {
date: string;
}
const Meta: React.FC<Props> = ({ date }: Props) => (
<div className={styles.meta}>
<p className={styles.meta__date}>
Published{" "}
{new Date(date).toLocaleDateString("en-US", {
year: "numeric",
month: "short",
day: "numeric",
})}
</p>
</div>
);
export default Meta;

View File

@@ -7,7 +7,8 @@ exports[`Meta renders correctly 1`] = `
<p
className="meta__date"
>
Published
Published
Sep 1, 2016
</p>
</div>

View File

@@ -1,2 +0,0 @@
// @flow strict
export { default } from './Meta';

View File

@@ -0,0 +1 @@
export { default as Meta } from "./Meta";

View File

@@ -1,42 +0,0 @@
// @flow strict
import React from 'react';
import { Link } from 'gatsby';
import Author from './Author';
import Comments from './Comments';
import Content from './Content';
import Meta from './Meta';
import Tags from './Tags';
import styles from './Post.module.scss';
import type { Node } from '../../types';
type Props = {
post: Node
};
const Post = ({ post }: Props) => {
const { html } = post;
const { tagSlugs, slug } = post.fields;
const { tags, title, date } = post.frontmatter;
return (
<div className={styles['post']}>
<Link className={styles['post__home-button']} to="/">All Articles</Link>
<div className={styles['post__content']}>
<Content body={html} title={title} />
</div>
<div className={styles['post__footer']}>
<Meta date={date} />
{tags && tagSlugs && <Tags tags={tags} tagSlugs={tagSlugs} />}
<Author />
</div>
<div className={styles['post__comments']}>
<Comments postSlug={slug} postTitle={post.frontmatter.title} />
</div>
</div>
);
};
export default Post;

View File

@@ -1,42 +1,40 @@
@import '../../assets/scss/variables';
@import '../../assets/scss/mixins';
@import "../../assets/scss/variables";
@import "../../assets/scss/mixins";
.post {
&__footer {
max-width: $layout-post-width;
margin: 0 auto;
max-width: $layout-post-width;
padding: 0 15px;
}
&__comments {
max-width: $layout-post-width;
margin: 0 auto;
max-width: $layout-post-width;
padding: 0 15px;
}
&__home-button {
display: block;
max-width: 90px;
height: $button-height;
padding: 0 24px;
line-height: $button-height;
text-align: center;
color: $color-base;
border: 1px solid $color-gray-border;
border-radius: $button-border-radius;
color: $color-base;
display: block;
font-size: $typographic-base-font-size;
font-weight: normal;
height: $button-height;
line-height: $button-height;
margin-left: auto;
margin-right: auto;
max-width: 90px;
padding: 0 24px;
text-align: center;
@include margin-top(1);
&:hover,
&:focus {
color: $color-primary;
}
}
}
@include breakpoint-md {
@@ -50,13 +48,11 @@
}
&__home-button {
position: fixed;
max-width: auto;
left: 30px;
margin: 0;
max-width: auto;
position: fixed;
top: 30px;
left: 30px
}
}
}
}

View File

@@ -1,46 +0,0 @@
// @flow strict
import React from 'react';
import renderer from 'react-test-renderer';
import { useStaticQuery, StaticQuery } from 'gatsby';
import Post from './Post';
import siteMetadata from '../../../jest/__fixtures__/site-metadata';
import type { RenderCallback } from '../../types';
describe('Post', () => {
beforeEach(() => {
StaticQuery.mockImplementationOnce(
({ render }: RenderCallback) => (
render(siteMetadata)
),
useStaticQuery.mockReturnValue(siteMetadata)
);
});
const props = {
post: {
id: 'test-123',
html: '<p>test</p>',
fields: {
slug: '/test',
categorySlug: '/test-category',
tagSlugs: [
'/test_0',
'/test_1'
]
},
frontmatter: {
date: '2016-09-01',
tags: [
'test_0',
'test_1'
],
title: 'test'
}
}
};
it('renders correctly', () => {
const tree = renderer.create(<Post {...props} />).toJSON();
expect(tree).toMatchSnapshot();
});
});

View File

@@ -0,0 +1,41 @@
import React from "react";
import renderer from "react-test-renderer";
import { StaticQuery, useStaticQuery } from "gatsby";
import { Post } from "@/components/Post";
import * as mocks from "@/mocks";
const mockedStaticQuery = StaticQuery as jest.Mock;
const mockedUseStaticQuery = useStaticQuery as jest.Mock;
describe("Post", () => {
beforeEach(() => {
mockedStaticQuery.mockImplementationOnce(({ render }) =>
render(mocks.siteMetadata),
);
mockedUseStaticQuery.mockReturnValue(mocks.siteMetadata);
});
const props = {
post: {
id: "test-123",
html: "<p>test</p>",
fields: {
slug: "/test",
categorySlug: "/test-category",
tagSlugs: ["/test_0", "/test_1"],
},
frontmatter: {
date: "2016-09-01",
tags: ["test_0", "test_1"],
title: "test",
},
},
};
it("renders correctly", () => {
const tree = renderer.create(<Post {...props} />).toJSON();
expect(tree).toMatchSnapshot();
});
});

View File

@@ -0,0 +1,47 @@
import React from "react";
import { Link } from "gatsby";
import type { Node } from "@/types";
import { Author } from "./Author";
import { Comments } from "./Comments";
import { Content } from "./Content";
import { Meta } from "./Meta";
import { Tags } from "./Tags";
import styles from "./Post.module.scss";
interface Props {
post: Node;
}
const Post: React.FC<Props> = ({ post }: Props) => {
const { html } = post;
const { tagSlugs, slug } = post.fields;
const { tags, title, date } = post.frontmatter;
return (
<div className={styles.post}>
<Link className={styles["post__home-button"]} to="/">
All Articles
</Link>
<div className={styles.post__content}>
<Content body={html} title={title} />
</div>
<div className={styles.post__footer}>
<Meta date={date} />
{tags && tagSlugs && <Tags tags={tags} tagSlugs={tagSlugs} />}
<Author />
</div>
<div className={styles.post__comments}>
<Comments postSlug={slug} postTitle={post.frontmatter.title} />
</div>
</div>
);
};
export default Post;

View File

@@ -1,25 +0,0 @@
// @flow strict
import React from 'react';
import { Link } from 'gatsby';
import styles from './Tags.module.scss';
type Props = {
tags: string[],
tagSlugs: string[]
};
const Tags = ({ tags, tagSlugs }: Props) => (
<div className={styles['tags']}>
<ul className={styles['tags__list']}>
{tagSlugs && tagSlugs.map((slug, i) => (
<li className={styles['tags__list-item']} key={tags[i]}>
<Link to={slug} className={styles['tags__list-item-link']}>
{tags[i]}
</Link>
</li>
))}
</ul>
</div>
);
export default Tags;

View File

@@ -1,8 +1,8 @@
@import '../../../assets/scss/variables';
@import '../../../assets/scss/mixins';
@import "../../../assets/scss/variables";
@import "../../../assets/scss/mixins";
.tags {
@include margin-bottom(.5);
@include margin-bottom(0.5);
&__list {
list-style: none;
@@ -14,24 +14,20 @@
margin: 10px 5px;
&-link {
display: inline-block;
height: $button-height;
padding: 0 24px;
line-height: $button-height;
border: 1px solid $color-gray-border;
text-decoration: none;
border-radius: $button-border-radius;
color: $color-base;
display: inline-block;
height: $button-height;
line-height: $button-height;
padding: 0 24px;
text-decoration: none;
&:hover,
&:focus {
color: $color-primary;
}
}
}
}
}
}

View File

@@ -1,22 +0,0 @@
// @flow strict
import React from 'react';
import renderer from 'react-test-renderer';
import Tags from './Tags';
describe('Tags', () => {
it('renders correctly', () => {
const props = {
tags: [
'test_0',
'test_1'
],
tagSlugs: [
'/test_0',
'/test_1'
]
};
const tree = renderer.create(<Tags {...props} />).toJSON();
expect(tree).toMatchSnapshot();
});
});

View File

@@ -0,0 +1,15 @@
import React from "react";
import renderer from "react-test-renderer";
import { Tags } from "@/components/Post/Tags";
describe("Tags", () => {
it("renders correctly", () => {
const props = {
tags: ["test_0", "test_1"],
tagSlugs: ["/test_0", "/test_1"],
};
const tree = renderer.create(<Tags {...props} />).toJSON();
expect(tree).toMatchSnapshot();
});
});

View File

@@ -0,0 +1,25 @@
import React from "react";
import { Link } from "gatsby";
import styles from "./Tags.module.scss";
type Props = {
tags: string[];
tagSlugs: string[];
};
const Tags = ({ tags, tagSlugs }: Props) => (
<div className={styles["tags"]}>
<ul className={styles["tags__list"]}>
{tagSlugs &&
tagSlugs.map((slug, i) => (
<li className={styles["tags__list-item"]} key={tags[i]}>
<Link to={slug} className={styles["tags__list-item-link"]}>
{tags[i]}
</Link>
</li>
))}
</ul>
</div>
);
export default Tags;

View File

@@ -1,2 +0,0 @@
// @flow strict
export { default } from './Tags';

View File

@@ -0,0 +1 @@
export { default as Tags } from "./Tags";

View File

@@ -40,7 +40,8 @@ exports[`Post renders correctly 1`] = `
<p
className="meta__date"
>
Published
Published
Sep 1, 2016
</p>
</div>
@@ -78,7 +79,7 @@ exports[`Post renders correctly 1`] = `
<p
className="author__bio"
>
Test bio
Pellentesque odio nisi, euismod in, pharetra a, ultricies in, diam. Sed arcu.
<a
className="author__bio-twitter"
href="https://www.twitter.com/#"
@@ -86,7 +87,7 @@ exports[`Post renders correctly 1`] = `
target="_blank"
>
<strong>
Test name
John Doe
</strong>
on Twitter
</a>

View File

@@ -1,2 +0,0 @@
// @flow strict
export { default } from './Post';

View File

@@ -0,0 +1 @@
export { default as Post } from "./Post";