<?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>DEV Community: Sam Atkinson</title>
    <description>The latest articles on DEV Community by Sam Atkinson (@samba_code).</description>
    <link>https://dev.to/samba_code</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%2F177194%2Fd2f5faaa-7141-40e5-bd45-156c8176be63.jpg</url>
      <title>DEV Community: Sam Atkinson</title>
      <link>https://dev.to/samba_code</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/samba_code"/>
    <language>en</language>
    <item>
      <title>Adding keyboard shortcuts in React</title>
      <dc:creator>Sam Atkinson</dc:creator>
      <pubDate>Wed, 26 Jun 2019 18:06:19 +0000</pubDate>
      <link>https://dev.to/samba_code/adding-keyboard-shortcuts-in-react-4ho4</link>
      <guid>https://dev.to/samba_code/adding-keyboard-shortcuts-in-react-4ho4</guid>
      <description>&lt;p&gt;Keyboard shortcuts are a great feature for your React app. They help power users to get the most from your application, and can greatly reduce the time spent navigating menus and suchlike.  I am currently building a web based markdown editor (because the world definitely need another one of those). I'm aiming for complete minimalism so that when writing it's just the raw text, with a preview pane which shows up when you use a keyboard shortcut.  &lt;/p&gt;

&lt;p&gt;A quick Google threw up &lt;a href="https://github.com/greena13/react-hotkeys"&gt;react-hotkeys&lt;/a&gt; which seemed great for the task. It's super simple to configure and set up.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;keyMap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;PREVIEW&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ctrl+shift+p&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="nx"&gt;handlers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;PREVIEW&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;preview&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;preview&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;

    &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;GlobalHotKeys&lt;/span&gt; &lt;span class="na"&gt;keyMap&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;keyMap&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;handlers&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handlers&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;rest&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;your&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="nx"&gt;here&lt;/span&gt;&lt;span class="p"&gt;....&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;keymap&lt;/strong&gt; is a list of the actions you want to make available (you can make up any name you want for your commands) mapped to the keyboard shortcut you want for it.  &lt;strong&gt;handlers&lt;/strong&gt;_ is an object, mapping the command names to an event handler function.  In the sample I update the preview field in my state, which is used to toggle a className in my app to either display or hide the preview div.&lt;/p&gt;

&lt;p&gt;After dropping this code into my app the shortcut worked first time, &lt;strong&gt;except for when my cursor was in a text area&lt;/strong&gt;.  Given that my app is almost 100% textarea this was a problem!  I discovered that react-hotkeys disables shortcuts from firing from inside textareas and other inputs by default, which makes &lt;br&gt;
 total sense. The standard when building webapps is for shortcuts to be single letters (eg. 'c' will compose a new email in gmail), and if you're typing a message out you don't want it to fire your shortcuts.&lt;/p&gt;

&lt;p&gt;react-hotkeys has a configure method which allows you to modify the defaults.  Placing this configuration in my component makes hotkeys work irrelevant of focus:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;configure&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;ignoreTags&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Simple!&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>What music are you coding to? </title>
      <dc:creator>Sam Atkinson</dc:creator>
      <pubDate>Wed, 19 Jun 2019 14:44:12 +0000</pubDate>
      <link>https://dev.to/samba_code/what-music-are-you-coding-to-2c7n</link>
      <guid>https://dev.to/samba_code/what-music-are-you-coding-to-2c7n</guid>
      <description>&lt;p&gt;Leaving aside the debate about whether you should have headphones on or make yourself approachable, what music have you been listening to this week (or in general) to get into Flow? &lt;/p&gt;

&lt;p&gt;I'm a huge fan of The American Dollar, in particular 'music for focus and creativity' and 'music for chilling out'.&lt;/p&gt;

&lt;p&gt;There's  a great album by Eluvium called 'False readings on' too. They also have an album called 'shuffle drones' for when you just need some white noise.&lt;/p&gt;

&lt;p&gt;Also love the 'Deep Focus' play list on Spotify.&lt;/p&gt;

&lt;p&gt;On the heavier side I'm loving the new architects album for when I'm in a furious mood post meetings :) &lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Nested Ternary statements in React JSX</title>
      <dc:creator>Sam Atkinson</dc:creator>
      <pubDate>Tue, 18 Jun 2019 07:39:29 +0000</pubDate>
      <link>https://dev.to/samba_code/nested-ternary-statements-in-react-jsx-35kp</link>
      <guid>https://dev.to/samba_code/nested-ternary-statements-in-react-jsx-35kp</guid>
      <description>&lt;p&gt;After discovering our ESLinter hasn't been running for &lt;em&gt;some time&lt;/em&gt; I've spent most of today going through trying to fix a whole bunch of eslint and a11y issues in our React app.  I hit quite an interesting one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/*eslint no-nested-ternary: "error"*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Which basically means, don't do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;dislikeCoke&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fanta&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;likesCherry&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cherryCoke&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dietCoke&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Which I think in general everyone can get behind as a rule.  It's not readable code, even when split over multiple lines with indentations, and should be broken out into if statements.&lt;/p&gt;

&lt;p&gt;However, this is a very common pattern in React where we can use ternary statements to do conditional rendering in a component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Data Loader!&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;loading&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; 
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;It is Loading.&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; 
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;:&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;There was no result!&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; 
        &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;(This is a very contrived example).&lt;/p&gt;

&lt;p&gt;I poked around on the internet for a while and the best alternative I've found to this is to extract the second part of the ternary into a stateless functional component.  The component can still live in the same file so it's still quick and easy to comprehend, and I found it to be a nice way to encapsulate the UI code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;DataDisplay&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; 
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;:&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;There was no result!&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; 

          &lt;span class="p"&gt;...&lt;/span&gt;

          &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;loading&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; 
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;It is Loading.&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;DataDisplay&lt;/span&gt; &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Full example codepen below:&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/samberic/embed/JQKbMd?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>eslint</category>
      <category>codepen</category>
    </item>
    <item>
      <title>Tips to start speaking at conferences?</title>
      <dc:creator>Sam Atkinson</dc:creator>
      <pubDate>Sat, 15 Jun 2019 07:58:58 +0000</pubDate>
      <link>https://dev.to/samba_code/tips-to-start-speaking-at-conferences-56p6</link>
      <guid>https://dev.to/samba_code/tips-to-start-speaking-at-conferences-56p6</guid>
      <description>&lt;p&gt;So I was lucky enough to talk at RedHat DevNation in SF a few years back, and although they bungled the audio on the recording overall I had a great experience.&lt;/p&gt;

&lt;p&gt;This week I attended The Lead Dev conference in London and it was awesome and really inspired me to have another crack at conference speaking.  I'm a confident public speaker and so I'm not worried about the talk itself.&lt;/p&gt;

&lt;p&gt;I was hoping the community would have some hints and tips on finding speaking and panel opportunities? Last time I just googled around to find relevant conferences that had a CFP open.  Surely there's something better?  Is there a site somewhere that lists all the CFPs that are currently open?&lt;/p&gt;

&lt;p&gt;And a bit of a stretch, does anyone who's been asked to speak (e.g. direct request as opposed to CFP) have any tips on what they've been doing (social media, blogging etc) to get a profile so conferences come to you.&lt;/p&gt;

&lt;p&gt;Thanks in advance :)&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>career</category>
    </item>
    <item>
      <title>Migrating a blog from Wordpress to Jekyll</title>
      <dc:creator>Sam Atkinson</dc:creator>
      <pubDate>Thu, 13 Jun 2019 21:09:07 +0000</pubDate>
      <link>https://dev.to/samba_code/migrating-a-blog-from-wordpress-to-jekyll-4flk</link>
      <guid>https://dev.to/samba_code/migrating-a-blog-from-wordpress-to-jekyll-4flk</guid>
      <description>&lt;p&gt;So I've decided it's time to start writing again.  As a result since taking this decision I've done everything I can to procrastinate and avoid writing.  The bulk of this time has been to move my blog from self hosted Wordpress over to Jekyll on GitHub pages.&lt;/p&gt;

&lt;h2&gt;
  
  
  A quick word on the why
&lt;/h2&gt;

&lt;p&gt;Wordpress is a very capable platform with huge support and tons of plugins and themes.  I would absolutely recommend it to anyone starting out who just wants to get a blog up and going.&lt;/p&gt;

&lt;p&gt;It is however big, slow and cumbersome.  An absurd amount of the web is powered by Wordpress and so it has to be all things to all people and it's gotten bulky.  My blog is a collection of maybe 30 pages that aren't going to change once they're up.  &lt;/p&gt;

&lt;p&gt;Google has a nice tool which assesses the speed of your site and a bunch of other metrics. My site was not scoring well.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RK_3JAnw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/l73bw6eydewwjarctd7c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RK_3JAnw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/l73bw6eydewwjarctd7c.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x8TPoLub--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/4hkyh31tci3ovlfvd5vq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x8TPoLub--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/4hkyh31tci3ovlfvd5vq.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'd also been hearing a lot about people using a tool called Gatsby to make their blog, which if I'm honest is what started me down this rabbit hole.&lt;/p&gt;
&lt;h3&gt;
  
  
  So why not Gatsby?
&lt;/h3&gt;

&lt;p&gt;I get that a static site generator is going to require some technical know how and a bit more work, but after even a light look into the world of Gatsby it strikes me as huge overkill for my little blog.  I just wanted to run some commands and have a static blog locally, then tweak it a bit and push.  Every "Getting started with Gatsby" article seemed to involve a small novel to get going.  I'm sure it's great, but I just wasn't willing to put the effort in.&lt;/p&gt;

&lt;p&gt;The other major advantage of Jekyll is that it is natively supported (encouraged even) for GitHub Pages.  This means now all I need to do is commit my posts to GitHub and it's auto built and deployed to my site.  Added bonus: it comes with HTTPS out the box.&lt;/p&gt;
&lt;h2&gt;
  
  
  Ok, so what is Jekyll?
&lt;/h2&gt;

&lt;p&gt;It's a static site generator.  You write your posts/pages in markdown (actual .md files!), and it smushes them up with some templates and spits out a super fast static website.  You can configure the site and templates as you wish (change the templates, content, css, add javascript, whatever you like).  It's written in Ruby (boo) but you don't need to know any to use it so that's a plus.&lt;/p&gt;
&lt;h2&gt;
  
  
  Where to start
&lt;/h2&gt;

&lt;p&gt;So first things first; this has already been done before and blogged.  I found &lt;a href="https://girliemac.com/blog/2013/12/27/wordpress-to-jekyll/"&gt;this post&lt;/a&gt; and &lt;a href="https://blog.webjeda.com/wordpress-to-jekyll-migration/"&gt;this post&lt;/a&gt; particularly useful.  However I hit issues which neither covered, and I figured it can't hurt to have another post.&lt;/p&gt;

&lt;p&gt;Caveat emptor: I'm on a mac.&lt;/p&gt;

&lt;p&gt;First things first, you need to upgrade your Ruby version to something about 2.6.X.  On a Mac to do this you need to install RVM.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
\curl -sSL https://get.rvm.io | bash -s stable

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now you have RVM you can upgrade Ruby.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rvm install ruby-2.6.3

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Hopefully your Ruby version is now up to scratch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(base) Sams-MacBook-Pro:sam sam$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now we can install Jekyll itself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gem install jekyll-importer
gem install jekyll-import
gem install jekyll bundler

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Navigate to wherever you store your code, and we'll create a new jekyll project.  Use your site name; if you've got your own domain, name it that.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;jekyll new yourdomain.io
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You'll have a new folder called yourname.io with your site in. cd into it.  We can now run this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bundle exec jekyll serve
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This magic command hosts your site locally at localhost:4000 and allows you to see your wonderful site.  Obviously it's a little raw, but let's get it up onto GitHub then we'll start customising it.&lt;/p&gt;

&lt;h3&gt;
  
  
  To GitHub!
&lt;/h3&gt;

&lt;p&gt;GitHub allows you one pages site per user account (you can have them for all your subprojects etc., but only one for your top level GitHub user).  You need to create a repo which is .github.io.  For me, that was samberic.github.io.&lt;/p&gt;

&lt;p&gt;On your local project, set it up as a git project and push to your new repo&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git init
git add *
git commit -m "initial commit"
-- follow instructions on github to add remote and push.

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Hopefully you can now got to  settings &amp;gt; GitHub Pages, and you'll hopefully see some sort of useful error message.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Customising your theme
&lt;/h3&gt;

&lt;p&gt;What really isn't obvious when you install Jekyll is how to customise it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--w92efPUT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/stb9gzsscqylrxvd3x2g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--w92efPUT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/stb9gzsscqylrxvd3x2g.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are no HTML files? How do you change this? Such confuse!&lt;/p&gt;

&lt;p&gt;Turns out that themes are bundled in gem files.  You can read the full doc-o's on the &lt;a href="https://jekyllrb.com/docs/themes/"&gt;jekyll site&lt;/a&gt;, but basically you need to find where the files are on your file system and copy them in if you want to edit them.  I think this is a valiant attempt to allow you to keep up to date with theme changes upstream, but in reality most people are going to want to customise the heck out of their themes so seems a bit pointless not exploding it locally by default.&lt;/p&gt;

&lt;p&gt;Find the name of your theme in config.yml; at the time of writing the default is "minima". On a mac, run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;open $(bundle show minima)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And all the juicy files will be revealed.  _layouts are the layouts of the various page types (the most pertinent to blogs are "post.html") and _includes are reusable html fragments across the layouts.  copy the same folder structure and files into your project and they will overwrite by default.  At a very minimum you're going to need to copy post.html across so we can add comments later on.&lt;/p&gt;

&lt;p&gt;You may want to go with a whole different theme. These can be found at RubyGems at &lt;a href="https://rubygems.org/search?utf8=%E2%9C%93&amp;amp;query=jekyll-theme"&gt;this link&lt;/a&gt;, but has the downside of no top level previews so it's a bit of a fuss trying to get one you like, although there are more direct demo links from &lt;a href="https://github.com/planetjekyll/awesome-jekyll-themes"&gt;this GitHub&lt;/a&gt;.  If you like a theme, just change the theme name in your config.yml and jekyll will handle the rest.&lt;/p&gt;

&lt;p&gt;Whenever you change your theme you need to do the whole customisation thing again though.&lt;/p&gt;

&lt;h3&gt;
  
  
  Exporting old content from Wordpress
&lt;/h3&gt;

&lt;p&gt;I was expecting this to be a nightmare but it turned out to be simple.  There's a great plugin called &lt;a href="https://ben.balter.com/wordpress-to-jekyll-exporter/"&gt;wordpress-to-jekyll-exporter&lt;/a&gt; which does just that- it takes all your posts and spits them out into jekyll suitable files.  It will put them in a Zip.  Simply unzip this, and copy all your posts out into the _posts directory of your theme.&lt;/p&gt;

&lt;p&gt;If you refresh your page locally you should now have your entire Wordpress blog locally in a jekyll site.&lt;/p&gt;

&lt;p&gt;Small note: I got hit with errors because my old posts contained curly braces from code.  Where this is the case you need to wrap the whole thing in a raw tag&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

 {{ "{% raw " }}%}
{ your code here }
 {{ "{% endraw " }}%} 


&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Setting up comments
&lt;/h3&gt;

&lt;p&gt;I'm going to assume you're already on the disqus comments system.  If not, sign up for Disqus (it's a really great comments engine) and follow &lt;a href="https://help.disqus.com/articles/1717131-importing-comments-from-wordpress"&gt;their guide&lt;/a&gt; on how to do it.&lt;/p&gt;

&lt;p&gt;Assuming you're already on disqus, you just need to paste the &lt;a href="http://docs.disqus.com/developers/universal/"&gt;Disqus universal code&lt;/a&gt; into your post.html wherever you want your comments to show.  Make sure you've selected in Disqus the correct site if you've got multiple sites! I got thrown for a loop because Disqus got confused by my account and gave me a busted universal code.  Ensure that whatever is under the src part resembles your blog name in disqus!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;s.src = 'https://sambastuff.disqus.com/embed.js'; # Make sure this line looks like your site!

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Important point to note&lt;/em&gt;: Locally you won't see any comments. I think that's because Disqus checks its being served up from the correct site it was set up as.  This means you're going to need to push up to GitHub to see it work.  Also, presuming like me you have a custom domain, you need to point your custom domain at GitHub pages and put your url in the GitHub pages settings for them to show up.&lt;/p&gt;

&lt;p&gt;I think that's everything; if you hit issues drop a comment and I'll try and help!&lt;/p&gt;

</description>
      <category>jekyll</category>
      <category>productivity</category>
      <category>tutorial</category>
      <category>githubpages</category>
    </item>
  </channel>
</rss>
