<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: liwenzhi</title>
    <description>The latest articles on Forem by liwenzhi (@lwz7512).</description>
    <link>https://forem.com/lwz7512</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F180882%2Fdc03fef4-ab47-4e07-a6a8-002c154bccb7.jpg</url>
      <title>Forem: liwenzhi</title>
      <link>https://forem.com/lwz7512</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/lwz7512"/>
    <language>en</language>
    <item>
      <title>Minimal dev.to post publish tool</title>
      <dc:creator>liwenzhi</dc:creator>
      <pubDate>Thu, 18 Feb 2021 20:48:03 +0000</pubDate>
      <link>https://forem.com/lwz7512/minimal-dev-to-post-publish-tool-5ea7</link>
      <guid>https://forem.com/lwz7512/minimal-dev-to-post-publish-tool-5ea7</guid>
      <description>&lt;p&gt;Just wrote a small NodeJS application to publish markdown content into dev.to:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/lwz7512/dev_to_blog"&gt;dev_to_blog&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For those devs who love to use VSCode to write blog articles, have a try this minimal dev.to blog publisher.&lt;/p&gt;

&lt;p&gt;Any feedbacks are welcome!&lt;/p&gt;

&lt;p&gt;I'm currently looking for a new job, if you like my open source &lt;a href="https://github.com/lwz7512"&gt;projects&lt;/a&gt;, and my &lt;a href="https://wenzhi.netlify.app/"&gt;experience&lt;/a&gt; match your needs, feel free to contact me.&lt;/p&gt;

&lt;p&gt;Thank you!&lt;/p&gt;

</description>
      <category>tooling</category>
      <category>node</category>
      <category>writing</category>
    </item>
    <item>
      <title>Using image in Gatsby application by a clear way</title>
      <dc:creator>liwenzhi</dc:creator>
      <pubDate>Thu, 15 Aug 2019 20:31:23 +0000</pubDate>
      <link>https://forem.com/lwz7512/using-image-in-gatsby-application-by-a-clear-way-2a96</link>
      <guid>https://forem.com/lwz7512/using-image-in-gatsby-application-by-a-clear-way-2a96</guid>
      <description>&lt;p&gt;Gatsby has many features to win the developers' love and prevails over other mainstream static site generators. One of those features is &lt;a href="https://www.gatsbyjs.org/packages/gatsby-image/" rel="noopener noreferrer"&gt;gatsby-image&lt;/a&gt; component. It solved the image optimization problem with the specified dimension scope you defined, progressively and responsively presenting to the webpage gives user a comfortable browsing experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Steps to use gatsby-image
&lt;/h2&gt;

&lt;p&gt;Like the official doc said, there are three steps needed to implement a gatsby image in Gatsby website:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;install &lt;a href="https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-image" rel="noopener noreferrer"&gt;gatsby-image&lt;/a&gt; component and two other build dependency plugins: &lt;a href="https://www.gatsbyjs.org/packages/gatsby-transformer-sharp/" rel="noopener noreferrer"&gt;gatsby-transformer-sharp&lt;/a&gt; and &lt;a href="https://www.gatsbyjs.org/packages/gatsby-plugin-sharp/" rel="noopener noreferrer"&gt;gatsby-plugin-sharp&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;define image source directory in gatsby-source-filesystem plugin as well as above two plugin in &lt;code&gt;gatsby-config.js&lt;/code&gt; plugins section&lt;/li&gt;
&lt;li&gt;import &lt;code&gt;gatsby-image&lt;/code&gt; component to your gatsby page component and declare a image tag/instance with a &lt;code&gt;fixed&lt;/code&gt; or &lt;code&gt;fluid&lt;/code&gt; property whose value derived from graphql query.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the step 2, you tell the Gatsby build tool, where to find the &lt;code&gt;root&lt;/code&gt; directory of all the image files. Just like the doc example, the root directory here is &lt;code&gt;src/images/&lt;/code&gt; of current Gatsby project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  resolve: `gatsby-source-filesystem`,
  options: {
    name: `images`,
    path: path.join(__dirname, `src`, `images`),
  },
},
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the step 3, you tell gatsby-image component instance where to get the file: graphql query result.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const query = graphql`
  query {
    file(relativePath: { eq: "blog/avatars/kyle-mathews.jpeg" }) {
      childImageSharp {
        # Specify the image processing specifications right in the query.
        # Makes it trivial to update as your page's design changes.
        fixed(width: 125, height: 125) {
          ...GatsbyImageSharpFixed
        }
      }
    }
  }
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Which directory to put image?
&lt;/h2&gt;

&lt;p&gt;After seeing this graphql code snippet, you may wonder where's the &lt;code&gt;blog/avatars/kyle-mathews.jpeg&lt;/code&gt;? Is it under project root or src/images? let's take a test from a blank gatsby project.&lt;/p&gt;

&lt;p&gt;create gatsby project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ gatsby new using-image-in-gatsby
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;place kyle-mathews.jpeg image under &lt;code&gt;src/images/blog/avatars/&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;replace original index.js content with the following code:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Flwz7512%2Fmy-dev.to%2Fmaster%2Fblog-posts%2Fusing-image-in-gatsby%2Fassets%2Findex_20190815_37.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Flwz7512%2Fmy-dev.to%2Fmaster%2Fblog-posts%2Fusing-image-in-gatsby%2Fassets%2Findex_20190815_37.png" alt="index page code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: Dont forget the &lt;code&gt;data&lt;/code&gt; property in IndexPage properties.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, we can start the website without the need to modify the other stuff:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ gatsby develop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Visit the &lt;code&gt;http://localhost:8000/&lt;/code&gt; in your browser, you'll see the correct result.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Flwz7512%2Fmy-dev.to%2Fmaster%2Fblog-posts%2Fusing-image-in-gatsby%2Fassets%2Fkyle_20190815_38.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Flwz7512%2Fmy-dev.to%2Fmaster%2Fblog-posts%2Fusing-image-in-gatsby%2Fassets%2Fkyle_20190815_38.png" alt="kyle"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This experiment verified our speculation, that is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;gatsy-image query(graphql) using relative path under the path defined in gatsby-source-filesystem as query condition!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  How about the dynamic image source value?
&lt;/h2&gt;

&lt;p&gt;Above example use static value &lt;code&gt;blog/avatars/kyle-mathews.jpeg&lt;/code&gt; to query in graphql expression. Then, what if the query condition is from markdown file meta data?&lt;/p&gt;

&lt;p&gt;Official doc about &lt;a href="https://www.gatsbyjs.org/docs/working-with-images-in-markdown/" rel="noopener noreferrer"&gt;Working with image in Markdown posts and pages&lt;/a&gt; told us the placing the featuredImage in the same position of markdown file:&lt;/p&gt;

&lt;p&gt;file structure:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;├── src
  ├── pages
    ├── example-post.md
    ├── awesome-image.png
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;example-post.md:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;---
title: My Amazing Post
featuredImage: ./awesome-image.png
---

Content goes here!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this solution, it works though, but, if you have many posts which include many images in each post, the directory structure will grow big dramatically and end up with chaos.&lt;/p&gt;

&lt;p&gt;How to restructure the images path in a reasonable way?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step one: deine a new content source in &lt;code&gt;gatsby-config.js&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;plugins: [
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        path: `${__dirname}/content`,
        name: `content`,
      },
    },
    ...
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Step two: place all the images under &lt;code&gt;content/assets&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;separate image files and .md files to different folder&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;├── content
  ├── posts
    ├── example-post.md
    ├── ....md
  ├── assets
      ├── fantastic-image.png
      ├── awesome-image.png
      |── ...
├── src
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;Step three: reference the image using relative path in markdown file metadata.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;example-post.md:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;---
title: My Amazing Post
featuredImage: ../assets/awesome-image.png
---

Business intro is missing...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to use html img tag in a Gatsby application
&lt;/h2&gt;

&lt;p&gt;In a normal web application, html img element can use relative or absolute path to assign &lt;code&gt;src&lt;/code&gt; property. We use image in a native and static way like &lt;a href="https://www.gatsbyjs.org/docs/static-folder/" rel="noopener noreferrer"&gt;the official doc&lt;/a&gt; said, place image under &lt;code&gt;static&lt;/code&gt; folder, display image in webpage as we expected. But, when we build and deploy the gatsby site the &lt;a href="https://pages.github.com/" rel="noopener noreferrer"&gt;GitHub Pages&lt;/a&gt;, visit it under an URL pattern like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://username.github.io/your-gatsby-website/" rel="noopener noreferrer"&gt;https://username.github.io/your-gatsby-website/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The images declared by img tag broken all!&lt;/p&gt;

&lt;p&gt;Although all the &lt;code&gt;gatsby-image&lt;/code&gt;s built by &lt;code&gt;$ gatsby build --prefx-paths&lt;/code&gt; works, but those native imgs don't work.&lt;/p&gt;

&lt;p&gt;What's the solution?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One solution is refactor all the &lt;code&gt;img&lt;/code&gt;s to &lt;code&gt;gatsby-image&lt;/code&gt; components&lt;/li&gt;
&lt;li&gt;Another solution is add context prefix the img &lt;code&gt;src&lt;/code&gt; property.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img src="/ueofcweb/images/project-home.jpg" className="img-fluid" alt="ultronele screenshot" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;ueofcweb&lt;/code&gt; is the github project name, &lt;code&gt;images/project-home.jpg&lt;/code&gt; is actually under &lt;code&gt;ueofcweb/static&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you're refactoring a traditional website which use a large amount of img tags, the second option would be a cheap option. My production &lt;a href="https://github.com/runbytech/ueofcweb" rel="noopener noreferrer"&gt;officail site&lt;/a&gt; is migrated from bootstrap/jquey stack, while I was adding it to the &lt;a href="https://www.gatsbyjs.org/showcase/" rel="noopener noreferrer"&gt;Gatsby showcase&lt;/a&gt;, I spend hours to figure out that the second approach is the best way to me.&lt;/p&gt;

&lt;p&gt;Last note I can give in this post is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Do not include folders under static folder, it's a BAD practice ending up with build error `childImageSharp' of null.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Gatsby image is the best responsive image solution which I have met. It frees you from the tedious optimization work in the build phase, add good performance and excellent user experience to your website. It deserves you to spend time to delve into and use proficiently.&lt;/p&gt;

</description>
      <category>gatsby</category>
      <category>react</category>
      <category>image</category>
    </item>
    <item>
      <title>Why More Developers Should Shift to Gatsby</title>
      <dc:creator>liwenzhi</dc:creator>
      <pubDate>Sat, 13 Jul 2019 03:10:46 +0000</pubDate>
      <link>https://forem.com/lwz7512/thinking-in-gatsby-way-series-to-build-a-static-web-application-overview-9mh</link>
      <guid>https://forem.com/lwz7512/thinking-in-gatsby-way-series-to-build-a-static-web-application-overview-9mh</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Flwz7512%2Fmy-dev.to%2Fmaster%2Fblog-posts%2Fthinking-in-gatsby-overview%2Fassets%2Fovidiu-gruescu-boJRk86YW5k-unsplash-2000.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Flwz7512%2Fmy-dev.to%2Fmaster%2Fblog-posts%2Fthinking-in-gatsby-overview%2Fassets%2Fovidiu-gruescu-boJRk86YW5k-unsplash-2000.jpg" alt="Photo by Ovidiu Gruescu on Unsplash"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As the one of the top static site generators, Gatsby have gained much momentum since last year. According to a recent statistics &lt;a href="https://npm-stat.com/charts.html?package=gatsby&amp;amp;from=2018-07-04&amp;amp;to=2019-07-04" rel="noopener noreferrer"&gt;charts&lt;/a&gt; show that the average downloads per week reach 200k around. Many web developers are attracted by its slogan: &lt;strong&gt;&lt;code&gt;build blazing fast websites and apps&lt;/code&gt;&lt;/strong&gt;, I am among them luckily. At the first impression, it may seems easy to start, but when you delve into it, things not like that.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why choose Gatsby
&lt;/h3&gt;

&lt;p&gt;7 months ago, I was looking for a web development framework to build a new elearning product, the ideal candidate should meet this tech requirements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;easy to get started&lt;/li&gt;
&lt;li&gt;no database dependency&lt;/li&gt;
&lt;li&gt;reactjs as front end&lt;/li&gt;
&lt;li&gt;markdown file as content source&lt;/li&gt;
&lt;li&gt;great performance while running&lt;/li&gt;
&lt;li&gt;scalability in customization dev&lt;/li&gt;
&lt;li&gt;lower cost for deployment&lt;/li&gt;
&lt;li&gt;no need content editor in backend&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All this conditions together point to a final solution: a static CMS, then I found the StaticGen. Among the top 5 frameworks, Jekyll, Hugo, Hexo, are not unfamiliar to me. They all use markdown file as content source, but not reactjs tech stack. The first one Next.js, whereas, do not support rendering markdown file to html page by default. In the end, I choose Gatsby as my final dev platform for it meet almost all my requirements.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to design the project structure
&lt;/h3&gt;

&lt;p&gt;We all know that how to create a reactjs application skeleton using &lt;strong&gt;&lt;code&gt;create-react-app&lt;/code&gt;&lt;/strong&gt;. Gatsby also has its cli tool &lt;strong&gt;&lt;code&gt;gatsby&lt;/code&gt;&lt;/strong&gt; to complete some tasks like project creation, start dev server, build project to production deployment and such.&lt;/p&gt;

&lt;p&gt;A typical &lt;a href="https://www.gatsbyjs.org/docs/gatsby-project-structure/" rel="noopener noreferrer"&gt;gatsby site structure&lt;/a&gt; created by &lt;strong&gt;&lt;code&gt;$ gatsby new my-gatsby-site&lt;/code&gt;&lt;/strong&gt; may like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Flwz7512%2Fmy-dev.to%2Fmaster%2Fblog-posts%2Fthinking-in-gatsby-overview%2Fassets%2Fgatsby_default_20190706_7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Flwz7512%2Fmy-dev.to%2Fmaster%2Fblog-posts%2Fthinking-in-gatsby-overview%2Fassets%2Fgatsby_default_20190706_7.png" alt="gatsby-default-struc"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you just treat it as a SSR(server side render) framework using reactjs, it's very similar to Next.js. But the truth is that the both are totally different. Actually, Gatsby doesn't render page while request received, it use &lt;strong&gt;&lt;code&gt;render at build time&lt;/code&gt;&lt;/strong&gt; approach to output static html content already transformed in build phase. Another difference between the two framework is that:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Gatsby using markdown, json, csv, yaml file, even database as content source. Combined with GraphQL, those contents are mapped to template component and then rendered into static web application.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is how the Gatsby works in nature, it's more like an engine, leveraging various kinds of plugin to transform different data source to unified data format which can be fetched by GraphQL query, you developer just write template page and GraphQL sentence to display your dynamic content.&lt;/p&gt;

&lt;p&gt;Then, back to our project structure, how do we reorganize project so as to let Gatsby render our content file to browser? That's the &lt;strong&gt;&lt;code&gt;magical part&lt;/code&gt;&lt;/strong&gt; which make Gatsby unique to other frameworks.&lt;/p&gt;

&lt;p&gt;Take the first Gatsby official starter project &lt;a href="https://github.com/gatsbyjs/gatsby-starter-blog" rel="noopener noreferrer"&gt;gatsby-starter-blog&lt;/a&gt; for example, we use &lt;strong&gt;&lt;code&gt;gatsby new&lt;/code&gt;&lt;/strong&gt; command to clone a gatsby-starter-blog into my-blog-starter directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# create a new Gatsby site using the blog starter
$ gatsby new my-blog-starter https://github.com/gatsbyjs/gatsby-starter-blog
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The newly created my-blog-starter project ends up a directory structure like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Flwz7512%2Fmy-dev.to%2Fmaster%2Fblog-posts%2Fthinking-in-gatsby-overview%2Fassets%2Fgatsby_blog_20190706_10.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Flwz7512%2Fmy-dev.to%2Fmaster%2Fblog-posts%2Fthinking-in-gatsby-overview%2Fassets%2Fgatsby_blog_20190706_10.png" alt="my-blog-starter"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The top red rectangle outlines the &lt;strong&gt;&lt;code&gt;content&lt;/code&gt;&lt;/strong&gt; directory which contains blog post content in markdown format(.md) and images referenced in post. This is an additional directory not included in the previous my-gatsby-site structure. Besides, &lt;strong&gt;&lt;code&gt;templates&lt;/code&gt;&lt;/strong&gt; directory is also a new directory which contains the post template component in charge of fetching markdown file content through GraphQL to reactjs components.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Put content directory in the project root is a good practice in Gatsby project, as well as templates directory under src directory.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Other good practices in planning project structure may include putting &lt;strong&gt;&lt;code&gt;hooks&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;style&lt;/code&gt;&lt;/strong&gt; directory under src directory, hooks contains all the hook components, and style contains all the css module file separated from those template and page components. My preferred &lt;strong&gt;&lt;code&gt;src&lt;/code&gt;&lt;/strong&gt; structure may like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;├── src
  ├── components
  ├── hooks
  ├── pages
  ├── stye
  ├── templates
  ├── utils
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Official Gatsby Project Structure document is &lt;a href="https://www.gatsbyjs.org/docs/gatsby-project-structure/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How's the Gatsby dev workflow look like
&lt;/h3&gt;

&lt;p&gt;In the my-blog-starter project, we saw the content .md file and the blog-post.js template. Then, who does the combination task and how does it works? The anwser is in &lt;strong&gt;&lt;code&gt;gatsby-node.js&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Basically, gatsby-node.js file act as an assembling factory, it first transform content source into node model, then create page components with template and context parameters originated from node object.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Official document about the Gatsby build lifecycle is &lt;a href="https://www.gatsbyjs.org/docs/gatsby-lifecycle-apis/" rel="noopener noreferrer"&gt;here&lt;/a&gt;, also the must read &lt;a href="https://www.gatsbyjs.org/docs/gatsby-internals/" rel="noopener noreferrer"&gt;Behind the Scenes with Gatsby Internals&lt;/a&gt;, gives developer a thorough description of the internal work mechanism.&lt;/p&gt;

&lt;p&gt;Here, I would like to summarize the process into a simple graph:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Flwz7512%2Fmy-dev.to%2Fmaster%2Fblog-posts%2Fthinking-in-gatsby-overview%2Fassets%2Fgatsy_node_cb_20190707_11.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Flwz7512%2Fmy-dev.to%2Fmaster%2Fblog-posts%2Fthinking-in-gatsby-overview%2Fassets%2Fgatsy_node_cb_20190707_11.png" alt="gatsby-node.js"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While developing Gatsby applications, we must understand 2 important config files first: &lt;strong&gt;&lt;code&gt;gatsby-config.js&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;gatsby-node.js&lt;/code&gt;&lt;/strong&gt;. One is for website metadata definition and plugins reference, another is for build process callback functions implementation.&lt;/p&gt;

&lt;p&gt;That are the major difference from the traditional web development. In traditional web development workflow, we start web server, read application related config such as port number, DB access account and other global parameters, then expose service to client request. But in Gatsby, we don't run service in server, we create content in build time through plugins and callback functions, then deliver them to CDN.&lt;/p&gt;

&lt;p&gt;Simply put, Gatsby workflow can be outlined in such a diagram:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Flwz7512%2Fmy-dev.to%2Fmaster%2Fblog-posts%2Fthinking-in-gatsby-overview%2Fassets%2Fgatsby_workflow_20190707_13.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Flwz7512%2Fmy-dev.to%2Fmaster%2Fblog-posts%2Fthinking-in-gatsby-overview%2Fassets%2Fgatsby_workflow_20190707_13.png" alt="gatsby workflow"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, our routine iteration development work may start with preparation work which may include writing config file and page templates, as well as content source, then implement callback functions in gatsby-node.js, last run &lt;strong&gt;&lt;code&gt;$ gasby develop&lt;/code&gt;&lt;/strong&gt; to see the result.&lt;/p&gt;

&lt;p&gt;Among that files, the large amount of time will be taken by template component development. you need to implement UI, interactive logic, write GraphQL sentence in &lt;strong&gt;&lt;code&gt;graphql explorer&lt;/code&gt;&lt;/strong&gt; to test the data you want to display, then copy those query sentence and paste into template component for later build use. The template component is like a glue to connect data source and UI layer.&lt;/p&gt;

&lt;p&gt;Wait, what if the data is not in file but in DB or 3rd part system? The anwser is using the existing gatsby plugin or developing your own gatsby plugins.&lt;/p&gt;

&lt;p&gt;So, to work with Gatsby, you must think in a Gatsby way, just as the above diagram described:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;using &lt;strong&gt;&lt;code&gt;Plugin&lt;/code&gt;&lt;/strong&gt; to fetch and convert source data to the Gatsby known data model&lt;/li&gt;
&lt;li&gt;using &lt;strong&gt;&lt;code&gt;Graphql&lt;/code&gt;&lt;/strong&gt; to query UI/template needed data from Gatsby&lt;/li&gt;
&lt;li&gt;using build &lt;strong&gt;&lt;code&gt;Hooks&lt;/code&gt;&lt;/strong&gt;(callback functions) to generate html content from template components.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What changes does it take to the front devs
&lt;/h3&gt;

&lt;p&gt;Web framework emerging endless, but excellent framework is so rare. In numerous JAMstack solutions, I believe that Gatsby is the most distinctive and innovative. Gatsby claims that it can build website with a blazing fast user experience, Lighthouse test in its &lt;a href="https://www.gatsbyjs.org/docs/audit-with-lighthouse/" rel="noopener noreferrer"&gt;official document&lt;/a&gt; proved their statement. How did they make it?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.gatsbyjs.org/docs/gatsby-core-philosophy/" rel="noopener noreferrer"&gt;The idea&lt;/a&gt; behind the product and &lt;a href="https://www.gatsbyjs.org/docs/prpl-pattern/" rel="noopener noreferrer"&gt;the architecture pattern&lt;/a&gt; they are following ensure its high performance.&lt;/p&gt;

&lt;p&gt;For a normal developer, this may mean a lot when you want to develop a prototype web application, deliver user a great user experience without taking pain to tune it little by little, furthermore, you don't have much money to purchase database service and web server.&lt;/p&gt;

&lt;p&gt;Take my first Gatsby project &lt;a href="http://ultronele.com" rel="noopener noreferrer"&gt;UltronEle&lt;/a&gt; for example, I toke near 3 months(60~70 workdays) development time to implement the first version of a feature rich elearning product. All my dev time spent in business logic and interactive logic implementation, no need to process database, no need to deploy a server in release environment. This make my product very light, and cost efficient.&lt;/p&gt;

&lt;p&gt;Without Gatsby framework, I doubt if my product would be born so soon. Although the initial exploration phase in Gatsby felt a little confusion, but the whole development experience was so cool.&lt;/p&gt;

&lt;p&gt;Gatsby's popularity may predict a better internet, the next generation of internet technology, with high speed display, excellent user experience, light weight deployment, lower cost to develop and use. This change would bring web developers and IT service sector plenty of potential opportunities.&lt;/p&gt;

&lt;h3&gt;
  
  
  Are there any pits still exist
&lt;/h3&gt;

&lt;p&gt;By the time of this post written, unfortunately, there still exist one annoying bug in Gatsby v2.3.27. That's the historic error statement: &lt;strong&gt;&lt;code&gt;TypeError: Cannot read property 'childImageSharp' of null&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Flwz7512%2Fmy-dev.to%2Fmaster%2Fblog-posts%2Fthinking-in-gatsby-overview%2Fassets%2Fgatsby_error_20190706_8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Flwz7512%2Fmy-dev.to%2Fmaster%2Fblog-posts%2Fthinking-in-gatsby-overview%2Fassets%2Fgatsby_error_20190706_8.png" alt="gatsby error"&gt;&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;This confused me for a long time, occasionally it popped up and gave you an accidental surprise. It was reported early in issue &lt;a href="https://github.com/gatsbyjs/gatsby/issues/2567" rel="noopener noreferrer"&gt;#2567&lt;/a&gt; on Oct 21, 2017. The solution for that issue ended up with removing &lt;strong&gt;&lt;code&gt;.cache&lt;/code&gt;&lt;/strong&gt; folder. So, each time the error jumped out, I would first stop server by &lt;strong&gt;&lt;code&gt;ctrl+c&lt;/code&gt;&lt;/strong&gt; then execute the following command and refresh page to get it back:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# in Mac OSX enviroment:
$ rm -rf .cache &amp;amp;&amp;amp; gatsby develop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This really works, and is the only approach to eliminate the error so far. The negative impact of this bug to my product is that each time I create tutorial content with generator I must stop server first then create tutorial last execute the command above, lead to a broken user experience.&lt;/p&gt;

&lt;h3&gt;
  
  
  What's the best practice to persuade clients to use it
&lt;/h3&gt;

&lt;p&gt;From a marketing view, how to sell your Gatsby solution to the best fit clients may be a top priority of concern. This topic has a few of articles discussed in &lt;a href="https://www.gatsbyjs.org/blog/2019-03-07-sell-gatsby-to-clients/" rel="noopener noreferrer"&gt;How to Talk about Gatsby to Clients and Your Team&lt;/a&gt; and &lt;a href="https://www.gatsbyjs.org/blog/2019-06-10-how-to-recognize-when-gatsby-is-a-good-fit-for-your-client/" rel="noopener noreferrer"&gt;How To Recognize When Gatsby is a Good Fit for Your Client&lt;/a&gt;, as well as the Gatsby advantages explanation in &lt;a href="https://www.gatsbyjs.org/gatsby-one-pager.pdf" rel="noopener noreferrer"&gt;one page&lt;/a&gt; from its official site.&lt;/p&gt;

&lt;p&gt;The internet world by nature consists of a variety of content, text, image, music, video... To push the boundary of distribution for these media content, as well as web resources html, javascript, css, Gatsby was designed to leverge the most advanced web technologies and the most smart design pattern, also referenced the good practice of other CMS framework: &lt;a href="https://www.gatsbyjs.org/blog/2019-07-03-announcing-stable-release-gatsby-themes/" rel="noopener noreferrer"&gt;themeization&lt;/a&gt; to make it more adaptable, reusable, customizable. Then, when you face your potential clients, how could you persuade your clients willing to invest such a technical upgrade, to bear the risk of system transition, and believe the return on investment?&lt;/p&gt;

&lt;p&gt;Apart from those How tos, I summarized the following viewpoints to improve the Gatsby adoption in clients business:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;leveraging the legacy system content or data by plugin extraction&lt;/li&gt;
&lt;li&gt;resolve the performance bottle neck problem through a Gatsby way&lt;/li&gt;
&lt;li&gt;start with the internal project, minor functionality unit&lt;/li&gt;
&lt;li&gt;introduce to reactjs stack based development team&lt;/li&gt;
&lt;li&gt;progressively adoption and migration little by little&lt;/li&gt;
&lt;li&gt;aim to clients who want to use cloud service and to cut cost in IT infrastructure&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is a short idea list I can think of currently about traditional web system migration to Gatsby. With more and more projects I involved, I believe this list will continue grow. Web technology is evolving constantly with fun and efficiency, that's how Gatsby comes, let's make it clear and lead a better life in partnership with Gatsby.&lt;/p&gt;

</description>
      <category>react</category>
      <category>graphql</category>
      <category>cms</category>
      <category>jamstack</category>
    </item>
  </channel>
</rss>
