Initialization of a Blog Using Pelican and GitLab Pages!
Tue 28 May 2024Introduction¶
We will see in this quick guide how to create a blog using Pelican, which will be hosted on GitLab Pages, offering free hosting and a simple way to deploy a static site.
First, we will need to choose a place to store the blog:
- Blogger from Google is free, with a simple interface, and easy to use. You will be able to store content in the form of text and code.
- Wordpress offers more options for content creators. This option is also very easy to configure. It is free for personal use.
- And finally, Pelican for GitLab Pages, a more advanced option.
We will opt for Pelican for GitLab Pages, a more comprehensive solution.
Using code¶
Let’s start by creating the blog, we will need to install Pelican and create a blog using it.
pip install pelican
pelican-quickstart
This will ask you several questions, like the title, author, description, etc. We will answer them to customize the initial blog setup.
Once this is done, we will be able to generate the site using Pelican:
make html
This will generate the HTML files of the blog in the output folder.
Contribution to the GitLab Git¶
GitLab Pages lets you host a static site from a repository. To do this, we will need to create a GitLab repository and upload the content.
The easiest way is to add the output folder as a new branch of the repository.
git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin git@gitlab.com:<USERNAME>/<REPO_NAME>.git
git push -u origin main
You can then go to the GitLab repository and configure GitLab Pages. It will automatically detect the presence of the index.html file and serve your website.
List of features¶
We will find different features in Pelican:
- content/ # The directory where your content lives
- pelicanconf.py # Configuration file for Pelican
- publishconf.py # Configuration file for Pelican (publication settings)
- makefile # Makefile for generating output
- themes/ # Directory for themes
- output/ # Directory for the output HTML
- content/ # The directory where your content lives
The most important files are:
pelicanconf.pyfor configuring the blog’s settings, including the theme, title, author, and more.publishconf.pyfor configuring the blog’s settings for publication on GitLab Pages.
Add Content to Git¶
GitLab Pages allows you to easily host a static site from a repository. You can use any branch in your repository to host a site. For example, the content of the main branch is used for the https://<USERNAME>.gitlab.io/<REPO_NAME> URL. If you want to create a site on the gh-pages branch, its content will be used for the https://<USERNAME>.gitlab.io/<REPO_NAME>/gh-pages URL.
Theming¶
Pelican is an easy way to host a static site on GitLab Pages. It’s a popular solution for a variety of blog configurations, but it’s not limited to these. You can even install a new theme:
pelican-themes
This command will list all available themes. To use one of them, you simply need to copy the theme folder to the themes directory and modify the pelicanconf.py file to point to the theme.
Adding themes¶
Once you’ve set up the basic Pelican configuration, you can start adding content to your blog. This content is stored in the content/ directory in Markdown files. For example, you can create a new file named content/posts/my-first-post.md.
The structure of the file is quite simple, it just includes the post’s title and the content, which can be formatted using Markdown. You can use this structure for all of your posts.
Adding features¶
You can add many features to your blog, such as:
- Comments: You can use a comment system like Disqus to add comments to your blog posts.
- Analytics: You can use Google Analytics to track traffic to your blog.
- Social media: You can add social media buttons to your blog to allow readers to share your content.
Once you have added all the features you need, you can generate the site and deploy it to GitLab Pages.
Automation¶
It can be repetitive to generate and deploy the site. This can be done automatically with make. There are many automation solutions to do this, like Github actions or Gitlab CI/CD.
Adding domains¶
You can use a custom domain name to host your blog. This can be done by modifying the GitLab Pages settings.
Adding custom content¶
You can add custom content to your blog, such as a portfolio section, a contact page, or an about page. Pelican makes it easy to create new pages.
Conclusion¶
Pelican is a powerful tool for creating static blogs. GitLab Pages provides a simple and free way to host them. By combining these two tools, you can create a beautiful and functional blog in a few hours. You can easily customize it using themes and features.
Cloud Ops Chronicles