Alright! Today is a great day, many years after I lost my old blog, I’ve decided to start from scratch and create again one blog to publish my experiences and don’t fall in the inertia. Here I will describe my experience creating my own blog using Gatsby and Github Pages.
This article will be structured in
What you will learn?
- Overview of Gatsby and GitHub Pages
- Creating your project with Gatsby
- Publishing your project in Github Pages
- Adding Travis CI to automate the deploy process
- Next steps
1. Overview of Gatsby and GitHub Pages
First things first. Before to explain you, how to create your site I will tell you more about Gatsby and Github Pages, if you alreay know about them, go ahead to the next step.
Taken from the official website Gatsby is:
Gatsby is a free and open source framework based on React that helps developers build blazing fast websites and apps.
So we can use the power of React, GraphQL, Markdown and some data sources to create really fast web sites, re-using lots of plugins and publishing in many Web hosting, in my case I will deploy in Github Pages.
2. Creating your project with Gatsby
After I reviewd some tutorials and content in Internet, about how to create my own site with Gatsby, here are my steps.
- Follow the quick-start with Gatsby to install the
- Once you have installed the Gatsby CLI can create your Gatsby project based on some Gatsby templates. To be honest, the simplest way to create your own site is using a template instead of creating everything from scratch. Also you can find some examples made with Gatsby and other technologies.
- In my case I’ve created my site based on the beautiful narative theme. Once of the benefits of using this template are:
- Really good structure to add author and post
- Can be integrated with Contentful to create dynamic post instead of static post (commits in Github)
- Can be integrated with Mailchimp to reuse tue Subscriptions for newsletter
- The styles can be modifies based on the theme-ui
- The metadata and social networks can be modified in a simple way.
- Is open source.
If you want to see more templates, you can visit this link.
3. Publishing your project in Github Pages
I will no describe the step by step to publish your site in Github Pages, because in the official page is described really well. However I can provide you some learned lessons.
- I recommend to install the gh-pages dependency to avoid doing many manual things.
- Don’t forget to create the
gh-pagesbranch in your repo.
- If you are trying to select your
gh-pagesbranch, please follow the next link.
- Please review the How Gatsby works with Github pages.
4. Adding Travis CI to automate the deploy process
In few words, Travis CI is
Easily sync your projects with Travis CI and you’ll be testing your code in minutes!
To be honest, this have changed my perspective and life when is needed to automate the deploy process based on commits in a branch.
To deploy your site using Travis CI you need to create a
.travis.yml file in your root folder project and add the next configuration.
1language: node_js2cache:3 directories:4 - ~/.npm5notifications:6 email:7 recipients:8 - [THE EMAIL WHERE WILL BE SENT THE NOTIFICATIONS]9 on_success: always10 on_failure: always11node_js:12 - '12.13.1'13git:14 depth: 315script:16 - npm run build17deploy:18 provider: pages19 skip_cleanup: true20 keep_history: true21 github_token: $GITHUB_TOKEN22 local_dir: public23 on:24 branch: master
You also can follow this article to get more details.
- You can achieve the same result using Circle CI
5. Next steps
It’s hard to tell you all things you can do with Gatsby, however you can start reviwing: