Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.cache/
.github/
public/
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@
"build": "gatsby build",
"build-ci": "gatsby build --prefix-paths",
"start": "gatsby develop",
"format": "prettier --write '**/*.tsx'",
"test": "jest"
"format": "prettier --write '**/*.{ts,tsx,js}'",
"format-check": "prettier --check '**/*.{ts,tsx,js}'",
"jest": "jest",
"test": "yarn run jest && yarn run format-check && yarn run tslint",
"tslint": "tslint --project ./tsconfig.json"
},
"devDependencies": {
"@babel/core": "^7.3.3",
Expand All @@ -57,7 +60,7 @@
"husky": "^1.3.1",
"identity-obj-proxy": "^3.0.0",
"jest": "^24.1.0",
"prettier": "^1.14.2",
"prettier": "^1.16.4",
"react-test-renderer": "^16.8.2",
"tslint-config-prettier": "^1.15.0",
"tslint-react": "^3.6.0"
Expand Down
10 changes: 6 additions & 4 deletions src/components/article.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ const Article = ({
flexWrap: 'wrap',
marginTop: '5rem',
alignItems: 'center',
}}>
}}
>
Contributors:
{authors && authors.map(author => (
author && <AuthorLink username={author} key={author}/>
))}
{authors &&
authors.map(
author => author && <AuthorLink username={author} key={author} />
)}
</div>
<EditLink relativePath={relativePath} />
<Pagination previous={previous} next={next} />
Expand Down
14 changes: 7 additions & 7 deletions src/components/hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import React from 'react';

type Props = {
title: string;
}
};

const Hero = ({ title }: Props) => (
<div className="hero">
<h1>{title}</h1>
<div className="diagonal-hero-bg">
<div className="stars">
<div className="small"/>
<div className="medium"/>
<div className="big"/>
</div>
<div className="small" />
<div className="medium" />
<div className="big" />
</div>
</div>
</div>
)
);

export default Hero
export default Hero;
9 changes: 7 additions & 2 deletions src/components/navigation-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const NavigationItem = ({ isDone, isActive, slug, title, onClick }: Props) => {
if (ref && isActive) {
element.current = ref;
}
}
};

useEffect(() => {
if (element.current) {
Expand All @@ -34,7 +34,12 @@ const NavigationItem = ({ isDone, isActive, slug, title, onClick }: Props) => {
}

return (
<Link ref={handleRef} to={`/${slug}`} onClick={onClick} className={className}>
<Link
ref={handleRef}
to={`/${slug}`}
onClick={onClick}
className={className}
>
{title}
</Link>
);
Expand Down
6 changes: 3 additions & 3 deletions src/components/pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PaginationInfo } from '../types';
type Props = {
previous?: PaginationInfo;
next?: PaginationInfo;
}
};

const ulStyles: SerializedStyles = css`
display: flex;
Expand All @@ -33,6 +33,6 @@ const Pagination = ({ previous, next }: Props) => (
)}
</li>
</ul>
)
);

export default Pagination
export default Pagination;
18 changes: 9 additions & 9 deletions src/components/seo.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react'
import { Helmet } from 'react-helmet'
import config from '../config'
import React from 'react';
import { Helmet } from 'react-helmet';
import config from '../config';

type Props = {
title?: string
description?: string
img?: string
}
title?: string;
description?: string;
img?: string;
};

const SEO = ({ title, description, img }: Props) => (
<Helmet
Expand Down Expand Up @@ -93,6 +93,6 @@ const SEO = ({ title, description, img }: Props) => (
>
<html lang={config.lang} />
</Helmet>
)
);

export default SEO
export default SEO;
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ module.exports = {
twitterCard: `summary`,
twitterImgAlt: `The Node.js Hexagon Logo`,
facebook: `https://www.facebook.com/nodejsfoundation/`,
}
};
16 changes: 8 additions & 8 deletions src/pages/404.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export default (props: Props) => {
return (
<Layout title={title} description={description}>
<Hero title={title} />
<article style={{width: '100%'}} className="article-reader">
<p>
The page you're trying to access does not exist. Go back to the
Homepage or find what you're looking for in the menu.
</p>
<p>
Take me back to the <a href="/">Homepage</a> →
</p>
<article style={{ width: '100%' }} className="article-reader">
<p>
The page you're trying to access does not exist. Go back to the
Homepage or find what you're looking for in the menu.
</p>
<p>
Take me back to the <a href="/">Homepage</a> →
</p>
</article>
</Layout>
);
Expand Down
12 changes: 6 additions & 6 deletions src/util/createSlug.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ function createSlug(title) {
let slug = title.toLowerCase().trim();

const sets = [
{to: 'nodejs', from: /node.js/ }, // Replace node.js
{to: '-and-', from: /&/ }, // Replace &
{to: '-', from: /[/_,:;\\ .]/g } // Replace /_,:;\. and whitespace
{ to: 'nodejs', from: /node.js/ }, // Replace node.js
{ to: '-and-', from: /&/ }, // Replace &
{ to: '-', from: /[/_,:;\\ .]/g }, // Replace /_,:;\. and whitespace
];

sets.forEach(set => {
Expand All @@ -13,9 +13,9 @@ function createSlug(title) {

return slug
.replace(/[^\w\-]+/g, '') // Remove any non word characters
.replace(/--+/g, '-') // Replace multiple hyphens with single
.replace(/^-/, '') // Remove any leading hyphen
.replace(/-$/, ''); // Remove any trailing hyphen
.replace(/--+/g, '-') // Replace multiple hyphens with single
.replace(/^-/, '') // Remove any leading hyphen
.replace(/-$/, ''); // Remove any trailing hyphen
}

module.exports = createSlug;
21 changes: 16 additions & 5 deletions src/util/scrollTo.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
const easeInOutCubic = (t: number, b: number, c: number, d: number) => (t /= d / 2) < 1 ? c / 2 * t * t * t + b : c / 2 * ((t -= 2) * t * t + 2) + b;
const easeInOutCubic = (t: number, b: number, c: number, d: number) =>
(t /= d / 2) < 1
? (c / 2) * t * t * t + b
: (c / 2) * ((t -= 2) * t * t + 2) + b;

export function scrollTo(scrollTo: number, duration: number = 333): Promise<boolean> {
const start = (window.pageYOffset || document.documentElement.scrollTop) - (document.documentElement.clientTop || 0);
export function scrollTo(
scrollTo: number,
duration: number = 333
): Promise<boolean> {
const start =
(window.pageYOffset || document.documentElement.scrollTop) -
(document.documentElement.clientTop || 0);
const change = scrollTo - start;
let previousTime = window.performance.now();
let currentTime = 0;
Expand All @@ -12,7 +20,10 @@ export function scrollTo(scrollTo: number, duration: number = 333): Promise<bool
const increment = time - previousTime;
previousTime = time;
currentTime += increment;
(document.scrollingElement || window).scrollTo(0, easeInOutCubic(currentTime, start, change, duration));
(document.scrollingElement || window).scrollTo(
0,
easeInOutCubic(currentTime, start, change, duration)
);

if (currentTime < duration) {
return window.requestAnimationFrame(animateScroll);
Expand All @@ -23,4 +34,4 @@ export function scrollTo(scrollTo: number, duration: number = 333): Promise<bool
});

return ret;
};
}
2 changes: 1 addition & 1 deletion test-setup.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
global.___loader = {
enqueue: jest.fn(),
}
};
4 changes: 3 additions & 1 deletion test/components/author-link.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import AuthorLink from '../../src/components/author-link';
describe('AuthorLink component', () => {
it('renders correctly', () => {
const username = 'test-author';
const tree = renderer.create(<AuthorLink key={username} username={username} />).toJSON();
const tree = renderer
.create(<AuthorLink key={username} username={username} />)
.toJSON();
expect(tree).toMatchSnapshot();
});
it('does not render without a username', () => {
Expand Down
14 changes: 7 additions & 7 deletions test/components/header.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react'
import renderer from 'react-test-renderer'
import Header from '../../src/components/header'
import React from 'react';
import renderer from 'react-test-renderer';
import Header from '../../src/components/header';

describe('Tests for Header component', () => {
it('renders correctly', () => {
const tree = renderer.create(<Header />).toJSON()
expect(tree).toMatchSnapshot()
})
})
const tree = renderer.create(<Header />).toJSON();
expect(tree).toMatchSnapshot();
});
});
2 changes: 1 addition & 1 deletion test/components/hero.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Hero from '../../src/components/hero';
describe('Hero component', () => {
it('renders correctly', () => {
const title = 'Introduction to Node.js';
const tree = renderer.create(<Hero title={title}/>).toJSON();
const tree = renderer.create(<Hero title={title} />).toJSON();
expect(tree).toMatchSnapshot();
});
});
8 changes: 1 addition & 7 deletions test/components/seo.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ describe('SEO component', () => {
const title = 'title-mock';
const description = 'description-mock';
const img = 'image-mock';
renderer.render(
<SEO
title={title}
description={description}
img={img}
/>
);
renderer.render(<SEO title={title} description={description} img={img} />);
expect(renderer.getRenderOutput()).toMatchSnapshot();
});
it('uses config properties as fallback for missing props', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/util/createSlug.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Tests for createSlug', () => {
'title: subtitle',
'a; b',
'C:\\Program Files\\nodejs',
'a---b'
'a---b',
].map(createSlug);
expect(slugs).toEqual([
'how-to-install-nodejs',
Expand All @@ -26,7 +26,7 @@ describe('Tests for createSlug', () => {
'title-subtitle',
'a-b',
'c-program-files-nodejs',
'a-b'
'a-b',
]);
});
});
6 changes: 3 additions & 3 deletions test/util/onCreateNode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ function createMockNodeOfType(type) {
getNode: jest.fn(),
node: {
internal: { type },
frontmatter: { title: 'Test title' }
}
}
frontmatter: { title: 'Test title' },
},
};
}

describe('Tests for onCreateNode', () => {
Expand Down
3 changes: 3 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"extends": ["tslint-react", "tslint-config-prettier"],
"jsRules": {
"no-empty": true
},
"rules": {
"array-type": [true, "array"],
"arrow-return-shorthand": true,
Expand Down
7 changes: 4 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9564,9 +9564,10 @@ preserve@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"

prettier@^1.14.2:
version "1.15.3"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.15.3.tgz#1feaac5bdd181237b54dbe65d874e02a1472786a"
prettier@^1.16.4:
version "1.16.4"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.16.4.tgz#73e37e73e018ad2db9c76742e2647e21790c9717"
integrity sha512-ZzWuos7TI5CKUeQAtFd6Zhm2s6EpAD/ZLApIhsF9pRvRtM1RFo61dM/4MSRUA0SuLugA/zgrZD8m0BaY46Og7g==

pretty-bytes@^4.0.2:
version "4.0.2"
Expand Down