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
- 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
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.
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.
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.
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.
language: node_js cache: directories: - ~/.npm notifications: email: recipients: - [THE EMAIL WHERE WILL BE SENT THE NOTIFICATIONS] on_success: always on_failure: always node_js: - '12.13.1' git: depth: 3 script: - npm run build deploy: provider: pages skip_cleanup: true keep_history: true github_token: $GITHUB_TOKEN local_dir: public on: branch: master
You also can follow this article to get more details.
- You can achieve the same result using Circle CI
It's hard to tell you all things you can do with Gatsby, however you can start reviwing:
- Review Gatsby Plugins
- Review Gatsby Resources
- Connect Gatsby with Contentful in five minutes
- Publish your site in other hosting like netlify
- Improve the GraphQL setup with Gatsby
- Add Gatsby Integrations
- Improve your SEO and Analytics tracking.
If you want to see my site, this is the demo: