Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit 1f33cc1

Browse files
authored
gatsby-config.ts + gatsby-node.ts (#97) 🚀
* Updated gatsby to 4.9.0 * Migrated gatsby config to typescript 🚀 * gatsby-node migrated 🚀 * Fixed types for gatsby plugin feed 🚀
1 parent 24b3a79 commit 1f33cc1

File tree

7 files changed

+2953
-528
lines changed

7 files changed

+2953
-528
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Change Log
22
All changes to Chicio coding will be documented in this file.
33

4+
## [5.4.0](https://github.com/chicio/chicio.github.io/releases/tag/v5.4.0)
5+
Release date: 2021-03-xx
6+
7+
#### Added
8+
9+
- gatsby-config migrated to typescript
10+
- gatsby-node migrated to typescript
11+
412
## [5.3.0](https://github.com/chicio/chicio.github.io/releases/tag/v5.3.0)
513
Release date: 2021-12-03
614

gatsby-config.js renamed to gatsby-config.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
import { GatsbyConfig } from "gatsby";
2+
13
require("dotenv").config();
24

3-
module.exports = {
5+
interface GatsbyPluginFeed {
6+
query: {
7+
site: any;
8+
allMarkdownRemark: any;
9+
};
10+
}
11+
12+
const config: GatsbyConfig = {
413
siteMetadata: {
514
title:
615
"Fabrizio Duroni | Fabrizio Duroni ‘Chicio Coding’ official site with profile details. Official blog chicio coding. Main skills: mobile application development, computer graphics, web development.",
@@ -68,23 +77,20 @@ module.exports = {
6877
name: "images",
6978
path: "./src/images/",
7079
},
71-
__key: "images",
7280
},
7381
{
7482
resolve: "gatsby-source-filesystem",
7583
options: {
7684
name: "pages",
7785
path: "./src/pages/",
7886
},
79-
__key: "pages",
8087
},
8188
{
8289
resolve: `gatsby-source-filesystem`,
8390
options: {
8491
path: `./src/posts`,
8592
name: `posts`,
8693
},
87-
__key: "posts",
8894
},
8995
{
9096
resolve: `gatsby-transformer-remark`,
@@ -163,13 +169,17 @@ module.exports = {
163169
`,
164170
feeds: [
165171
{
166-
serialize: ({ query: { site, allMarkdownRemark } }) => {
167-
return allMarkdownRemark.edges.map((edge) => {
172+
serialize: (data: GatsbyPluginFeed) => {
173+
return data.query.allMarkdownRemark.edges.map((edge: any) => {
168174
return Object.assign({}, edge.node.frontmatter, {
169175
description: edge.node.excerpt,
170176
date: edge.node.frontmatter.date,
171-
url: site.siteMetadata.siteUrl + edge.node.fields.slug,
172-
guid: site.siteMetadata.siteUrl + edge.node.fields.slug,
177+
url:
178+
data.query.site.siteMetadata.siteUrl +
179+
edge.node.fields.slug,
180+
guid:
181+
data.query.site.siteMetadata.siteUrl +
182+
edge.node.fields.slug,
173183
custom_elements: [{ "content:encoded": edge.node.html }],
174184
});
175185
});
@@ -212,3 +222,5 @@ module.exports = {
212222
},
213223
],
214224
};
225+
226+
export default config;

gatsby-node.js renamed to gatsby-node.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
const path = require("path");
2-
const readingTime = require("reading-time");
3-
const {
4-
slugs,
5-
generateTagSlug,
6-
generatePostSlug,
7-
} = require("./src/logic/slug");
8-
const { createFilePath } = require("gatsby-source-filesystem");
1+
import { GatsbyNode } from "gatsby";
2+
import readingTime from "reading-time";
3+
import * as path from "path";
4+
import { createFilePath } from "gatsby-source-filesystem";
5+
import { generatePostSlug, generateTagSlug, slugs } from "./src/logic/slug";
96

10-
exports.createPages = async ({ graphql, actions, reporter }) => {
7+
export const createPages: GatsbyNode["createPages"] = async ({
8+
graphql,
9+
actions,
10+
reporter,
11+
}) => {
1112
const { createPage } = actions;
12-
const result = await graphql(
13+
const result: any = await graphql(
1314
`
1415
{
1516
allMarkdownRemark(
@@ -41,12 +42,12 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
4142
const posts = result.data.allMarkdownRemark.edges;
4243

4344
//Create posts pages
44-
posts.forEach(({ node }) => {
45+
posts.forEach((post: any) => {
4546
createPage({
46-
path: node.fields.slug,
47+
path: post.node.fields.slug,
4748
component: path.resolve(`./src/templates/post.tsx`),
4849
context: {
49-
slug: node.fields.slug,
50+
slug: post.node.fields.slug,
5051
},
5152
});
5253
});
@@ -68,8 +69,8 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
6869
});
6970

7071
//Create tag pages
71-
const tags = result.data.tagsGroup.group;
72-
tags.forEach((tag) => {
72+
const tags: any = result.data.tagsGroup.group;
73+
tags.forEach((tag: any) => {
7374
createPage({
7475
path: generateTagSlug(tag.fieldValue),
7576
component: path.resolve("./src/templates/tag.tsx"),
@@ -80,15 +81,19 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
8081
});
8182
};
8283

83-
exports.onCreateNode = ({ node, actions, getNode }) => {
84+
export const onCreateNode: GatsbyNode["onCreateNode"] = ({
85+
node,
86+
actions,
87+
getNode,
88+
}) => {
8489
const { createNodeField } = actions;
8590
if (node.internal.type === `MarkdownRemark`) {
8691
const filename = createFilePath({ node, getNode, basePath: `pages` });
8792
createNodeField({ node, name: `slug`, value: generatePostSlug(filename) });
8893
createNodeField({
8994
node,
9095
name: `readingTime`,
91-
value: readingTime(node.rawMarkdownBody),
96+
value: readingTime(node.rawMarkdownBody as string),
9297
});
9398
}
9499
};

0 commit comments

Comments
 (0)