10.3 Deployment
There are multiple ways to deploy a website, such as using your own web server, GitHub Pages, or Amazon S3. We only mention one in this chapter: Netlify (https://www.netlify.com). It provides both free and paid plans. For personal users, the free plan may be enough, because many useful features have been included in the free plan, e.g., the Hugo support, CDN (content delivery network) for high availability and performance of your website, HTTPS, binding your custom domain, and 301/302 redirects.
Netlify currently supports GitHub, GitLab, and Bitbucket. You may log in using one of these accounts at https://app.netlify.com, and create a new website from your GIT repository that contains the source of your website. Note that you do not need to commit or push the public/
directory in GIT (in fact, I recommend that you ignore this directory in .gitignore
).
When creating a new site on Netlify, you can specify the build command to be hugo
, the publish directory to be public
(unless you changed the setting publishDir
in config.toml
), and also add an environment variable HUGO_VERSION
with a value of a suitable Hugo version (e.g., 0.39
). To find the Hugo version on your local computer, call the function blogdown::hugo_version()
. You may want to use the same Hugo version on Netlify.
Netlify will assign a random subdomain of the form xxx-xxx-1234.netlify.com
to you. You may change it to a meaningful domain name, or request a free *.rbind.io
domain name from https://github.com/rbind/support/issues if you like it.
If possible, I strongly recommend that you enable HTTPS for your websites (why?). HTTPS is free on Netlify, so you really do not have a reason not to enable it.
Once your GIT repository is connected with Netlify, you only need to push source files to the repository in the future, and Netlify will automatically rebuild your website. This is called “continuous deployment.”