手把手搭建基于pelican的博客环境

Date:
Categories: pelican
Author: sysublackbear
Tags: ,

下面说一下我是如何搭建这个博客的,这个博客用的静态模板框架是pelican, 是一个基于python的一个框架,因为自己对python算是比较熟悉, 定制化对自己来说也没有那么难。

1.安装pelican和pip

pip这么强悍的python包管理工具,不可能错过了吧。

$ easy_install pip

此外,为了单独为pelican环境进行一个单独的沙箱隔离,最后也安装一个沙箱环境:virtualenv

$ pip install virtualenv

然后初始化沙箱环境

mkdir pelicanBlog
cd pelicanBlog
#设定沙箱环境名字venv
virtualenv --no-site-packages venv
source venv/bin/active

然后安装pelicanmarkdown

pip install pelican
pip install markdown

2.初始化pelican的环境

mkdir blog
cd blog
pelican-quickstart

目录结构如下:

(pelicanvenv) ➜  PycharmProjects tree pelicanBlog -L  1
pelicanBlog
├── Makefile
├── content
├── fabfile.py
├── output
├── pelican-plugins
├── pelican-themes
├── pelicanconf.py
├── pelicanconf.pyc
├── pelicanvenv
├── publishconf.py
├── publishconf.pyc
└── sysublackbear.github.io

我们进入output目录,把git的项目路径拉取下来。

cd output
git clone git@github.com:sysublackbear/sysublackbear.github.io.git

将拉下来的代码目录重命名为output。

3.开始写博文

博文支持markdown的方式去编写,然后通过发布来看效果。

make publish
make serve

然后登陆http://127.0.0.1:8000,可以看到效果。

如果我们想要一键发布到github,可以通过修改makefile文件来解决。

github: publish
cd $(OUTPUTDIR) && git add . && git commit -am "update my blog content" && git push 

后续发布博客,可以直接:

make publish
make github

4.挑选主题

我所使用的是dev-random2这个主题,比较简洁的一个主题,后面我会把我的主题配置放到github里面, 我定制化修改了一些东西。

先下载安装主题包和插件包

git clone git://github.com/getpelican/pelican-themes.git
git clone git://github.com/getpelican/pelican-plugins.git

主题包有用到,插件包暂时没有用,后面会陆续完善功能吧。

当你进入pelican-themes目录后,可以进入你想要的主题目录去拉取最新的主题模板。 可以在这里预览所有的主题

然后看一下pelican-themes的用法吧

(pelicanvenv) ➜  content pelican-themes -h
usage: pelican-themes [-h] [-l | -p | -V] [-i theme path [theme path ...]]
[-r theme name [theme name ...]]
[-U theme path [theme path ...]]
[-s theme path [theme path ...]] [-c] [-v]

Install themes for Pelican
optional arguments:
-h, --help            show this help message and exit
-l, --list            Show the themes already installed and exit
-p, --path            Show the themes path and exit
-V, --version         Print the version of this script
-i theme path [theme path ...], --install theme path [theme path ...]
The themes to install
-r theme name [theme name ...], --remove theme name [theme name ...]
The themes to remove
-U theme path [theme path ...], --upgrade theme path [theme path ...]
The themes to upgrade
-s theme path [theme path ...], --symlink theme path [theme path ...]
Same as `--install', but create a symbolic link instead of copying the theme. Useful for theme development
-c, --clean           Remove the broken symbolic links of the theme path
-v, --verbose         Verbose output

从上面我们可以知道修改和更新主题的基本操作。

基本暂时用到的功能只有这些,后面可能要慢慢挖掘功能使用。

另外,如果对pelican源码感兴趣的,可以看看源码文档吧。

Pelican:http://docs.getpelican.com/en/3.2

dev-random2:https://github.com/sysublackbear/dev-random2