Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrated to Next.js v10 away from GatsbyJS v1 #29

Merged
merged 7 commits into from
Oct 28, 2020
Merged

Migrated to Next.js v10 away from GatsbyJS v1 #29

merged 7 commits into from
Oct 28, 2020

Conversation

jonrh
Copy link
Owner

@jonrh jonrh commented Oct 28, 2020

No description provided.

The renaming and relocation of these files and folders is to facilitate a migration from GatsbyJS to Next.js v10.

Renamed all blog post folders. Removed the "YYYY-MM-DD---" prefix. This prefix was a legacy naming scheme from Gatsby v0 beta from 3 years ago. As I recall it was required for Gatsby to know what files should be considered Markdown blog posts. There is now no longer any need for this and in order to retain the same URL structure the folders will need to be renamed as they have.
For about 3 years I used Gatsby as a static site generator for jonrh.is. I started using the v0 beta and then migrated to v1 later on. Gatsby dependencies were unstable to the point that in 2020 I could no longer make changes.

I have used Next.js v9 in two smaller projects and the developer experience was significantly better. Especially when used in combination with Vercel.

Deleted Rollbar error tracking for now. I may add it back later.

Deleted html.js. layout/index.js and _app.js now serves that purpose.

Deleted blog-post.js file that served as a blog post template. In future commits I will either convert all markdown files into React JavaScript files or use MDX.

Modified the Font Awsome minified font slightly. Changed the URL of the fonts that it loads. Before the URLs were assuming the font files were located relative to the CSS file in a sibling /fonts folder. However for now they have been relocated to the public/fonts/ folder so the URL path is now absolute. A bit of a dirty hack but I'm okay with it for now. I hope to move away from Font Awesome in the future and use something lighter.

Moved the required contents of typography.js (sets the font sizes, etc) into layout/index.js. I would like to move away from this dependency later on but for now I am focused on porting the site from GatsbyJS to Next.js with ideally no visual changes.

Files deleted that were only relevant for GatsbyJS:
+ .babelr
+ gatsby-config.js
+ gatsby-node.js

Greatly simplified package.json. Removed all dependencies that were no longer required. Most of them were Gatsby plugins or utility libraries required to work with Gatsby.

about.js / blog.js / dashboard-consulting.js / index.js / portfolio.js. Refactored to use new Layout. Removed React prop types because most of them were very vague anyway (just telling an input is an object). Removed GraphQL query strings that were used by GatsbyJS.

New file: pages/_app.js. This is the root file of a Next.js v10 app (see docs). This is sort of the equivalent to the html.js file that Gatsby v1 used (no longer used in v2 if I remember correctly).
This CircleCI config file was used to deploy the website to AWS. Static files were stored in S3 and then globally distributed with CloudFront. I will be using Vercel hosting now that I have Next.js. I have used it in a few projects before and it's a terrific combination.

As far as I know, Vercel actually used S3 and CloudFront under the hood but now I do not have to worry about it.
Followed the setup instructions by mdxjs.com: https://mdxjs.com/getting-started/next

With MDX it will become a lot less work to convert the site to Next.js because all the blog posts are written in Markdown. With MDX I can also intermix React components which is really nice.
Post.js is a template file/component for each and every blogpost. Originally designed to be used by MDX files.

To show images I use the newly introduced next/image component. I think it works similarly to the resharp image component of Gatsby. It creates an <img> tag with a sourceset of the images in various sizes. What is new with this component is that width and height has to be defined. I just use the original dimensions of the image so the aspect ratio stays the same. The style layout already makes sure that images don't go out of bounds for large source images.

The next/image component expects images to be located in the public/ folder. I couldn't get it to work otherwise. Therefore all blog post images have been relocated to public/images/name-of-blogpost-folder/.

Deleted the markdown front matter of ever post as it is no longer relevant. Converted it to <Post title="Blog post title" date="October 28, 2020" /> instead.
@vercel
Copy link

vercel bot commented Oct 28, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/jonrh/jonrh-is/bgxvc0inq
✅ Preview: https://jonrh-is-git-nextjs-v10.jonrh.vercel.app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant