First Post
Here are the basic steps to set up and provision a Pelican blog using Visual Studio Code, Git, a local GitLab instance, GitLab CI/CD, and free hosting on Cloudflare Pages as part of a local GitLab deployment pipeline (how I'm running this blog):
-
Install Visual Studio Code and python extensions... Create a new directory for your blog and navigate to it in the command line:
mkdir myblog && cd myblog
-
python -m venv .venv
(activate it in your workspace when vscode asks / open a new terminal in the venv) pip install pelican Markdown typogrify invoke livereload
-
Initialize the Pelican project by running the following command: pelican-quickstart
This will prompt you to answer a few questions about your blog, such as the title, author, and URL. Fill in the information as prompted. Allow tasks/make to be generated. 4.
pip freeze > requirements.txt
5. Initialize a new git repository:git init
Once the project is initialized, you can create new content by adding Markdown or reStructuredText files to the content directory. I will be using markdown as it seems to play better with code
despite rst being more feature rich.
To generate the HTML for your blog, run the command: pelican content
To preview the generated HTML locally, run the command: pelican --listen
A better alternative to automatically build and hot-reload is invoke livereload
Add, commit and push your code to the local GitLab instance:
git add .
git commit -m "initial commit"
git remote add origin git@your-local-gitlab-instance:group/myblog.git
git push -u origin master
Go to your GitLab instance, navigate to your project and create a new pipeline, this pipeline will generate the static content, deploy it to Cloudflare Pages.
You can use Cloudflare Pages to host your static website for free, you can sign up to Cloudflare and create a new app, then follow their guide to deploy your website.
In your pipeline, you need to configure it to run when changes are pushed to the master branch, it will build the static content using Pelican, then it will deploy it using cloudflare-cli,
You need to configure the pipeline variables to include the credentials for cloudflare and the app id for your website
The pipeline should look like this:
stages:
- build
- deploy
build_job:
stage: build
script:
- pip install pelican Markdown typogrify
- pelican content -s publishconf.py
artifacts:
paths:
- output/
deploy_job:
stage: deploy
script:
- curl -sL https://raw.githubusercontent.com/cloudflare/cloudflare-cli/main/install.sh | sh
- cloudflare login --api-key=$CF_API_KEY
- cloudflare pages deploy -a $CF_APP_ID -p output
Note: This is a very basic setup, it might not suit your needs, you might want to consider using pelican plugins, themes and customizing it to your needs. Please don't be afraid to alter steps for your preferences or use case.