Skip to content
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
19 changes: 11 additions & 8 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
{
"extends": ["prettier", "prettier/react"],
"parser": "babel-eslint",
"extends": ["prettier"],
"parser": "@babel/eslint-parser",
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error",
"no-var": "warn"
},
"env": {
"node": true,
"es6": true
"browser": true,
"es2021": true
},
"parserOptions": {
"ecmaVersion": 8,
"ecmaVersion": "latest",
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true,
"modules": true
"jsx": true
},
"sourceType": "module"
"sourceType": "module",
"requireConfigFile": false,
"babelOptions": {
"presets": ["@babel/preset-react"]
}
}
}
6 changes: 2 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
node-version: [10.x]
node-version: [22.x]

steps:
- name: Checkout code
Expand All @@ -27,9 +27,7 @@ jobs:
cache: 'npm'

- name: Install dependencies
run: |
npm install -g npm@5.8.0
npm ci
run: npm ci

- name: Run linting
run: npm run lint
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# Jon Gear's Website And Blog

[![Netlify Status](https://api.netlify.com/api/v1/badges/4771c8dc-35e6-45fa-96d2-158d20f5c2d0/deploy-status)](https://app.netlify.com/projects/gear-dev/deploys)

Thanks for checking out my site. This is the complete code for my website and blog.

## Setup
Expand Down
9 changes: 3 additions & 6 deletions gatsby-browser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import 'typeface-bitter';
import 'typeface-open-sans';

import { wrapRootElement as wrap } from './wrap-root-element';

export const wrapRootElement = wrap;
import { wrapRootElement as wrap } from './wrap-root-element';

export const wrapRootElement = wrap;
9 changes: 4 additions & 5 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ module.exports = {
},
},
{
resolve: 'gatsby-plugin-google-analytics',
resolve: 'gatsby-plugin-google-gtag',
options: {
trackingId: config.googleAnalyticsID,
trackingIds: [config.googleAnalyticsID],
},
},
{
resolve: 'gatsby-mdx',
resolve: 'gatsby-plugin-mdx',
options: {
extensions: ['.mdx', '.md'],
gatsbyRemarkPlugins: [
{
resolve: 'gatsby-remark-external-links',
Expand All @@ -48,14 +49,12 @@ module.exports = {
linkImagesToOriginal: false,
},
},
// TODO: Replace with "mdx-component-autolink-headers"
{
resolve: 'gatsby-remark-autolink-headers',
options: {
maintainCase: false,
},
},
//'gatsby-remark-copy-linked-files'
],
},
},
Expand Down
30 changes: 22 additions & 8 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const _ = require('lodash');

// graphql function doesn't throw an error so we have to check to check for the result.errors to throw manually
const wrapper = promise =>
promise.then(result => {
const wrapper = (promise) =>
promise.then((result) => {
if (result.errors) {
throw result.errors;
}
return result;
});

exports.onCreateNode = ({ node, actions }) => {
exports.onCreateNode = ({ node, actions, getNode }) => {
const { createNodeField } = actions;

let slug;
Expand All @@ -27,6 +27,16 @@ exports.onCreateNode = ({ node, actions }) => {
slug = `/${_.kebabCase(node.frontmatter.title)}`;
}
createNodeField({ node, name: 'slug', value: slug });

// Calculate reading time
const parent = getNode(node.parent);
if (parent && parent.internal && parent.internal.content) {
const content = parent.internal.content;
const wordsPerMinute = 200;
const wordCount = content.split(/\s+/).length;
const readingTime = Math.ceil(wordCount / wordsPerMinute);
createNodeField({ node, name: 'timeToRead', value: readingTime });
}
}
};

Expand All @@ -39,7 +49,7 @@ exports.createPages = async ({ graphql, actions }) => {
const result = await wrapper(
graphql(`
{
allMdx(sort: { fields: [frontmatter___date], order: DESC }) {
allMdx(sort: { frontmatter: { date: DESC } }) {
edges {
node {
fields {
Expand All @@ -49,6 +59,10 @@ exports.createPages = async ({ graphql, actions }) => {
title
categories
}
id
internal {
contentFilePath
}
}
}
}
Expand All @@ -64,7 +78,7 @@ exports.createPages = async ({ graphql, actions }) => {

createPage({
path: edge.node.fields.slug,
component: postTemplate,
component: `${postTemplate}?__contentFilePath=${edge.node.internal.contentFilePath}`,
context: {
slug: edge.node.fields.slug,
prev,
Expand All @@ -75,17 +89,17 @@ exports.createPages = async ({ graphql, actions }) => {

const categorySet = new Set();

_.each(posts, edge => {
_.each(posts, (edge) => {
if (_.get(edge, 'node.frontmatter.categories')) {
edge.node.frontmatter.categories.forEach(cat => {
edge.node.frontmatter.categories.forEach((cat) => {
categorySet.add(cat);
});
}
});

const categories = Array.from(categorySet);

categories.forEach(category => {
categories.forEach((category) => {
createPage({
path: `/categories/${_.kebabCase(category)}`,
component: categoryTemplate,
Expand Down
6 changes: 3 additions & 3 deletions gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { wrapRootElement as wrap } from './wrap-root-element';
export const wrapRootElement = wrap;
import { wrapRootElement as wrap } from './wrap-root-element';

export const wrapRootElement = wrap;
Loading