{"componentChunkName":"component---src-templates-blog-post-js","path":"/migrating-jekyll-gatsby","result":{"data":{"markdownRemark":{"html":"<h3 class=\"font-sans font-bold break-normal text-gray-700 pt-2 pb-2\">Making a blogging platform with React, how satisfying</h3>\n<p class=\"text-base test-grey-700 pt-4 pb-4\">Two years ago, when I went back into coding, I wanted to document my learning, have a few posts here and there.\nSomething that I could look back at a few years later, and say \"Wow, I've come a long way since then\". Indeed, that's the case, and as a result of my learning, I'm now a full-stack Javascript developer. Which means that the Jekyll, that I've chosen at the time for its simplicity of use and deployment, is not really the go-to choice anymore as a blogging platform.</p>\n<ul class=\"\">\n<li>What if there was a static-site generator made in Node/JS ? </li>\n</ul>\n<p class=\"text-base test-grey-700 pt-4 pb-4\">Well, there is, and it's called Gatsby. I can't even begin to explain the excitement I've felt when I've stumbled upon Gatsby's website. A static-site generator, where you can write components in React, that mixes static and dynamic content, with no routing hassle thanks to the opinionated routing structure, and where you can use GraphQL queries for pretty much everything as a result of a strong plugins system ? Wow. As a React lover, that was it : I <em>had</em> to migrate my Jekyll site to Gatsby.</p>\n<p class=\"text-base test-grey-700 pt-4 pb-4\">As a background note, I've worked quite intensively with React these last months, may it be with create-react-app, or server-side rendered (SSR) React with Next.js. SSR has been really amazing performance-wise, and it brings a few nice benefits over client-side, such as better SEO, which is what you want for a blog, really. Gatsby then sounded like the perfect option for me, to build a blogging platform on.</p>\n<h3 class=\"font-sans font-bold break-normal text-gray-700 pt-2 pb-2\">Keeping the content</h3>\n<p class=\"text-base test-grey-700 pt-4 pb-4\">Thankfully, Gatsby has support for Markdown files, that it can parse with the <code class=\"language-text\">gatsby-transformer-remark</code> plugin. So there was no action required there,even though I've switched to one folder per article, with the relevant expected naming, as it's a bit cleaner of a structure IMO.</p>\n<h3 class=\"font-sans font-bold break-normal text-gray-700 pt-2 pb-2\">Theming / Building components</h3>\n<p class=\"text-base test-grey-700 pt-4 pb-4\">Again, the theme I had at the time was a pre-made theme, which I had no reason to keep anymore, as I wanted to make my Gatsby app from scratch, styles included. As such, there was no fiddling needed with how to keep the theme, and making your own Gatsby theme also comes with the fact that you can really understand how it works.</p>\n<p class=\"text-base test-grey-700 pt-4 pb-4\">In reality, there is no \"making a theme\" here, as you're building the blog platform (almost) entirely from scratch with React component. As such, you're not tied to a very opinionated app structure like with Jekyll. Here, you are free to model you app and styles however you want, may it be with styled-components, SASS (there is a plugin for it), or even good old CSS if that's your thing.</p>\n<p class=\"text-base test-grey-700 pt-4 pb-4\">Gatsby exposes a very robust API to get data, may it be from markdown files, from a REST API.. All thanks to GraphQL queries. It's then really easy to get post(s) data in your components.\nFor example, getting all the posts from Markdown file was done like this, in a named export : </p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"> query allNodesQuery <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">allMarkdownRemark</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">sort<span class=\"token operator\">:</span><span class=\"token punctuation\">{</span>fields<span class=\"token operator\">:</span><span class=\"token punctuation\">[</span>frontmatter___date<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> order<span class=\"token operator\">:</span><span class=\"token constant\">DESC</span><span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      edges <span class=\"token punctuation\">{</span>\n        node <span class=\"token punctuation\">{</span>\n          html\n          frontmatter <span class=\"token punctuation\">{</span>\n            <span class=\"token function\">date</span><span class=\"token punctuation\">(</span>formatString<span class=\"token operator\">:</span> <span class=\"token string\">\"MMMM DD, YYYY\"</span><span class=\"token punctuation\">)</span>\n            title\n            path\n          <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n      <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<p class=\"text-base test-grey-700 pt-4 pb-4\">It is then used in the default export, like this : </p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">IndexPage</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span>data<span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> allMarkdownRemark<span class=\"token operator\">:</span> posts <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> data<span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">{</span>posts<span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span>node<span class=\"token operator\">:</span> post<span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n      <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span><span class=\"token constant\">RENDER</span> <span class=\"token constant\">A</span> <span class=\"token constant\">POST</span> <span class=\"token constant\">HERE</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n      <span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span></code></pre></div>\n<h3 class=\"font-sans font-bold break-normal text-gray-700 pt-2 pb-2\">Plugins</h3>\n<p class=\"text-base test-grey-700 pt-4 pb-4\">This is the strength of Gatsby, and what made it really easy to start using.\nThere are plugin for the data layer (expose data from various sources availble to query through GraphQL), and even plugins can have their own plugins !\nTake for example <code class=\"language-text\">gatsby-transformer-remark</code> responsible for the parsing of Markdown files:\nIt also has a plugin for the parsing of images in md files, as well as a plugin for parsing code blocks.</p>\n<p class=\"text-base test-grey-700 pt-4 pb-4\">If you need a plugin for something, there is a good chance the community has done it already.</p>","frontmatter":{"date":"April 03, 2018","path":"/migrating-jekyll-gatsby","title":"Migrating from Jekyll to Gatsby"}}},"pageContext":{}},"staticQueryHashes":[]}