Creating your site for free in 5 minutes
Tags: go, github, hugo, beginners
Published: 2020-03-01 15:11:32

### Let's create a site in 5 minutes with Hugo

Who never wanted to have a website, curriculum or even a completely customized portfolio, with your face and your own description? Many use Wordpress to achieve these points but end up demanding a server to run or pay for it to work. Here, I will explain how I used [Hugo](https://gohugo.io/) to make this site in less than 5 minutes using, [Github Pages](https://pages.github.com/) and an editor text, in my case [VSCode](https://code.visualstudio.com/).

## Github Pages
In case you don't know [Github](https://github.com/), it is a code control version that uses [Git](https://git-scm.com/) as a system. If you do not know one of the two, I recommend further reading for further study. For now, we will need to install Git on your local machine and create an [Github account](https://github.com)

### Installing Git
To install Git is very simple and you can choose which version you want. Be it [Windows](https://git-scm.com/download/win), [Mac OS X](https://git-scm.com/download/mac) or [Linux](https://git-scm.com/download/linux).

After installing, you will need to perform some basic settings. Open your operating system terminal and run the command below.

``` bash
$ git config --global user.email "me@domain.com"

$ git config --global user.name "Your Name"
```

There, your Git client is set up!


### Creating your Github account
Go to [Github] (https://github.com), click **Sign Up** to create an account.

![signup](https://dev-to-uploads.s3.amazonaws.com/i/28khvgql5cw6g5tozs5a.png)

Then create your account by filling out the form and select the free Github plan.

![form](https://dev-to-uploads.s3.amazonaws.com/i/fylel5hin5hgq6rrfxuc.png)

And ... Shazaam !! Your account is created, but don't close Github now, we will need it soon! :)

## Go
Install [Go](https://golang.org/dl/) on your machine before proceeding. We will need it to install and perform the next step.

## Hugo

Hugo is a [go](https://golang.org) framework designed to create websites using templates, abstracting as much logic as possible. You can create a template and make it available in the community for others to use. Soon, other (very cool) people have already created templates for us to use. If you want to take a look at the options, you can find them by clicking [here] (https://themes.gohugo.io/).

Remember, before installing/running Hugo, you will need to have [go](https://golang.org) installed!

### Starting our website

The first thing we will need to do is create a repository on Github. A repository is a "directory" in the cloud with history and from that history, it is possible to do a lot of things. Then, on your Github homepage, click on the green button in the left corner to create a new repository, like the image below.

![gh-create-repo](https://dev-to-uploads.s3.amazonaws.com/i/rlnpogldy7llygwg4tme.png)
In the form to create a new repository, you * must * create a repository in the format _nomedasuaconta.github.io_, otherwise, it will not work.

![gh-create-repo-pages](https://dev-to-uploads.s3.amazonaws.com/i/tr5j3zvdvtc8uu1hd3t5.png)

You will then be redirected to a page with a tutorial to start modifying your repository.

![gh-create-repo-feedback](https://dev-to-uploads.s3.amazonaws.com/i/eovha80omcfp8kc7atdt.png)

We will use the first example and we will start making our edits with Hugo.

## Using our repository as a website

Now, open the command line of your operating system and run the command

```bash
$ git clone https://github.com/<yourreponame>/<yourreponame>.github.io.git
```

By default, git will ask for your password to access Github. Relax, this is normal. Enter your password and soon you will see that a folder has been created with the name_positure_name_.

Enter that passata and we will begin to perform the magic.

## Installing Hugo

First, we will install Hugo, you will need to have installed [go](https://golang.org) 1.11+ and Git. Those are the only prerequisites. Now run one of these options on your terminal.

#### Mac OS
```bash
$ brew install hugo
```

#### Linux
```bash
$ brew install hugo
```
* If you don't have [Homebrew] (https://docs.brew.sh/Homebrew-on-Linux) installed on Linux, install it first.

#### Windows
```bash
$ choco install hugo -confirm
```
* If you don't have [Chocolatey] (https://chocolatey.org/) installed on Windows, install it first.

## Running Hugo
After the installation has been completed, we will be able to execute the following command in the terminal to create our websites.

```bash
$ hugo new site. --force
```

The _-- force_ argument is necessary because the directory already exists and Hugo confirms that we want to write to that destination folder. After running you should have the following structure:

```bash
$
├── archetypes
│ └── default.md
├── config.toml
├── content
├── date
├── layouts
├── static
└── themes
```

#### Choosing a theme
This is a basic structure of the framework that we don't need to worry about now. Let's choose a theme on the [community page](https://themes.gohugo.io/). I will use the [Cactus theme](https://themes.gohugo.io/cactus/).

At the root of our project, we will execute the two commands below:
```bash
$ cd themes
$ git clone https://github.com/digitalcraftsman/hugo-cactus-theme.git
```

This will make us download the Cactus theme to our repository and we can customize it. Notice that at the root of your project, there is a file called `config.toml`. We will add a line indicating which theme we will be using. The file should look like this:

```bash
baseURL = "http://example.org/" <- change this value to https://<yourreponame.github.io>
languageCode = "en-us"
title = "My New Hugo Site"
theme = "hugo-cactus-theme"
```

Now, we will execute the following command `hugo server` at the root of the project. This will run a local server so that you can see a preview of your site. At the moment, we will only have one example because we haven't changed anything yet. If you access the url: http://localhost:1313 through the browser you will see a page similar to this

![boilerplate](https://dev-to-uploads.s3.amazonaws.com/i/1z245jgk74r5dx6d57x5.png)

Great, now we have something visual! We now need to customize as we prefer to make our website more beautiful. There are many ways to customize the Cactus theme. We can see more details by clicking [here](https://github.com/digitalcraftsman/hugo-cactus-theme).

#### Customizing our theme

The first change we are going to make is to copy to the root of our project, a file called `config.toml` (yes, just like yours) which is in `./themes/exampleSite`. This file already contains many configuration options and there you can change the name, title, description, and others.

We will set up a section together, which is _social_. At the end of the file we will add the following content:
```bash
[social]
    twitter = "https://www.twitter.com/fernandosolivas"
    github = "https://www.github.com/fernandosolivas"
    linkedin = "https://www.linkedin.com/in/fernandosoliva/"
    medium = "https://medium.com/fernandosolivas"
```

And choose a really cool photo to put in the center of the page, you will need to move it to `./themes/static/images/avatar.png`. It must have the same name, otherwise, it will not work.

In the end, we will have something like this.

![cactus-boilerplate-edited](https://dev-to-uploads.s3.amazonaws.com/i/hyln19rvy2qbdon0atel.png)

#### Adding more information

Now, our page is still a little raw, so let's add a page with a description of you. The Hugo framework expects that all created pages will be inside the `<project>/content` folder, so let's create an `about`  folder inside content and a file called `_index.md` inside the new folder created.

```bash
├── archetypes
│ └── default.md
├── config.toml
├── content
│ └── about
│ └── _index.md
...
```

You may not be familiar, but this file suffix `.md` represents a file of type [Markdown](https://en.wikipedia.org/wiki/Markdown) and [here](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) has a list of examples and tips of how to use it.

Let's start by editing the file and adding the following text at the top of the file:

```bash
+++
date = "2015-06-20T14: 02: 37 + 02: 00"
title = "About"
hidden = false
menu = "main"
+++
```

Each item is self-explanatory but let's take a look at them:
- Date: Date of publication of the page
- Title: Title / Page name
- Hidden: Should appear or not in the menu
- Menu: Which menu it should be related to

After that we can only start writing, my `_index.md` file looks like this:

```bash
+++
date = "2015-06-20T14: 02: 37 + 02: 00"
title = "About"
hidden = true
menu = "main"
+++

Software Developer at [Calindra](https://calindra.tech/), Coordinator of [Meetup GopheRio](https://www.meetup.com/pt-BR/GopheRio), volunteer at [Poder do Voto](https : //poderdovoto.org), Founder of [Simbah](https://www.simbahdc.com/), writer in his spare time, father of an amazing girl and husband of the best illustrator in Brazil [link](https://www.instagram.com/aruizilustra/)!

I like to develop in many languages ​​and use each one for its correct purpose. The languages ​​I am most familiar with are: Java, Go, Python, JavaScript (TypeScript).

TDD, Clean Code, CI and CD enthusiast and good development practices.

***

```

#### Making our website available on the internet

Now, back to Git. We will send the changes we made to the files there to the repository we created. For this, we will execute the following commands at the root of the project.

```bash
$ hugo -d.
$ git add *
$ git commit -m "Submitting site with description"
$ git push origin master
```

Now if you access https://yourrepository.github.io you will see your website online, for free and without having to write 1 line of code, only texts.

#### Conclusion

There are some ways to create a website for free without having to write code, like wix.com, WordPress * and others. Hugo is a good tool for those who already program or are starting because it requires little (if any) knowledge in the development and tools to be able to make a website.

Hugo has several amazing themes and easy to use, if you want to try to modify yours, go for it!

I hope you enjoyed the post and send your questions on my twitter.

To the next!