How to deploy your static Pelican website to Netlify

razcodes

Raz

Posted on February 23, 2020

How to deploy your static Pelican website to Netlify

This article was first published on razcodes.dev

In the previous article I talked about creating the static website. Now it's time to deploy it. I started by creating a free account on Netlify.

Domains

One of the first things to consider would be the domain name. You can go with one that is provided by Netlify, or you can register your own. I already had my own domain razcodes.dev that I registered with Google Domains.

I logged into my account and went to Domains in the top menu and added my domain by following the instructions on the screen. I then went back to Google Domains and put in the NS servers provided, under DNS settings.

Back on my machine, I edited the 'publishconf.py' file so the URL matches my domain:

SITEURL = 'https://razcodes.dev'

Source Control

In order to get the website up and running I needed to upload it to either GitHub, Gitlab or Bitbucket. That is where Netlify is going to reach out and pick it up from. I went with GitHub.

Since the website will be rebuilt every time we upload to source control and also because it's good practice, I created the 'requirements.txt' file. With the virtual environment activated:

pip freeze > requirements.txt

In GitHub, I created a new repository, gave it a name, set it to private and clicked the button. What I like here is that even if you are not comfortable with git, on the next page after creation, they give you the instructions on how to get your code in.

I added a '.gitignore' file in my main website folder so I can tell git what not to upload. There is this cool website that helps you create that file if you are not sure what to include called gitignore.io.

Back in the console, in the website folder, I got everything ready:

git init
git add .
git commit -m "first commit"
git remote add origin https://github.com/razcodesdotdev/my-pelican-website.git
git push -u origin master

Creating the site

Back on the Netlify website, under Sites I clicked on New Site from Git. I clicked on GitHub and authorized the connection between the websites as well as pointed to the new repo that I created.

For the Branch to deploy I chose master. Under the build command, I put in the following:

pelican content -s publishconf.py -t theme

For the Publish directory I put in output because that is the folder name where the website gets built.

I clicked Deploy site.

As the website was deploying, I went under Domain settings for the new site and added in my custom domain, as well as provisioned a free SSL certificate from Let's Encrypt. All done automatically by Netlify just by clicking a few buttons. For free.

💖 💪 🙅 🚩
razcodes
Raz

Posted on February 23, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related