Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
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
44 changes: 44 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"root": true,
"plugins": ["@typescript-eslint", "react-hooks", "jest"],
"extends": [
"airbnb",
"plugin:@typescript-eslint/recommended",
"plugin:jest/recommended",
"prettier/@typescript-eslint"
],
"env": {
"browser": true
},
"settings": {
"import/resolver": {
"typescript": {}
}
},
"rules": {
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn"
},
"overrides": [
{
"files": ["**/*.ts", "**/*.tsx"],
"parser": "@typescript-eslint/parser",
"rules": {
"react/jsx-filename-extension": "off",
"camelcase": "off",
"@typescript-eslint/camelcase": ["error", { "properties": "never" }],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/indent": ["error", 2]
}
},

{
"files": ["**/*.js"],
"parser": "@typescript-eslint/parser",
"rules": {
"@typescript-eslint/no-var-requires": "off"
}
}
]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package-lock.json
# Build directory
/public
.DS_Store
build

.env
.firebase/*
Expand Down
12 changes: 0 additions & 12 deletions .prettierrc

This file was deleted.

53 changes: 26 additions & 27 deletions gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if (process.env.ENVIROMENT !== 'production') {
// eslint-disable-next-line global-require
require('dotenv').config();
}

Expand All @@ -17,50 +18,53 @@ module.exports = {
'gatsby-plugin-catch-links',
'gatsby-plugin-react-helmet',
{
resolve: `gatsby-plugin-canonical-urls`,
resolve: 'gatsby-plugin-canonical-urls',
options: {
siteUrl: config.siteUrl,
},
},
`gatsby-plugin-sharp`,
'gatsby-plugin-sharp',
{
resolve: `gatsby-source-filesystem`,
resolve: 'gatsby-source-filesystem',
options: {
name: `learn`,
name: 'learn',
path: `${__dirname}/src/documentation/`,
include: [`**/*.md`], // ignore files starting with a dot
include: ['**/*.md'], // ignore files starting with a dot
},
},

{
resolve: `gatsby-plugin-manifest`,
resolve: 'gatsby-plugin-manifest',
options: {
name: config.title,
/* eslint-disable @typescript-eslint/camelcase */
short_name: config.title,
start_url: '/',
background_color: config.color,
theme_color: config.color,
/* eslint-disable @typescript-eslint/camelcase */
display: config.display,
icon: config.icon,
},
},
'gatsby-plugin-offline',
`gatsby-plugin-typescript`,
'gatsby-plugin-typescript',
{
resolve: 'gatsby-transformer-remark',
options: {
plugins: [
{
resolve: `gatsby-remark-autolink-headers`,
resolve: 'gatsby-remark-autolink-headers',
options: {
offsetY: `125`,
icon: `<svg aria-hidden="true" height="20" version="1.1" viewBox="0 0 16 16" width="20"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>`,
className: `autolink-headers`,
offsetY: '125',
icon: '<svg aria-hidden="true" height="20" version="1.1" viewBox="0 0 16 16" width="20"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>',
className: 'autolink-headers',
maintainCase: false,
removeAccents: true,
},
},
{
resolve: `gatsby-remark-prismjs`,
resolve: 'gatsby-remark-prismjs',
options: {
classPrefix: 'language-',
inlineCodeMarker: null,
Expand All @@ -70,7 +74,7 @@ module.exports = {
},
},
{
resolve: `gatsby-remark-images`,
resolve: 'gatsby-remark-images',
options: {
maxWidth: 590,
},
Expand All @@ -79,7 +83,7 @@ module.exports = {
},
},
{
resolve: `gatsby-plugin-sitemap`,
resolve: 'gatsby-plugin-sitemap',
options: {
query: `{
site {
Expand All @@ -106,28 +110,23 @@ module.exports = {
}
}`,
serialize: ({ site, allSitePage, allMarkdownRemark }) => {
let pages = [];
allSitePage.edges.map(edge => {
pages.push({
const sitePages = allSitePage.edges.map(edge => ({
url: site.siteMetadata.siteUrlNoSlash + edge.node.path,
changefreq: `daily`,
changefreq: 'daily',
priority: 0.7,
});
});
allMarkdownRemark.edges.map(edge => {
pages.push({
}));
const markdownRemark = allMarkdownRemark.edges.map(edge => ({
url: `${site.siteMetadata.siteUrlNoSlash}/${edge.node.fields.slug}`,
changefreq: `daily`,
changefreq: 'daily',
priority: 0.7,
});
});
}));

return pages;
return sitePages.concat(markdownRemark);
},
},
},
{
resolve: `gatsby-plugin-emotion`,
resolve: 'gatsby-plugin-emotion',
},
],
};
37 changes: 20 additions & 17 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const createSlug = require('./src/util/createSlug');
/* eslint-disable @typescript-eslint/no-var-requires */
// Use in this file CommonJS syntax see https://www.gatsbyjs.org/docs/migrating-from-v1-to-v2/#convert-to-either-pure-commonjs-or-pure-es6
const path = require('path');
const createSlug = require('./src/util/createSlug');

exports.createPages = ({ graphql, actions }) => {
const { createPage, createRedirect, createNodeField } = actions;
const { createPage } = actions;

return new Promise((resolve, reject) => {
const docTemplate = path.resolve('./src/templates/learn.tsx');
Expand Down Expand Up @@ -54,9 +56,10 @@ exports.createPages = ({ graphql, actions }) => {
}
}
}
`
).then(result => {
`,
).then((result) => {
if (result.errors) {
// eslint-disable-next-line no-console
console.log(result.errors);
reject(result.errors);
}
Expand All @@ -65,7 +68,7 @@ exports.createPages = ({ graphql, actions }) => {
const docPages = [];
edges.forEach(({ node }, index) => {
const {
fields: { slug, authors },
fields: { slug },
frontmatter: { title, section },
parent: { relativePath },
} = node;
Expand All @@ -80,8 +83,7 @@ exports.createPages = ({ graphql, actions }) => {
}

let nextNodeData = null;
const nextNode =
index === edges.length - 1 ? undefined : edges[index + 1].node;
const nextNode = index === edges.length - 1 ? undefined : edges[index + 1].node;
if (nextNode) {
nextNodeData = {
slug: nextNode.fields.slug,
Expand All @@ -108,7 +110,7 @@ exports.createPages = ({ graphql, actions }) => {
});
});

docPages.forEach(page => {
docPages.forEach((page) => {
createPage({
path: `/${page.slug}`,
component: docTemplate,
Expand All @@ -117,44 +119,45 @@ exports.createPages = ({ graphql, actions }) => {
next: page.next,
previous: page.previous,
relativePath: page.relativePath,
navigationData: navigationData,
navigationData,
},
});
if (page.slug === 'introduction-to-nodejs')
if (page.slug === 'introduction-to-nodejs') {
createPage({
path: `/`,
path: '/',
component: docTemplate,
context: {
slug: page.slug,
next: page.next,
previous: page.previous,
relativePath: page.relativePath,
navigationData: navigationData,
navigationData,
},
});
}
});
})
}),
);
});
};

exports.onCreateNode = ({ node, getNode, actions }) => {
exports.onCreateNode = ({ node, actions }) => {
if (node.internal.type === 'MarkdownRemark') {
const { createNodeField } = actions;

const slug = createSlug(node.frontmatter.title);
createNodeField({
node,
name: `slug`,
name: 'slug',
value: slug,
});

let authors = node.frontmatter.authors;
let { authors } = node.frontmatter;
if (authors) {
authors = authors.split(',');
createNodeField({
node,
name: `authors`,
name: 'authors',
value: authors,
});
}
Expand Down
24 changes: 17 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"dotenv": "^6.0.0",
"emotion": "^10.0.7",
"emotion-server": "^10.0.7",
"eslint-plugin-jest": "^22.17.0",
"gatsby": "^2.13.13",
"gatsby-plugin-canonical-urls": "^2.0.10",
"gatsby-plugin-catch-links": "^2.0.9",
Expand All @@ -31,7 +32,6 @@
"react-dom": "^16.8.0",
"react-emotion": "^10.0.0",
"react-helmet": "^5.2.0",
"tslint": "^5.11.0",
"typescript": "^3.1.1"
},
"keywords": [
Expand All @@ -43,14 +43,15 @@
"build": "gatsby build",
"build-ci": "gatsby build --prefix-paths",
"start": "gatsby develop",
"format": "prettier --write '**/*.{ts,tsx,js}'",
"format": "yarn lint:fix",
"format-check": "prettier --check '**/*.{ts,tsx,js}'",
"jest": "jest",
"update-snapshot": "jest --updateSnapshot",
"test": "yarn format-check && yarn tslint && yarn jest",
"test": "yarn lint && yarn jest",
"test-watch": "yarn jest --watch",
"test-ci": "yarn test --coverage && codecov",
"tslint": "tslint --project ./tsconfig.json",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"serve": "yarn build && clear && gatsby serve"
},
"devDependencies": {
Expand All @@ -60,16 +61,25 @@
"@commitlint/config-conventional": "^7.3.1",
"@types/jest": "^24.0.5",
"@types/react-test-renderer": "^16.8.1",
"@typescript-eslint/eslint-plugin": "^1.4.2",
"babel-jest": "^24.1.0",
"babel-preset-gatsby": "^0.1.7",
"codecov": "^3.3.0",
"eslint": "^5.14.1",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-prettier": "^4.1.0",
"eslint-import-resolver-typescript": "^1.1.1",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-prettier": "^3.0.1",
"eslint-plugin-react": "^7.12.4",
"eslint-plugin-react-hooks": "^1.4.0",
"husky": "^1.3.1",
"identity-obj-proxy": "^3.0.0",
"jest": "^24.1.0",
"prettier": "^1.16.4",
"react-test-renderer": "^16.8.2",
"tslint-config-prettier": "^1.15.0",
"tslint-react": "^3.6.0"
"typescript": "~3.2.1"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -103,7 +113,7 @@
"husky": {
"hooks": {
"commit-msg": "commitlint --edit $HUSKY_GIT_PARAMS",
"pre-push": "yarn format-check && yarn tslint"
"pre-push": "yarn lint"
}
}
}
Loading