建立專案
然後使用指令 pelican-quickstart
來進行專案的生成,這個動作會詢問使用者若干問題並且自動地依據回答產生 Pelican 的設定檔(設定檔在生成之後我們可以隨時更改,所以在這邊回答問題的時候不用太擔心),以下是一個簡單的範例和說明:
$ pelican-quickstart
Welcome to pelican-quickstart v3.6.3.
This script will help you create a new Pelican-based website.
Please answer the following questions so this script can generate the files
needed by Pelican.
> Where do you want to create your new web site? [.]
# 這邊是指定 Pelican 專案內容產生的路徑,我們就選擇放在當前的目錄下
> What will be the title of this web site? dokelung.me
# 靜態站的名稱,這邊自行發揮
> Who will be the author of this web site? dokelung
# 作者的名稱,一樣自行發揮
> What will be the default language of this web site? [en] zh
# 預設的語言,基本上是英文,我們改成使用中文 zh
> Do you want to specify a URL prefix? e.g., http://example.com (Y/n) Y
# 是否設定網站 URL 的前綴
> What is your URL prefix? (see above example; no trailing slash) http://dokelung.me
# 如果上題答是的話這邊就會問你想要的 URL prefix 是什麼
> Do you want to enable article pagination? (Y/n) Y
# 是否設定每頁顯示的文章數
> How many articles per page do you want? [10]
# 每頁顯示的文章數
> What is your time zone? [Europe/Paris] Asia/Taipei
# 設定時區,我們調整成台北時間
> Do you want to generate a Fabfile/Makefile to automate generation and publishing? (Y/n) Y
是否要生成 Fabfile/Makefile 來幫助我們自動生成和發佈網站,我選擇使用 make 工具所以這邊選擇是
> Do you want an auto-reload & simpleHTTP script to assist with theme and site development? (Y/n) Y
# 在開發靜態站的時候,我們常常會進行修改和測試,Pelican 有內建一個小型的 web server,但是基本上每次修改都必須要先關閉 server 然後修改,最後重啟,這邊選是的話可以生成一個會自動重載的 script 幫助我們節省開發的時間
# 接下來是一連串的發佈管道詢問,如果你在這裡預先告知 Peclian 要使用哪種方式上傳發佈,他會替你預先做一些設定和建立一些快捷指令,不過我們這邊暫時都先略過
> Do you want to upload your website using FTP? (y/N) N
> Do you want to upload your website using SSH? (y/N) N
> Do you want to upload your website using Dropbox? (y/N) N
> Do you want to upload your website using S3? (y/N) N
> Do you want to upload your website using Rackspace Cloud Files? (y/N) N
> Do you want to upload your website using GitHub Pages? (y/N) N
Done. Your new project is available at /Users/dokelung/Project/blog-demo
好的,到這裡總算產生了第一個專案,接著我們就來檢視一下 pelican-quickstart
為我們做了什麼吧!
我們檢視我們的 blog 目錄,大家可以簡單地使用 ls
來確認,不過 tree
命令是非常不錯的檔案結構檢視工具:
$ tree
.
├── Makefile
├── content
├── develop_server.sh
├── fabfile.py
├── output
├── pelicanconf.py
└── publishconf.py
2 directories, 5 files
我們大致上來做個介紹:
Makefile
:還記得我們剛剛請 Pelican 幫我們生成 Makefile 嗎?透過make
指令操作Makefile
可以讓我們自動化地執行許多動作,在這裡 Pelican 已經很貼心地將許多常用的pelican
命令組合寫成若干 make 動作了,這可以幫助我們節省不少時間。content
:這是一個置放靜態站原始資料的地方,也就是說,日後我們寫的所有的文章,都是放在這裡面,當然,目前是空無一物的狀態。develop_server.sh
:這是一個 bash 命令稿,可以幫助重載我們修改和測試網站的時候能夠進行自動重載而不必關閉重啟。fabfile.py
:這裡我們使用 make 所以我們暫時不需要用到它。output
:content
目錄下放置的是原始的內容,而 Pelican 產生出來的靜態站內容會輸出到output
目錄,不過此時也是空空如也。pelicanconf.py
:Pelican 的設定檔,裡面已經根據使用者回答的問題設定好部分變數了,Pelican 的設定檔名稱沒有嚴格規定,使用者可以任意取名改名,我們通常會準備兩個設定檔,一個測試用,一個發佈用,這個自動產生的設定檔是預設為開發用的。publishconf.py
:跟pelicanconf.py
沒什麼兩樣,都是 Pelican 的設定檔,內容跟pelicanconf.py
略有不同,預設是用來給發佈用的。