The original article is reprinted from liu Yue’s Technology blog v3u.cn/a_id_81

Go Lang is undoubtedly the current hot chicken, greatly improving the efficiency of back-end programming, while having extremely high performance. With Go language, we can write highly concurrent server software in a synchronous way. Meanwhile, Go language is also the first native language of cloud. Docker, Kubernetes and other famous projects are realized using Go language.

Hugo is a static website generator based on the Go language.

What is a static web site builder? As the name implies, is with the fastest speed to generate a high availability of web page, we know that the Django framework is widely used as a very popular, but it is too much trouble, deployed various command various configuration, dynamic pages are bound to involve database configuration and operation, as long as involving other database operations, You have to consider a number of security factors such as SQL injection. While pure static page do not have this trouble, if we only need a simple site, some simple function and page, such as blogs, we just want to use in the form of a minimalist markdown syntax written text or code, let the server access pure static page, this is a static generator can give us the benefits of the website.

Why Hugo?

Hugo is a static website generator written in go. It is a small CMS system suitable for building personal blog, company homepage, help and other websites. The benefits of static sites are fast, secure, easy to deploy, and easy to manage.

Hugo’s advantages include but are not limited to:

Thanks to Go’s high performance, performance is fast the world’s fastest static website generation tool, 5 seconds to generate 6000 pages of documents for Markdown format, super simple syntax Hugo can do static file generation tool, or high performance Web service; Rich site migration tools, you can easily migrate wordpress, Ghost, Jekyll, DokuWiki, Blogger to Hugo super detailed documentation active community more free content organization rich theme templates, can make your website more colorful

Multi-environment support: MacOS, Linux, Windows

First of all, you can go to the go official website to download the installation package https://golang.org/dl/ and double-click the installation directly. There is no need to configure environment variables, because the installation process is automatically configured. After the installation is complete, open the command line and enter

go version
Copy the code

If the main version number is displayed, the installation is successful

To do Hugo’s online source compilation installation, open the command line and type the following command

go get -u -v github.com/spf13/hugo
go build -o hugo main.go
mv hugo $GOPATH/bin
Copy the code

If you don’t want to compile and install online, you can also go to Hugo’s official website github.com/gohugoio/hu… Download the stable version of the zip package, decompression after the configuration of the environment variables can also be

When the installation is complete, type it on the command line

hugo version
Copy the code

Printing and publishing this number means Hugo has been successfully installed

Enter commands on the command line

hugo new site hugo_blog
Copy the code

I created a new site named hugo_blog, which is very fast, compared to the speed of vue.js creating new sites

Open the config file config.toml, which is the relevant configuration for Hugo’s site, and you can make some personalized customization, as follows:

baseURL = "/"
languageCode = "en-us"
title = "My Blog"
# specify a theme
theme = "hyde"

[params]
# Blog Profile
description = "This is Liu Yue's personal blog"
# Blog theme color
themeColor = "theme-base-08"
Copy the code

You can see that we have a Theme called Hyde, and adding the Theme makes the site more fleshed out and colorful.

More themes can be downloaded from themes.gohugo. IO /, which is free and open source

Go to the Themes directory within the site and type command to download Hyde themes. Hugo has a number of nice themes to choose from

git clone https://github.com/spf13/hyde.git
Copy the code

We have structure and style, we don’t have content yet. Let’s create the first article for the site

Type the command

hugo new one.md
Copy the code

Hugo creates the one.md file under content, and we write some file contents:

---
date: "2019-05-23"
title: "The first article"
---

# # # hello

123123123


Copy the code

print(‘hello world’)


Copy the code

Then enter it on the command line

hugo server
Copy the code

To hot start the project

You can see that a Hugo service has been installed on port 1313

Visit the

So now that you have a very fast and simple blog, how do you deploy it online? Very simple to enter the command to pack:

hugo --baseUrl="/"
Copy the code

Hugo will generate pure static pages for your site and package them into a public folder

Upload public to the root directory of Ali cloud server

Modify the nginx configuration file

vim /etc/nginx/conf.d/default.conf
Copy the code

Listen on port 80 and specify /root/public as the project directory

server {
    listen       80;
    server_name  localhost;

    access_log      /root/md_vue_access.log;
    error_log       /root/md_vue_error.log;


    client_max_body_size 75M;


    location / {

        root /root/public;
        index index.html;

    }
    
    error_log    /root/md_vue/error.log    error;

}
Copy the code

Restart nginx systemctl restart nginx.service and access it

Thanks to Hugo’s speed and efficiency, within three minutes you have a purely static personal blog

The original article is reprinted from liu Yue’s Technology blog v3u.cn/a_id_81