<?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: Tzook</title>
    <description>The latest articles on Forem by Tzook (@tzookb).</description>
    <link>https://forem.com/tzookb</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%2F200927%2F4a0ee496-b0e1-4386-9e94-68e1b951ddc4.png</url>
      <title>Forem: Tzook</title>
      <link>https://forem.com/tzookb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/tzookb"/>
    <language>en</language>
    <item>
      <title>How I Automated My github Code to Gatsby Posts</title>
      <dc:creator>Tzook</dc:creator>
      <pubDate>Tue, 01 Sep 2020 18:01:34 +0000</pubDate>
      <link>https://forem.com/tzookb/how-i-automated-my-github-code-to-gatsby-posts-3km</link>
      <guid>https://forem.com/tzookb/how-i-automated-my-github-code-to-gatsby-posts-3km</guid>
      <description>&lt;ul&gt;
&lt;li&gt;My previous situation&lt;/li&gt;
&lt;li&gt;Goal&lt;/li&gt;
&lt;li&gt;Action&lt;/li&gt;
&lt;li&gt;Outcome&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  My previous situation
&lt;/h2&gt;

&lt;p&gt;As I moved my blog to Gatsby, I started adding more content to my site.&lt;br&gt;
So "normal" blog posts just like this one, its fine to manually upload as I need to write it down first.&lt;br&gt;
The problem was that I was solving algorithm exercises either on LeetCode, HackerRank or other.&lt;br&gt;
I would upload the code my github repo and then I'll need to go to my blog and write a blog post.&lt;br&gt;
The rate of me solving problems was much faster of me uploading the blog content.&lt;/p&gt;

&lt;h2&gt;
  
  
  Goal
&lt;/h2&gt;

&lt;p&gt;I would like to be able to upload my algorithm solutions, add some readme doc and then it will automatically create a new blog post on my blog.&lt;/p&gt;

&lt;h2&gt;
  
  
  Action
&lt;/h2&gt;

&lt;p&gt;I would first need to decide on a "template" for my readme page, so I'll know how to build the blog post on my site.&lt;br&gt;
After that I altered my Gatsby site, to load my Github repo files. It will look for readme file with a specific template and if&lt;br&gt;
it find those, it will create a blog post with that content.&lt;/p&gt;

&lt;h2&gt;
  
  
  Outcome
&lt;/h2&gt;

&lt;p&gt;Everytime I solve a new exercise and want to have a blog post for it, I just create the readme file.&lt;br&gt;
Push the code and post gets created on my site.&lt;/p&gt;

&lt;h1&gt;
  
  
  Actions Steps on Gatsby
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;add this config to &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;{
  resolve: `gatsby-source-git`,
  options: {
    name: `challenges`,
    remote: `https://github.com/tzookb/programming-challenges.git`,
    patterns: [`exercises/**/*.md`]
  }
},
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;add product creation in &lt;code&gt;gatsby-node.js&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;I wont share all the page creation as its a bit big&lt;/li&gt;
&lt;li&gt;but the relevant Graphql query is this:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  const result = await graphql(`
    {
      allFile(
        filter: { sourceInstanceName: { eq: "challenges" } },
        limit: 10000,
        sort: {order: ASC, fields: [childMdx___frontmatter___date]}
      ) {
        edges {
          node {
            relativePath
            childMarkdownRemark {
              frontmatter {
                title
                url
                desc
                date
                source
              }
              html
            }
          }
        }
      }
  `)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I look up all the files (only readmes, from config)&lt;br&gt;
and take the details I need for creating the post page.&lt;/p&gt;

&lt;p&gt;just go to the home page and look up any LeetCode or HackerRank exercises :)&lt;/p&gt;

&lt;p&gt;Original post on my site:&lt;br&gt;
&lt;a href="https://tzookb.com/how-i-automated-my-github-code-to-gatsby-posts"&gt;Automate Github to Gatsby&lt;/a&gt;&lt;/p&gt;

</description>
      <category>gatsby</category>
      <category>automation</category>
      <category>javascript</category>
      <category>react</category>
    </item>
  </channel>
</rss>
