This article mainly introduces how to use Pelican to build a blog on GitHubPages. Pelican is an open-source blog system implemented using Python. For more information, see
Introduction to Pelican
First, let's take a look at some of the main features of Pelican:
- Python implementation, open source code
- Outputs static pages to facilitate hosting
- Supports topics and uses the Jajin2 template engine.
- Supports code syntax highlighting
- Supports reStructuredText, Markdown, and AsciiDoc formats
- Support Disqus comments
- Support Atom and RSS output
These features are all in love and fully satisfy my basic needs for blog systems. with free and unrestricted GitHub Pages, everything is almost perfect.
Install Pelican
Install the Python environment by yourself and support 2.7.X and 3.3 +. for convenience, install distribute, pip, and virtualenv. (Note: my operating system is Windows 7)
Create a Pelican virtual environment
virtualenv PelicanEnv --distributePelicanEnv\Scripts\activate
Install Pelican
pip install pelican
If you use Markdown to write articles, you also need to install the Markdown library
pip install Markdown
Create a Blog
Create a Blog Directory
mkdir myblogcd myblog
Quick Blog creation
pelican-quickstart
Follow the prompts to enter the corresponding configuration items step by step and do not know how to set to accept the default settings. you can change the configuration by editing the pelicanconf. py file.
The generated directory structure is as follows:
The code is as follows:
Myblog/
── Content # store the input source file
│ ── (Pages) # store manually created static pages
── Output # generated output file
── Develop_server.sh # enable the test server
├ ── Makefile # convenient management of blog Makefile
── Pelicanconf. py # Main configuration file
── Publishconf. py # configuration file used for publishing
Write an article
Write an article using Markdown syntax in the content directory
The code is as follows:
Title: My super title
Date:
Category: Python
Tags: pelican, publishing
Slug: my-super-post
Author: Alexis Metaireau
Summary: Short version for index and feeds
This is the content of my super blog post.
Generate page
make html
Now you can view the generated html file in the output directory.
Since my operating system is Windows, I made some modifications to Makefile.
PY=pythonPELICAN=pelicanPELICANOPTS=BASEDIR=$(CURDIR)INPUTDIR=$(BASEDIR)/contentOUTPUTDIR=$(BASEDIR)/outputGITHUBDIR=$(BASEDIR)/togithubCONFFILE=$(BASEDIR)/pelicanconf.pyPUBLISHCONF=$(BASEDIR)/publishconf.pyhelp: @echo ' ' @echo 'Makefile for a pelican Web site ' @echo ' ' @echo 'Usage: ' @echo ' make help print help information ' @echo ' make all (re)generate the web site ' @echo ' make html (re)generate the web site ' @echo ' make clean remove the generated files ' @echo ' make cptogithub copy output files to GITHUBDIR ' @echo ' make regenerate regenerate files upon modification ' @echo ' make serve serve site at http://localhost:8000' @echo ' make devserver start/restart develop_server.sh ' @echo ' make stopserver stop local server ' @echo ' make publish generate using production settings ' @echo ' 'all: htmlhtml: clean $(OUTPUTDIR)/index.html cptogithubclean: @echo -n 'Cleaning............................' @rm -fr $(OUTPUTDIR) @mkdir $(OUTPUTDIR) @echo 'Done'$(OUTPUTDIR)/%.html: $(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)cptogithub: @echo -n 'Copying.............................' @cp -fR $(OUTPUTDIR)/* $(GITHUBDIR) @echo 'Done'regenerate: clean $(PELICAN) -r $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)serve: cd $(OUTPUTDIR) && $(PY) -m pelican.serverdevserver: $(BASEDIR)/develop_server.sh restartstopserver: kill -9 `cat pelican.pid` kill -9 `cat srv.pid` @echo 'Stopped Pelican and SimpleHTTPServer processes running in background.'publish: $(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(PUBLISHCONF) $(PELICANOPTS).PHONY: help all html clean cptogithub regenerate serve devserver stopserver publish
Create GitHub Pages
GitHub Pages can be divided into two types: project Pages, which can be created multiple times; user Pages, where each user ID can be created only one. Both of them can be used to host the Pelican blog. Here we take the user page as an example.
Click here to create a Repository. the Repository name can be xxx. github. io or xxx.github.com, where xxx is your user ID.
After the creation is successful, you can push the generated page to github.
cd outputgit initgit add .git commit -m "first commit"git remote add origin https://github.com/xxx/xxx.github.io.gitgit push -u origin master
Now you can access your blog through xxx. github. io or xxx.github.com.
Domain name binding
In the root directory of the repo, create a text file named CNAME, which is written into the domain name you want to bind, such as the top-level domain name example.com or the second-level domain name xxx.example.com.
If A top-level domain name is bound, DNS creates A new A record pointing to 204.232.175.78.
If a second-level domain name is bound, DNS creates a CNAME record pointing to xxx. github. io or xxx.github.com.
Take my example:
CNAME file
Www.dongxf.com
DNSPod settings
Enter the following link in the browser address bar to jump to the http://www.dongxf.com/
Http://dongxf.com/
Http://www.dongxf.com/
Http://blog.dongxf.com/
Http://dongdxf.github.io/
Http://dongdxf.github.com/
Unfinished matters
For more information, see the official Pelican documentation. I am translating this document. it's just getting started and the process is slow. Click the Chinese version of the Pelican document to visit. You are welcome to provide valuable comments and suggestions.