使用pelican创建静态博客

创建工作目录

首先使用pip安装pelican和markdown

pip install pelican markdown

然后创建目录

mkdir my_blog

接着进入目录cd my_blog,执行pelican-quickstart,当前目录内就会生成默认配置好的文件

修改配置

pelicanconf.py是博客的配置文件:

#!/usr/bin/env python
# -*- coding: utf-8 -*- #
from __future__ import unicode_literals

AUTHOR = u'printR'
SITENAME = u"catmelo"
SITEURL = 'http://www.cnblogs.com/catmelo/'

PATH = 'content'
TIMEZONE = 'Asia/Shanghai'
DATE_FORMATS = {'zh':'%Y-%m-%d %H:%M'}

DELETE_OUTPUT_DIRECTORY = False
DEFAULT_LANG = u'zh'

THEME = 'pelican-themes/pelican-bootstrap3'
PLUGIN_PATHS = ["plugins", "pelican-plugins"]
PLUGINS = ['tag_cloud', 'related_posts']

USE_FOLDER_AS_CATEGORY = True
#DEFAULT_CATEGORY = u'文章'

SITELOGO = 'images/logo.png'
FAVICON = 'images/logo.png'
SITELOGO_SIZE = 14

ARTICLE_URL = 'posts/{category}/{slug}/'
ARTICLE_SAVE_AS = 'posts/{category}/{slug}/index.html'
PAGE_URL = 'pages/{slug}/'
PAGE_SAVE_AS = 'pages/{slug}/index.html'

MD_EXTENSIONS = ['codehilite(css_class=highlight)','extra']

STATIC_PATHS = ['images', 'extra']
EXTRA_PATH_METADATA = {'extra/CNAME': {'path': 'CNAME'},}

DISPLAY_ARTICLE_INFO_ON_INDEX = True
DISPLAY_TAGS_INLINE = False
DISPLAY_RECENT_POSTS_ON_SIDEBAR = True
SHOW_ARTICLE_CATEGORY = True
SHOW_DATE_MODIFIED = True
RELATED_POSTS_TEXT = u'相关文章'

FEED_ALL_ATOM = None
CATEGORY_FEED_ATOM = None
TRANSLATION_FEED_ATOM = None
AUTHOR_FEED_ATOM = None
AUTHOR_FEED_RSS = None

# Blogroll
LINKS = ((u'Github', 'http://github.com'),)

# Social widget
SOCIAL = (('Github', 'http://github.com'),)

DEFAULT_PAGINATION = 10

# Uncomment following line if you want document-relative URLs when developing
#RELATIVE_URLS = True

在Makefile文件里添加upload命令,方便上传到github:

...

html:
	$(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)
upload:
	cd $(OUTPUTDIR) && git add -A && git commit -am "update blog" && git push origin master

...

使用主题和插件

获取主题:git clone git://github.com/getpelican/pelican-themes.git

获取插件:git clone git://github.com/getpelican/pelican-plugins.git

修改pelicanconf.py文件,使主题和插件生效:

THEME = 'pelican-themes/pelican-bootstrap3' #直接指定主题目录
PLUGIN_PATHS = ["plugins", "pelican-plugins"] #pelican-plugins为插件总目录
PLUGINS = ['tag_cloud', 'related_posts'] #插件总目录里的插件(文件夹)名

上传到GitHub Pages

域名设置

content/extra/内添加CNAME文件,CNAME里只需写入一行域名,例如:github.com

修改pelianconf.py:

STATIC_PATHS = ['extra']
EXTRA_PATH_METADATA = {'extra/CNAME': {'path': 'CNAME'},}

git操作

cd output
git init
git remote add origin https://github.com/your_name/your_blog.git
git add -A
git commit -am "update blog"
git pull origin master
git push origin master

以后更新网站只需要执行:

cd my_blog
make html
make upload

添加logo和favicon(仅针对pelican-bootstrap3主题)

修改pelicanconf.py:

STATIC_PATHS = ['images', 'extra']

SITELOGO = 'images/logo.png'
FAVICON = 'images/logo.png'
SITELOGO_SIZE = 14

把图标logo.png放进content/images/里即可

posted @ 2015-12-26 22:19  catmelo  阅读(1114)  评论(0编辑  收藏  举报