Skip to content

Commit

Permalink
Remove lodash
Browse files Browse the repository at this point in the history
aldis-ameriks committed Dec 28, 2023
1 parent 319b554 commit 2876f58
Showing 4 changed files with 8 additions and 35 deletions.
1 change: 0 additions & 1 deletion gatsby-config.ts
Original file line number Diff line number Diff line change
@@ -58,7 +58,6 @@ const gatsbyConfig: GatsbyConfig = {
'gatsby-plugin-image',
'gatsby-plugin-sharp',
'gatsby-transformer-sharp',
'gatsby-plugin-lodash',
'gatsby-plugin-sitemap',
{
resolve: 'gatsby-plugin-manifest',
11 changes: 8 additions & 3 deletions gatsby-node.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { GatsbyNode } from 'gatsby'
import path from 'path'
import _ from '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: any) =>
@@ -22,13 +21,13 @@ export const onCreateNode: GatsbyNode['onCreateNode'] = ({ node, actions }: any)
Object.prototype.hasOwnProperty.call(node.frontmatter, 'slug')
) {
// If the frontmatter has a "slug", use it
slug = `/${_.kebabCase(node.frontmatter.slug)}`
slug = `/${convertToKebabCase(node.frontmatter.slug)}`
} else if (
Object.prototype.hasOwnProperty.call(node, 'frontmatter') &&
Object.prototype.hasOwnProperty.call(node.frontmatter, 'title')
) {
// If not derive a slug from the "title" in the frontmatter
slug = `/${_.kebabCase(node.frontmatter.title)}`
slug = `/${convertToKebabCase(node.frontmatter.title)}`
}
createNodeField({ node, name: 'slug', value: slug })
}
@@ -80,3 +79,9 @@ export const createPages: GatsbyNode<Queries.ProjectNodesQuery>['createPages'] =
})
})
}

const convertToKebabCase = (text: string) =>
text
.replace(/([a-z])([A-Z])/g, '$1-$2')
.replace(/[\s_]+/g, '-')
.toLowerCase()
29 changes: 0 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -38,7 +38,6 @@
"gatsby": "5.13.1",
"gatsby-plugin-google-analytics": "5.13.0",
"gatsby-plugin-image": "3.13.0",
"gatsby-plugin-lodash": "6.13.0",
"gatsby-plugin-manifest": "5.13.0",
"gatsby-plugin-mdx": "5.13.0",
"gatsby-plugin-offline": "6.13.0",
@@ -52,7 +51,6 @@
"gatsby-transformer-sharp": "5.13.0",
"jquery": "3.7.1",
"justifiedGallery": "3.8.1",
"lodash": "4.17.21",
"polished": "4.2.2",
"react": "18.2.0",
"react-dom": "18.2.0",

0 comments on commit 2876f58

Please sign in to comment.