<?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: When Shit Breaks</title>
    <description>The latest articles on DEV Community by When Shit Breaks (@whenshitbreaks).</description>
    <link>https://dev.to/whenshitbreaks</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%2F785383%2Faab3b6e3-836a-4582-a643-f53c3887a0ac.png</url>
      <title>DEV Community: When Shit Breaks</title>
      <link>https://dev.to/whenshitbreaks</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/whenshitbreaks"/>
    <language>en</language>
    <item>
      <title>How to Change the Favicon in Gatsby</title>
      <dc:creator>When Shit Breaks</dc:creator>
      <pubDate>Sun, 10 Apr 2022 19:51:06 +0000</pubDate>
      <link>https://dev.to/whenshitbreaks/how-to-change-the-favicon-in-gatsby-25kf</link>
      <guid>https://dev.to/whenshitbreaks/how-to-change-the-favicon-in-gatsby-25kf</guid>
      <description>&lt;p&gt;&lt;em&gt;PHOTO CREDIT: &lt;a href="https://www.seobility.net/en/wiki/Favicon"&gt;Figure: Favicon, Author: Seobility - License: CC BY-SA 4.0&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;In this tutorial, if you don't know what a favicon is, it's briefly described, and then I go step by step on how you can change the favicon in your Gatsby project to something else, instead of the default Gatsby icon.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is a Favicon?
&lt;/h2&gt;

&lt;p&gt;Here is a great explanation of what a favicon is from the &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Favicon"&gt;MDN web docs&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A favicon (favorite icon) is a tiny icon included along with a website, which is displayed in places like the browser's address bar, page tabs and bookmarks menu.&lt;/p&gt;

&lt;p&gt;Usually, a favicon is 16 x 16 pixels in size and stored in the GIF, PNG, or ICO file format.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://whenshitbreaks.com"&gt;On our blog&lt;/a&gt;, you'll see that the favicon is a piece of a shit💩&lt;/p&gt;




&lt;h2&gt;
  
  
  How to Change the Favicon
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Steps
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Install the plugin &lt;code&gt;gatsby-plugin-manifest&lt;/code&gt; if it's not installed already.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// shell
npm install gatsby-plugin-manifest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you had set up Gatsby with any of the starter packs, e.g. &lt;code&gt;gatsby-starter-default&lt;/code&gt;, &lt;code&gt;gatsby-starter-blog&lt;/code&gt;, then this plugin is most likely already installed. Otherwise, if you initialized your Gatsby project with the command &lt;code&gt;npm init gatsby&lt;/code&gt;, selecting the option to generate a manifest file will have installed this plugin. You can check if the plugin is installed via &lt;code&gt;package.json&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Add your favicon to the assets / images folder.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By default, this is the &lt;code&gt;src/images&lt;/code&gt; folder (at least in Gatsby v4.3.0), and this is where you'll find the default Gatsby icon (&lt;code&gt;src/images/icon.png&lt;/code&gt;). This may differ depending on your project setup and preferences.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Configure the plugin in your &lt;code&gt;gatsby-config.js&lt;/code&gt; file.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Change the file path for &lt;code&gt;options.icon&lt;/code&gt; to where your favicon is from Step 2.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// gatsby-config.js
module.exports = {
  // ...siteMetaData
  plugins: [
    {
      resolve: 'gatsby-plugin-manifest',
      options: {
        "icon": "src/images/icon.png"
      }
    },
    // ...other plugins
  ];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. (Re)Run &lt;code&gt;gatsby develop&lt;/code&gt; to see the favicon for your Gatsby app.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;And that's it! Pretty simple shit, right?&lt;/p&gt;




&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Favicon"&gt;MDN Web Docs Glossary: Definitions of Web-Related Terms &amp;gt; Favicon&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.gatsbyjs.com/docs/how-to/performance/add-a-manifest-file/#using-gatsby-plugin-manifest"&gt;Using gatsby-plugin-manifest&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>gatsby</category>
      <category>favicon</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Adding Google reCAPTCHA to Getform on Gatsby</title>
      <dc:creator>When Shit Breaks</dc:creator>
      <pubDate>Sun, 27 Feb 2022 15:34:52 +0000</pubDate>
      <link>https://dev.to/whenshitbreaks/adding-google-recaptcha-to-getform-on-gatsby-mdc</link>
      <guid>https://dev.to/whenshitbreaks/adding-google-recaptcha-to-getform-on-gatsby-mdc</guid>
      <description>&lt;p&gt;For static websites, such as those on Gatsby, when handling form submissions, you either need a server to use a third-party form service. The &lt;a href="https://www.gatsbyjs.com/docs/building-a-contact-form"&gt;Gatsby docs do a pretty good job in explaining how to build a contact form&lt;/a&gt; and it provides options for form submissions. I'm going to assume that you already have your html form set up, you're using &lt;a href="https://getform.io"&gt;Getform&lt;/a&gt; for it, and now you're here because you need to add Google reCAPTCHA.&lt;/p&gt;

&lt;p&gt;If you were like me, it was pretty straightforward and easy in setting up a contact form with Getform on a Gatsby website. However, within days, I was already receiving spam. Looks like the Akismet spam filtering wasn't able to filter these ones out, and it was time to implement Google reCAPTCHA.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Gs8mAp-j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/16iau8ym77cm8wm3zrv2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Gs8mAp-j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/16iau8ym77cm8wm3zrv2.png" alt="Screenshot of form spam" width="880" height="659"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  How to add Google reCAPTCHA
&lt;/h2&gt;

&lt;p&gt;The below instructions are for Google reCAPTCHA v2.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://www.gatsbyjs.com/docs/building-a-contact-form"&gt;Set up html form on your Gatsby website&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.getform.io/installations"&gt;Set up Getform and add endpoint to html form&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Steps
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Get API keys for Google reCAPTCHA.&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to &lt;a href="https://www.google.com/recaptcha"&gt;Google reCAPTCHA&lt;/a&gt; and click on "Admin Console".&lt;/li&gt;
&lt;li&gt;Create (+) to register a new site and select v2 with the "I'm not a robot" checkbox.&lt;/li&gt;
&lt;li&gt;Add your domain, along with &lt;code&gt;localhost&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Accept the terms and submit.&lt;/li&gt;
&lt;li&gt;Save the site key and secret key somewhere safe.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bhotPf9v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8oushju99clueiogsvyu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bhotPf9v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8oushju99clueiogsvyu.png" alt="Screenshot of how to set up Google reCAPTCHA v2" width="880" height="784"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Install the &lt;code&gt;gatsby-plugin-recaptcha&lt;/code&gt; plugin and add it to your gatsby-config.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   // console
   npm install --save gatsby-plugin-recaptcha
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   // gatsby-config.js
   plugins: [`gatsby-plugin-recaptcha`];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will inject the script for the reCAPTCHA library between the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; tags.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. (optional) Add the site key as an environment variable to &lt;code&gt;.env.development&lt;/code&gt; and to your CI/CD.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Since it's the site key, this step doesn't matter too much, but I did so for maintainability and management purposes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Add the reCAPTCHA element with the site key to your html form between the &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt; tags.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   // pages/contact.tsx
   &amp;lt;div class="g-recaptcha" data-sitekey="YOUR reCAPTCHA SITE KEY" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you had the site key as an environment variable, it would look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   // pages/contact.tsx
   &amp;lt;div
     class="g-recaptcha"
     data-sitekey={process.env.GATSBY_GOOGLE_RECAPTCHA_SITE_KEY}
   /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I added the element just before my buttons for clearing and submitting the form, as it will be displayed like this:&lt;br&gt;
   &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Bfl0Oxro--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5x4x5fof1r3iw6kmtida.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Bfl0Oxro--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5x4x5fof1r3iw6kmtida.png" alt="Google reCAPTCHA v2 input element" width="616" height="164"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Add the secret key to your Getform endpoint.&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to &lt;a href="https://getform.io"&gt;Getform&lt;/a&gt; and click on the form endpoint under "All" on the left sidebar.&lt;/li&gt;
&lt;li&gt;Click on the lighting bolt icon at the top right for "Automation" settings.&lt;/li&gt;
&lt;li&gt;Add the action "Secure endpoint with Google reCAPTCHA".&lt;/li&gt;
&lt;li&gt;Add the secret key and click "Complete".&lt;/li&gt;
&lt;li&gt;Click on "Save" at the top right to save your form settings.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;6. Run &lt;code&gt;gatsby develop&lt;/code&gt; if it's not running already, and you should now see the reCAPTCHA element appear on your form.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now I can look forward to getting messages from real visitors!&lt;/p&gt;

</description>
      <category>gatsby</category>
      <category>getform</category>
      <category>googlerecaptcha</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
