<?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: Javier Bauset</title>
    <description>The latest articles on DEV Community by Javier Bauset (@baunes).</description>
    <link>https://dev.to/baunes</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%2F196897%2Fc82d3966-0a8c-4dd7-8be9-b3313cf11ad8.png</url>
      <title>DEV Community: Javier Bauset</title>
      <link>https://dev.to/baunes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/baunes"/>
    <language>en</language>
    <item>
      <title>Deploy a Personal Blog With Hugo and Netlify</title>
      <dc:creator>Javier Bauset</dc:creator>
      <pubDate>Tue, 19 Nov 2019 16:54:10 +0000</pubDate>
      <link>https://dev.to/baunes/deploy-a-personal-blog-with-hugo-and-netlify-2n42</link>
      <guid>https://dev.to/baunes/deploy-a-personal-blog-with-hugo-and-netlify-2n42</guid>
      <description>&lt;p&gt;I've finally decided to start a blog, but I need it simple and under my control. I don't need a lot of features like those offered by CMS, like Wordpress, neither want to give control of my content to a third party.&lt;/p&gt;

&lt;p&gt;That's why I decide to use a &lt;a href="https://jamstack.org/"&gt;JAMstack&lt;/a&gt; with a &lt;a href="https://www.staticgen.com/"&gt;static site generator&lt;/a&gt; like &lt;a href="https://gohugo.io/"&gt;Hugo&lt;/a&gt; and &lt;a href="https://www.netlify.com/"&gt;Netlify&lt;/a&gt; to host the site.&lt;/p&gt;

&lt;p&gt;I've chosen Hugo because it is an option widely extended, has a lot of &lt;a href="https://themes.gohugo.io/"&gt;themes&lt;/a&gt; and I feel confident with &lt;a href="https://golang.org/"&gt;Go&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I've also choose Netlify because I've used it before and is very simple to set up an environment for production with CDN and SSL and auto-deployment.&lt;/p&gt;

&lt;p&gt;Another useful feature of Netlify is that it can auto-deploy every branch in a Git repository so you can work in a draft version of a post in a branch and every time you push the changes you can see the results deployed on Netlify on another URL and no mix changes with the production version of the blog.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a site with Hugo
&lt;/h2&gt;

&lt;p&gt;First of all, we need to create a new Hugo project, for that we can take a look at the &lt;a href="https://gohugo.io/getting-started/quick-start/"&gt;Hugo Quickstart&lt;/a&gt;.&lt;/p&gt;

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

&lt;p&gt;Once we have created a new Hugo project we need to upload it to a Git Repository, Netlify supports &lt;a href="https://github.com/"&gt;GitHub&lt;/a&gt;, &lt;a href="https://about.gitlab.com/"&gt;GitLab&lt;/a&gt; and &lt;a href="https://bitbucket.org"&gt;Bitbucket&lt;/a&gt; out of the box, but in this case, I will use GitHub because I use it in most of my projects but we're free to choose the one we want.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a site with Netlify
&lt;/h2&gt;

&lt;p&gt;When the blog is ready on the Git repository, it's time to create the project in Netlify.&lt;/p&gt;

&lt;p&gt;Assuming we already have an account we need to create a "New site with Git"&lt;/p&gt;

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

&lt;p&gt;After we select the Git account, Netlify will ask for the repository to use.&lt;br&gt;
In case we didn't give access to Netlify to all our repositories, we can now add a new Repository selecting the next option.&lt;/p&gt;

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

&lt;p&gt;Then we can leave the default options and use &lt;em&gt;master&lt;/em&gt; as the branch to deploy.&lt;/p&gt;
&lt;h2&gt;
  
  
  Configuring Netlify
&lt;/h2&gt;

&lt;p&gt;One we have created the project on Netlify, it will be aware of new commits on the master branch and will deploy them automatically.&lt;/p&gt;

&lt;p&gt;Before finishing, we can (and should) configure Netlify options creating a file &lt;a href="https://docs.netlify.com/configure-builds/file-based-configuration/#sample-file"&gt;netlify.toml&lt;/a&gt; in the root directory when we can set several configurations, some important for this project are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="nn"&gt;[build]&lt;/span&gt;
&lt;span class="py"&gt;command&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"hugo"&lt;/span&gt;

&lt;span class="nn"&gt;[context.production.environment]&lt;/span&gt;
&lt;span class="py"&gt;HUGO_VERSION&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"0.59.1"&lt;/span&gt;
&lt;span class="py"&gt;HUGO_ENV&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"production"&lt;/span&gt;

&lt;span class="nn"&gt;[context.branch-deploy.environment]&lt;/span&gt;
&lt;span class="py"&gt;HUGO_VERSION&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"0.59.1"&lt;/span&gt;

&lt;span class="nn"&gt;[context.deploy-preview.environment]&lt;/span&gt;
&lt;span class="py"&gt;HUGO_VERSION&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"0.59.1"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;in which we can specify this is a Hugo project (though Netlify detects it automatically) and the Hugo version.&lt;/p&gt;

&lt;h2&gt;
  
  
  Extra: Stop auto-publishing changes on master and preview new changes
&lt;/h2&gt;

&lt;p&gt;If for any reason we don't want Netlify to auto-deploy the changes, we can lock the current published version and when a new commit occurs, Netlify will not deploy the changes automatically in the production site.&lt;/p&gt;

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

&lt;p&gt;Although Netlify does not deploy the changes to production, they will be available in a preview URL, so we can review them an accept the changes when they ready.&lt;/p&gt;

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

&lt;p&gt;That also can be used when working a new branch and we made a Pull Request to master, every commit &amp;amp; push generate a new preview url where we can see the changes.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;If we want to have control of our content and we don't want to worry about setting up servers, databases ... the combination of &lt;a href="https://gohugo.io/"&gt;Hugo&lt;/a&gt; and &lt;a href="https://www.netlify.com/"&gt;Netlify&lt;/a&gt; is very powerful and can save us a lot of time.&lt;/p&gt;

</description>
      <category>hugo</category>
      <category>netlify</category>
    </item>
  </channel>
</rss>
