靜態站生成
最後讓我們回到 blog 目錄,使用 pelican 命令產生網站內容,pelican 命令的用法如下:
$ pelican <原始內容目錄> -o <靜態站生成位置> -s <使用的設定檔>
所以我們使用 pelican 命令,根據 pelicanconf.py 中的設定,將 content 目錄的原始內容在 output 目錄中轉為靜態站的內容:
$ pelican content -o output -s pelicanconf.py
Done: Processed 1 article, 0 drafts, 0 pages and 0 hidden pages in 0.15 seconds.
訊息告訴我們,Pelican 產生了一個 article,總共花了 0.15 秒。
要檢視 Pelican 生成的內容是很容易的,我們不必將靜態站上傳到真正的網路伺服器,只要利用 Pelican 內建的 local server 就能在本機端預覽靜態站:
$ cd output
$ python -m pelican.server
打開瀏覽器,輸入 URL:
http://127.0.0.1:8000/
就可以見到我們的網站和剛剛新增的第一篇文章囉:

雖然 Pelican 的操作不算特別複雜,但是還是滿煩瑣的,光是每次要 pelican -o -s 的就夠惱人了,幸好 Pelican 已經自動幫我們產生了一個 Makefile,裡面已經有預設的一些自動化指令了,讓我們一起來瞧一瞧:
$ make
Makefile for a pelican Web site
Usage:
make html (re)generate the web site
make clean remove the generated files
make regenerate regenerate files upon modification
make publish generate using production settings
make serve [PORT=8000] serve site at http://localhost:8000
make serve-global [SERVER=0.0.0.0] serve (as root) to :80
make devserver [PORT=8000] start/restart develop_server.sh
make stopserver stop local server
make ssh_upload upload the web site via SSH
make rsync_upload upload the web site via rsync+ssh
make dropbox_upload upload the web site via Dropbox
make ftp_upload upload the web site via FTP
make s3_upload upload the web site via S3
make cf_upload upload the web site via Cloud Files
make github upload the web site via gh-pages
Set the DEBUG variable to 1 to enable debugging, e.g. make DEBUG=1 html
Set the RELATIVE variable to 1 to enable relative urls
是的,我們往後新增修改了文章,或是調整了 Pelican 的設定後,可以透過這些快捷的指令來幫助我們自動化,比如說原本了生成指令,我們可以用簡單地 make html 來完成:
$ make html
pelican /Users/dokelung/Project/blog-demo/content -o /Users/dokelung/Project/blog-demo/output -s /Users/dokelung/Project/blog-demo/pelicanconf.py
Done: Processed 1 article, 0 drafts, 0 pages and 0 hidden pages in 0.14 seconds.
在這裡我們也可以從訊息中看出,make 幫我們做了什麼。
同樣地,我們也可以用 make serve 來啟動測試用的伺服器。make devserver 和 make stopserver 將會自動啟動和停止之前產生的 develop_server.sh,這一樣會啟動伺服器,但我們修改內容後不必關閉重啟,直接在瀏覽器上刷新頁面就可以觀察出變化了。
當然,大家也可以自己添加 make 規則,直接修改 Makefile 就可以了(當然前提是知道怎麼改XD)。
需要注意的是,這些 make 動作是使用哪一個設定檔。舉例來說,
make html預設是使用pelicanconf.py,make publish則預設使用publishconf.py