3.3 GitHub pages
GitHub pages is a very popular way to host static websites (especially those built with Jekyll), but its advantages are not obvious or appealing compared to Netlify. We recommend you to consider Netlify + Hugo due to these reasons:
Currently GitHub pages does not support HTTPS for custom domain names. HTTPS only works for
*.github.iosubdomains. This limitation does not exist on Netlify. You may read the article “Why HTTPS for Everything?” to know why it is important, and you are encouraged to turn on HTTPS for your website whenever you can.
Redirecting URLs is awkward with GitHub pages but much more straightforward with Netlify.25 This is important especially when you have an old website that you want to migrate to Hugo; some links may be broken, in which case you can easily redirect them with Netlify.
One of the best features of Netlify that is not available with GitHub pages is that Netlify can generate a unique website for preview when a GitHub pull request is submitted to your GitHub repository. This is extremely useful when someone else (or even yourself) proposes changes to your website, since you have a chance to see what the website would look like before you merge the pull request.
Basically Netlify can do everything that GitHub pages can, but there is still one little missing feature, which is closely tied to GitHub itself. That is GitHub Project Pages. This feature allows you to have project websites in separate repositories, e.g., you may have two independent websites
https://username.github.io/proj-b/, corresponding to GitHub repositories
username/proj-b, respectively. However, since you can connect any GitHub repositories with Netlify, and each repository can be associated with a domain or subdomain name, you may replace GitHub Project Pages with different subdomains like
proj-b.netlify.com. The actual limitation is that you cannot use subpaths in the URL but you can use any (sub)domain names.
Although GitHub does not officially support Hugo (only Jekyll is supported), you can actually publish any static HTML files on GitHub pages, even if they are not built with Jekyll. The first requirement of using GitHub pages is that you have to create a GitHub repository named
username.github.io under your account (replace
username with your actual GitHub username), and what’s left is to push your website files to this repository. The comprehensive documentation of GitHub pages is at https://pages.github.com, and please ignore anything related to Jekyll there unless you actually use Jekyll instead of Hugo. To make sure GitHub does not rebuild your website using Jekyll and just publish whatever files you push to the repository, you need to create a (hidden) file named
.nojekyll in the repository.26 GitHub offers a free subdomain
username.github.io, and you can use your own domain name by configuring its A or CNAME records to point it to GitHub pages (consult the GitHub pages documentation for how).
public/ directory should be the GIT repository. You have two possible choices of setting up this repository locally. The first choice is to follow the default structure of a Hugo website like the diagram below, and initialize the GIT repository under the
source/ │ ├── config.toml ├── content/ ├── themes/ ├── ... └── public/ | ├── .git/ ├── .nojekyll ├── index.html ├── about/ └── ...
If you know how to use the command line, change the working directory to
public/, and initialize the GIT repository there:
cd public git init git remote add origin https://github.com/username/username.github.io
The other choice is to clone the GitHub repository you created to the same directory as your website source:
git clone https://github.com/username/username.github.io
And the structure looks like this:
source/ │ ├── config.toml ├── content/ ├── themes/ └── ... username.github.io/ │ ├── .git/ ├── .nojekyll ├── index.html ├── about/ └── ...
The source directory and the
username.github.io directory are under the same parent directory. In this case, you need to set the option
publishDir: "../username.github.io" in
GitHub pages uses a Jekyll plugin to write an
HTTP-REFRESHmeta tag to redirect pages, and Netlify can do pattern-based 301 or 302 redirects, which can notify search engines that certain pages have been moved (permanently or temporarily).↩
You may use the R function
file.create('.nojekyll')to create this file if you do not know how to do this.↩