Publish a website for free using Hugo and Netlify
The time necessary: An hour!
In this post, I will explain how you can publish an amazing website completely for free using serverless technology called Hugo. Here is the video of me going through it if you are more of a visual learner.
So what is Hugo? Hugo is the fastest growing serverless tech stack for creating amazing websites, it is written in Go, and it makes obvious the fact that for most of the websites you don’t actually need SQL and that is a huge blessing if you are concerned about the cost of the hosting services, which can amount to more than we are willing to pay, especially if your website does not have a huge amount of traffic. If you follow this guide you will be able to create a website completely for free and therefore I think this post could be beneficial for you.
If you want to follow along the link to the GitHub repository will be below. You need to have git installed on your machine for hosting to work, so If you do not have it. Just head over to this URL and download it https://git-scm.com/download/win First of all, you need to install Hugo. Hugo is available on all operating systems and depending on the one you are using you will find instructions on how to install it on the Hugos website. I will presume that most of you are on Windows and therefore here I will post the code necessary for Windows but once you have Hugo installed the process is the same.
Now, when the installation is complete you can then run this command inside CMD to install Hugo
After we install Hugo we are ready to go. Create a folder somewhere, this folder will be the home of your project. Open a cmd and navigate to that folder or open git bash with a right click inside of the folder. Then we create a new Hugo website by running this command, change the example with the name of your site.
You will get a message saying that the site has been successfully created, and that is it for the boilerplate site. Now we will initialize a git repository so that we can use it to publish our site.
After we do this we need to choose a theme for our website because by default Hugo does not come with a theme. You can go to the Hugo website and see all of the available themes there, but I would suggest that you first try „anubis“ and then choose another one, there are almost identical to set up, but if you want to see how it works first then there is nothing wrong with this one. We will add the theme as a submodule to our project. To do this you need to run the next command.
Then we will want to open the folder inside of a text editor, for non C# languages I use Visual Studio Code, and I think you would like it too, but feel free to use whichever one you want. Inside of the text editor open the config.toml and it should like like this
At the end of the file we need to add the next line telling Hugo which theme we want to use
That’s it. We have created Hugo powered website! Congratulations. To see our website inside of the CMD we can run.
And then in your browser you can navigate to http://localhost:1313/ to see it. Your website should appear there. To add a new post to our site we can run the next command.
A new file will be created inside of content/post called hello-world.md. Since Hugo does not use a database those files are our our posts and so by changing them we make changes to the posts themselves The post file should look like this.
Change the draft to false and then say something after the closing „—„ Mine looks like this
Then after we save the file and had back to http://localhost:1313/ we can see our post there. Run this command afterward.
This is just a basic blog, you can of course make your site look and function much better by changing the config.toml and finding more information online on how to add pages, change the design add additional javascript, manage subscriptions, and so on, but for now, let us say that we have done all of that and we want to publish the site for free.
PUBLISHING THE SITE
In order to publish the site, we need to create a GitHub repository. I believe you know how to do this so once you do create it, copy the link to your repository and come back to the cmd and add it to your project folder.
Now we you add a .gitignore file so that our public folder does not get published to GitHub. From your editor of choice create a new file called .gitignore and add the following line there.
To publish the project to GitHub ran the following commands:
Mine is 0.102.3, yours might be different, so change the contents of netlify.toml accordingly.
Also now that the site is active we need to change the baseURL inside of the config.toml to the address of the Netlify app. Change example.com to the address of the app
Every time we change the GitHub repository the site will rebuild. So you can then add posts, set up a domain, and customize your site however you want. I hope you found this useful. If you need some help you can contact me using the social links at the front page. See you in another post.