Jason Blog

使用Pelican建立Blog

1.1 安裝Pelican

pip install virtualenv
virtualenv pelican_env
source pelican_env/bin/activate

安裝pelican工具

pip install pelican markdown ghp-import

1.2 建立 Github Page * 在Github上創建一個倉庫,倉庫名是用戶名.github.io,注意這裡的用戶名是自己的用戶名

  • 建立好後,clone 到 local
git clone https://github.com/xxxx/xxx.github.io
cd xxx.github.io

2.1 建立 Pelican Blog 建立 source branch

git checkout -b source

建立 Pelican

pelican-quickstart

建立的過程中,會問你一些問題,你可以參考下面的回答。

> Where do you want to create your new web site? [.] 
> What will be the title of this web site? Buttermilch
> Who will be the author of this web site? Tony Stark
> What will be the default language of this web site? [en] 
> Do you want to specify a URL prefix? e.g., http://example.com   (Y/n) n
> Do you want to enable article pagination? (Y/n) 
> How many articles per page do you want? [10] 
> Do you want to generate a Fabfile/Makefile ... and publishing? (Y/n) 
> Do you want an auto-reload & simpleHTTP ... and site development? (Y/n) 
> Do you want to upload your website using FTP? (y/N) 
> Do you want to upload your website using SSH? (y/N) 
> Do you want to upload your website using Dropbox? (y/N) 
> Do you want to upload your website using S3? (y/N) 
> Do you want to upload your website using Rackspace Cloud Files? (y/N)

2.1.1 安裝 theme 跟 plugins

git clone https://github.com/jakevdp/pelican-octopress-theme.git
git clone https://github.com/getpelican/pelican-plugins.git

將 pelicanconf.py 檔案裡的 THEME 跟 PLUGIN_PATH 修改成你放置 pelican-octopress-theme 跟 pelican-plugins 的路徑:

import os # 新增
path = os.path.join(os.environ.get('HOME'), 'pelican')
THEME = '%s/pelican-octopress-theme' % path
PLUGIN_PATH = '%s/pelican-plugins' % path

2.2 建立Markdown文章

Title: 你好,世界!
Date: 2014-09-26 16:08
Category: Python
Tags: python
Author: Jason
Summary: 你好,世界!
你好,世界,世界,你好。

2.3 Local test 編寫好了之後,就可以在本地進行測試了。

pelican content -s pelicanconf.py --ignore-cache
cd output
python -m SimpleHTTPServer 1111

2.4 提交更改

git add .
git commit -m "initial commit"

2.5 發佈

git branch gh-pages
ghp-import output
git checkout master
git merge gh-pages
git push --all

2.6 之後修改文章只需下面步驟即可

git checkout source
新增修改文章
git add .
git commit -m "update"
ghp-import output
git checkout master
git merge gh-pages
git push --all

Pelican