在GitHub Pages上使用Pelican搭建部落格的教程

來源:互聯網
上載者:User
Pelican 介紹

首先看看 Pelican 的一些主要特性:

  • Python實現,開放源碼
  • 輸出靜態頁面,方便託管
  • 支援主題,採用Jajin2模板引擎
  • 支援代碼文法高亮
  • 支援reStructuredText、Markdown、AsciiDoc格式
  • 支援Disqus評論
  • 支援Atom和RSS輸出

這些特性都是大愛,完全滿足我對部落格系統的基本需求,再配合免費無限制的GitHub Pages,一切近乎完美了。
安裝 Pelican

開始前請自行安裝Python環境,支援2.7.X和3.3+,為方便,再順手裝上distribute、pip、virtualenv。(註:我的作業系統是:Windows 7)

建立Pelican虛擬環境

virtualenv PelicanEnv --distributePelicanEnv\Scripts\activate

安裝 Pelican

pip install pelican

如果您使用Markdown來寫文章的話,還需要安裝Markdown庫

pip install Markdown

建立 Blog

建立一個 Blog 目錄

mkdir myblogcd myblog

快速建立 Blog

pelican-quickstart

根據提示一步步輸入相應的配置項,不知道如何設定的接受預設即可,後續可以通過編輯pelicanconf.py檔案更改配置。

以下是產生的目錄結構:

複製代碼 代碼如下:

myblog/
├── content # 存放輸入的源檔案
│ └── (pages) # 存放手工建立的靜態頁面
├── output # 產生的輸出檔案
├── develop_server.sh # 方便開啟測試伺服器
├── Makefile # 方便管理部落格的Makefile
├── pelicanconf.py # 主設定檔
└── publishconf.py # 發布時使用的設定檔

撰寫文章

在 content 目錄下用 Markdown 文法來寫一篇文章

複製代碼 代碼如下:

Title: My super title
Date: 2010-12-03 10:20
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.

產生頁面

make html

現在就可以在output目錄查看產生的html檔案了。

由於我的作業系統是Windows,我對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

建立 GitHub Pages

GitHub Pages分兩種,一種是項目頁面,可建立多個;另一種是使用者頁面,每個使用者ID只能建立一個。兩種都可以用來託管Pelican部落格,這裡以使用者頁面為例。

點擊這裡,建立一個Repository,Repository名字可以是 xxx.github.io 或者 xxx.github.com,其中 xxx 是您的使用者ID。

建立成功以後,便可以把產生的頁面push到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

現在可以通過 xxx.github.io 或者 xxx.github.com 來訪問您的部落格了。
網域名稱綁定

在repo的根目錄下面,建立一個名為CNAME的文字檔,裡面寫入你要綁定的網域名稱,比如頂級網域名稱 example.com 或者次層網域 xxx.example.com。

如果綁定的是頂級網域名稱,則DNS要建立一條A記錄,指向 204.232.175.78。

如果綁定的是次層網域,則DNS要建立一條CNAME記錄,指向 xxx.github.io 或者 xxx.github.com 。

以我的為例:

CNAME檔案

www.dongxf.com

DNSPod上設定

在瀏覽器地址欄中輸入以下連結,都將跳轉指向 http://www.dongxf.com/

http://dongxf.com/
http://www.dongxf.com/
http://blog.dongxf.com/
http://dongdxf.github.io/
http://dongdxf.github.com/

未盡事宜

其他內容請參考 Pelican官方文檔 。我正在翻譯這個文檔,才剛開始,進展緩慢。請點擊 Pelican文檔中文版 訪問,歡迎提出寶貴意見和建議。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.