Pelican + Github Pages 搭建自己的博客
转载请注明来源小小小makerwei
pelican
Pelican是用python写的一套开源的静态网页生成项目,与当前很火的Jekyll很相似。不过作为一个python爱好者,Pelican更加让我喜欢。它评论使用Disqus,支持Markdown格式,支持代码高亮等功能。之前有使用Wordpress搭过blog,但是并没有坚持写下去,现在,我想在这里开始记录我学习的一点一滴。
Installation
virtualenv
可用来用来建立一个虚拟的python环境,一个专属于项目的python环境。
激活环境
pip install virtualenv
virtualenv myblog
cd myblog
source bin/activate
安装Pelican
git clone https://github.com/getpelican/pelican.git
cd pelican
python setup.py install
创建blog
cd path(your blog's path)
pelican-quickstart
在回答一系列的问题后就会自动生成你的blog,主要文件如下:
path/
|-- content
|-- output
|-- Makefile
|-- develop_server.sh
|-- pelicanconf.py
|-- publishconf.py
写一篇文章
为了支持Markdown
,你首先还要通过pip install Markdown
安装相关的包,然后在content目录下新建一个test.md文件,示例内容如下:
Title: My super title
Date: 2010-12-03 10:20
Modified: 2010-12-05 19:30
Category: Python
Tags: pelican, publishing
Slug: my-super-post
Authors: Alexis Metaireau, Conan Doyle
Summary: Short version for index and feeds
This is the content of my super blog post.
然后执行
make html
./develop_server.sh start
这将开启一个测试服务器,可以通过http://localhost:8000
来查看blog的效果
使用Disqus第三方评论
在Disqus上申请一个站点,然后在pelicanconf.py
里添加或修改DISQUS_SITENAME
:
DISQUS_SITENAME = u"你的站点ID"
然后执行
make html
然后刷新http://localhost:8000
可以查看效果
主题
Pelican也有一些主题可以下载,比如本人就用的Flex这个主题。我觉得蛮好看的,不过我觉得Hexo的有些主题更好看。
git clone git://github.com/getpelican/pelican-themes.git
然后将你想要的主题拷贝进你博客项目的目录,然后在pelicanconf.py
文件中修改THEME为Flex
THEME = "Flex"
然后执行
make html
再打开http://localhost:8000
查看效果
使用插件
在博客的目录中执行:
git clone git://github.com/getpelican/pelican-plugins.git
以配置sitemap
为例,在pelicanconf.py
的配置文件里添加以下配置:
SITEMAP = {
'format': 'xml',
'priorities': {
'articles': 1,
'pages': 0.9,
'indexes': 0.8,
},
'changefreqs': {
'indexes': 'daily',
'articles': 'daily',
'pages': 'weekly'
}
}
然后再执行make html
打开http://localhost:8000/sitemap.xml
就可看到生成的Sitemap了。
Github Pages
创建一个新的repository,并将其命名为username.github.io
配置
进入output目录,将生成好的静态HTML文件上传到你的username.github.io
中。
cd output
git init
git remote add origin 远端地址
git add .
git commit -m "first commit"
git push -u origin master
等待一段时间你就可以访问username.github.io
看到网站效果。
若要使用独立域名,则要output当前目录新建一个CNAME
文件,里面写入你的域名(域名的指向等设置请自行查阅资料),然后上传到你的repository里就成功了。
参考
更多的配置请参考官方文档