How to Create Site With Hugo

Install hugo on Centos7

Add epel repo

The Hugo package can be found at https://copr.fedorainfracloud.org/coprs/daftaupe/hugo/, take the correct version, and place it in /etc/yum.repos.d/hugo.repo

vim /etc/yum.repos.d/hugo.repo 

# add content below the file
[copr:copr.fedorainfracloud.org:daftaupe:hugo]
name=Copr repo for hugo owned by daftaupe
baseurl=https://download.copr.fedorainfracloud.org/results/daftaupe/hugo/epel-7-$basearch/
type=rpm-md
skip_if_unavailable=True
gpgcheck=1
gpgkey=https://download.copr.fedorainfracloud.org/results/daftaupe/hugo/pubkey.gpg
repo_gpgcheck=0
enabled=1
enabled_metadata=1

Install

yum -y install hugo
hugo version

Quick start

# Create a new site 
hugo new site mysite

# Add a Theme
cd mysite
git init
git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/ananke

echo theme = \"ananke\" >> config.toml

# Add a new page 
hugo new post/my-test-post.md

Run the server locally

hugo server -D --watch --verbose  -p 8080

Deploy to S3 Bucket

  • AWS CLI has been installed and with AWS access key and token configured in the deployment machine
  • In the config.toml file, we need to provide S3 bucket details
[deployment]
[[deployment.targets]]
name = "mydeployment"
URL = "s3://[your s3 bucket name]]?region=[region]}"

The run the command below to build and deploy the site to S3

rm -rf public && hugo && hugo deploy

Convert Wordpress to Hugo

  • Go to Wordpress to hugo exporter, and download it as zip file
  • Log into wordpress site, and upload the zip file as plugin
  • go to Tools-> Export to Hugo
  • if the ui doesn’t work, try command line
ssh root@your.server
sudo apt-get install php7.2-zip  # Need to make sure php zip insalled, this command is for an ubuntu box
cd /var/www/html/wp-content/plugins/wordpress-to-hugo-exporter-master/
php hugo-export-cli.php
# a wp-hugo.zip will be created, unzip and place it under content folder of the Hugo site

Reference