There are many ways to setup a Github blog, but since I love Python I think it makes sense to use Pelican, which is a Static Site Generator, Powered by Python.
mkdir <blogname>
cd <blogname>
.gitignore
, and add in the content from this file. The .gitignore
file is used to omitted certain dynamic compiled file when commit your changes.Create a file called requirements.txt
in the blog directory with the following content:
Markdown==3.2.1
pelican==3.7.1
jupyter>=1.0
ipython>=4.0
nbconvert>=4.0
beautifulsoup4
ghp-import==0.4.1
matplotlib==1.5.1
Make sure your virtual environment is activated and run pip install -r requirements.txt
in the blog directory to install all of the required packages.
pelican-quickstart
in the blog directory and follow the interactive setup sequence.Enter
key to accept the default values except for the following lines:There are a lot of plugins that are super handy for Pelican, and jupyter plugin is definitely one among them. Follow the steps below to install the plugin:
git init
in the blog foldermkdir plugins
git submodule add git://github.com/danielfrg/pelican-ipynb.git plugins/ipynb
Open pelicanconf.py
and add the following lines:
MARKUP = ('md', 'ipynb')
PLUGIN_PATHS = ['./plugins']
PLUGINS = ['ipynb.markup']
IGNORE_FILES = ['.ipynb_checkpoints']
There is also a github repo that has all the available plugins for Pelican and you can find it here
.ipynb-meta
extension. first-post.ipynb-meta
Title: First Post
Slug: first-post
Date: 2020-04-12 12:12
Category: posts
Tags: python, tutorial, pelican
Author: Carson Z.
Summary: This is my first post!
<username>.github.io
. <username>
with your GitHub username.zmcddn
cd
to the blog directory and run git remote add origin git@github.com:<username>/<username>.github.io.git
SITEURL
in publishconf.py
to http://<username>.github.io
https://zmcddn.github.io
(remember to remove the trailing slash if there is one)<blogname>
folder) and create a theme folder through mkdir theme
cd theme
and git clone --recursive https://github.com/getpelican/pelican-themes pelican-themes
pelicanconf.py
and add this line: THEME = '<path_to_chosen_theme>'
theme/pelican-themes/tuxlite_tbs
Note that once you've chosen your theme, you have to click into the theme page to see how the theme is setup, coz it might need some special configuration and cannot be used directly out of box
cd <blogname>\output
python -m pelican.server
to spin up the serverhttp://localhost:8000/
, then you should see you blogIf you would like to see theme change or how your new article looks like, each time you've changed anything you could run the following steps to see it locally:
cd <blogname>
pelican content -s publishconf.py
to create html filescd output
python -m pelican.server
to spin up the server and you can see it in your browser at http://localhost:8000/
cd <blogname>
pelican content
pelican content -s publishconf.py
ghp-import output -b master
git push origin master
In the future, make sure
and then repeat the 5 steps above to publish new posts.
ghp-import
and command ghp-import output -b master
is used to push static blog pages to the github.io
site so its super easy to setupgit status
in your blog directory, you'll see many uncommitted files since ghp-import
doesn't work exactly the same as git commit
content
folder and once you run pelican content
it will generate static pages and store them in the output
directory, which is used (and pushed) to github.io
for displayAction | Command |
---|---|
Run local | python -m pelican.server in output folder |
create HTML | pelican content |
Setup deployment | pelican content -s publishconf.py |
Setup import for github | ghp-import output -b master |
Push to github | git push origin master |