Migrating from Pelican to Hugo
Table of Contents
- Goal
- Installing Hugo
- Creating my project
- Create Hugo Site
- Choosing a theme
- Configuring your project and theme
- Content Types, Archetypes and Front Matter
- Creating Content
- Permalinks
- GitHub
- Creating your Amazon AWS S3 bucket
- Moving my domains DNS management to Amazon AWS Route 53
- Creating a User on Amazon AWS to use for deployment
- Automate your deployments with Wercker
- Adding your application to Wercker
- Create and add wercker.yml file
- Adding environment variables for deployment
- Your first deployment
- Conclusion
In this post I will discuss the steps I took to migrate my blog from Pelican to Hugo. In this post I will discuss the steps I took to migrate my blog from Pelican to Hugo. I do all of my development on an Apple Macbook Pro so I used homebrew to install Hugo: Its up to you how you organize your project, but as I am a Go Language developer and Hugo is built using Go I have created a folder for this project here: change directory to this and in terminal run (for the rest of this blog I will assume you are in this directory): This will create a git repository for your project. To create your new Hugo site in terminal run: This will create the skeleton for your new Hugo site. First I headed over to the themes showcase for hugo here: Hugo Themes. This has screenshots and links to demo sites for each theme. I chose hyde-x for my blog. Make a subdirectory called Once this theme repo got cloned into my project I then removed its In the root of your project there is a file called I have decided to have two content types: When creating any kind of content using Hugo you must provide some meta data about it. This meta data is known as For example my You can get Hugo to automatically create the above front matter for you for each content type. These are called Looking at the content of So this will be added to the top of every content of type page that I add. Of course I will have to edit this template for each content with that contents specific meta data. The main difference between my two different content types is that the To create content, from the project root you call: So to create this page I did: So to migrate my blog posts from pelican to hugo I used to above command to create a post with same file name as I had in pelican, copy and pasted the contents of each file from my pelican project to my hugo project. Note that of course I did not copy the front matter of my pelican posts across. Instead I updated the hugo front matter with the same meta data as I had in pelican manually. I repeated this process for my pages too. My permalinks structure for my old pelican based blog was: meaning to access my a post it would have URL like: In hugo I have changed this to: meaning to access my a post it would have URL like: I could have kept it the same so that the URL to my existing content moving from Pelican to Hugo would not change, but I prefered to move forward with it this way. This is a personal choice of course. If you have a look at my For more details on permalinks have a look at the Hugo documentation on permalinks. By this stage I had migrated all my content to hugo and had setup my site. All tested locally. So to get ready for deployment I created a new GitHub repo for it and pushed my code to it: To add github repo I created as my remote: Commit All My work: Merge the remote with my local: Pushed my code to GitHub: I already had an account with Amazon AWS so I signed in and created a S3 bucket: When I created the Of course replace I then moved my domain’s DNS management to Amazon AWS Route 53 service for convenience. I followed the steps in this Amazon document to move my domain’s DNS management. We need to create a user on Amazon AWS to use for deployments to the S3 bucket we created. To do this log into your Amazon AWS console and select Give the new user a name and make note of the access keys for this user that gets generated for you. You will need to create a policy and attach to this user. Here is a sample policy you can use: Of course replace Head over to Wercker website and click sign up and register for an account. Once you have your account, login and go to your settings and click git connections. Here click to connect to your GitHub account. I followed these steps: Once the app was created Wercker gave me the option to trigger a build. Decline it as we have not finished creating our app. In the root of my project I added a new Log back into wercker and go to your application settings. Select AWS_ACCESS_KEY_ID - As provided for the user you created on Amazon AWS AWS_SECRET_ACCESS_KEY - As provided for the user you created on AWS AWS_BUCKET_URL - set this to You are all set now to deploy your hugo website. Commit your changes and push to the GitHub repo you created and your website will be deployed to S3 for you automatically. From now on when ever you make any changes to your site, as soon as you push to your GitHub repo , it will build and deploy your changes to Amazon S3. I am really enjoying using Hugo for my blog and having it deploy automatically when I push a change to GitHub. My workflow is a lot simpler now making it easier for me to write and publish my blogs. You may ask why I moved from the Python based Pelican to Hugo, well I simply wanted to try something new. I think both Pelican and Hugo are great at what they do so you can’t go wrong with either. If I had to choose between them, I would choose Hugo for the more modern approach and excellent documentation. Goal
Original Blog New Blog Static site generator Pelican Hugo Hosting Linode Amazon S3 Deployment Strategy Manual using git Automated using Wercker Source Control bitbucket GitHub Installing Hugo
Creating my project
Create Hugo Site
Choosing a theme
themes
and change directory to it and clone the theme you have chosen there:
.git
directory by changing directory into the themes root folder and removing it:
Configuring your project and theme
config.toml
that you need to update to configure your site. You can look at my configuration to get an idea of the things you can set. For your theme specific settings of course look at the github repo for your theme’s readme for detailsi (e.g. for my chosen theme: hyde-x documentation). Content Types, Archetypes and Front Matter
post
for my blog postspage
for my sites static pages (like my about me page).front matter
.front matter
for this post is:+++
categories = ["python", "golang"]
date = "2015-11-29T07:16:53-05:00"
description = "In this post I will discuss the steps I took to migrate my blog from Pelican to Hugo."
keywords = ["pelican", "hugo", "golang", "go", "python", "blog"]
slug = "migrating-from-pelican-to-hugo"
tags = ["pelican", "hugo", "golang", "go", "python", "blog"]
title = "Migrating from Pelican to Hugo"
+++
archetypes
. If you look at the archetypes
subdirectory of my project there are two archetypes default.md
and page.md
. Any content created that is of type page
will have the contents of page.md
added to its header. Any other content type will have the content of default.md
added to its header.page.md
we have:+++
title = ""
slug = ""
description = ""
menu = "main"
keywords = [""]
categories = [""]
tags = [""]
+++
page.md
content type has menu = "main"
this tells hugo that this content is not a blog post and it should be added to the left column of my website below my name as a link. Creating Content
hugo new <content type>/<name of new content md file>
hugo new post/migrating-from-pelican-to-hugo.md
Permalinks
/blog/<slug>
http://www.softinio.com/blog/<slug>
/post/<slug>
http://www.softinio.com/post/<slug>
config.toml
file you will see under the permalinks
section how I have defined my permalinks. GitHub
Creating your Amazon AWS S3 bucket
www.softinio.com
and set it up for static website hosting by following this Amazon Documentwww.softinio.com
bucket I also clicked properties
and selected the permissions
section. Here I edited the bucket policy and added:
<domain/bucket name>
with your actual bucket name which for me would be www.softinio.com
. Moving my domains DNS management to Amazon AWS Route 53
Creating a User on Amazon AWS to use for deployment
Identity & Access Management
, then select Users
and then select Create New Users
.
<domain/bucket name>
with what you actually called your Amazon S3 bucket name. Automate your deployments with Wercker
Adding your application to Wercker
werker will checkout the code without using an ssh key
) Create and add wercker.yml file
wercker.yml
file for my configuration of wercker: box: debian
build:
steps:
- arjen/hugo-build:
version: "0.14"
theme: hyde-x
config: config.toml
flags: --disableSitemap=false
deploy:
steps:
- s3sync:
source_dir: public/
delete-removed: true
bucket-url: $AWS_BUCKET_URL
key-id: $AWS_ACCESS_KEY_ID
key-secret: $AWS_SECRET_ACCESS_KEY
Adding environment variables for deployment
Targets
and in there add 3 new variables to your deploy pipeline:s3://yourdomain.com
(Note: having the s3://
in front of your domain is very important!) Your first deployment
Conclusion