時間:2023-07-21 11:21:01 | 來源:網(wǎng)站運營
時間:2023-07-21 11:21:01 來源:網(wǎng)站運營
Pelican 入門:一個 Python 靜態(tài)網(wǎng)站生成器:Pelican 是那些想要自我托管簡單網(wǎng)站或博客的 Python 用戶的絕佳選擇。如果你想創(chuàng)建一個自定義網(wǎng)站或博客,有很多選擇。許多提供商可以托管你的網(wǎng)站并為你完成大部分工作。(WordPress 是一個非常受歡迎的選項。)但是使用托管方式,你會失去一些靈活性。作為一名軟件開發(fā)人員,我更喜歡管理我自己的服務(wù)器,并在我的網(wǎng)站如何運行方面保持更多的自由。
$ mkdir test-site$ cd test-site$ python3 -m venv venv$ ./venv/bin/pip install --upgrade pip...Successfully installed pip-18.1$ ./venv/bin/pip install pelicanCollecting pelican...Successfully installed MarkupSafe-1.1.0 blinker-1.4 docutils-0.14 feedgenerator-1.9 jinja2-2.10 pelican-4.0.1 pygments-2.3.1 python-dateutil-2.7.5 pytz-2018.7 six-1.12.0 unidecode-1.0.23
Pelican 的 quickstart CLI 工具將創(chuàng)建基本布局和一些文件來幫助你開始,運行 pelican-quickstart
命令。為了簡單起見,我輸入了網(wǎng)站標(biāo)題和作者的名字,并對 URL 前綴和文章分頁選擇了 “N”。(對于其它選項,我使用了默認(rèn)值。)稍后在配置文件中更改這些設(shè)置非常容易。$ ./venv/bin/pelicanquickstartWelcome to pelicanquickstart v4.0.1.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? [.]> What will be the title of this web site? My Test Blog> Who will be the author of this web site? Craig> What will be the default language of this web site? [en]> Do you want to specify a URL prefix? e.g., https://example.com (Y/n) n> Do you want to enable article pagination? (Y/n) n> What is your time zone? [Europe/Paris]> Do you want to generate a tasks.py/Makefile to automate generation and publishing? (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)> Do you want to upload your website using GitHub Pages? (y/N)Done. Your new project is available at /Users/craig/tmp/pelican/test-site
你需要啟動的所有文件都準(zhǔn)備好了。pelicanconf.py
文件,尋找 TIMEZONE
變量。TIMEZONE = 'Europe/Paris'
將其改為 UTC
。TIMEZONE = 'UTC'
要更新公共設(shè)置,在 pelicanconf.py
中查找 SOCIAL
變量。SOCIAL = (('You can add links in your config file', '#'), ('Another social link', '#'),)
我將添加一個我的 Twitter 賬戶鏈接。SOCIAL = (('Twitter (#craigs55)', 'https://twitter.com/craigs55'),)
注意末尾的逗號,它很重要。這個逗號將幫助 Python 識別變量實際上是一個集合。確保你沒有刪除這個逗號。Makefile
。將 devserver
傳給 make
命令將在你的計算機上啟動一個開發(fā)服務(wù)器,以便你可以預(yù)覽所有內(nèi)容。Makefile
中使用的 CLI 命令假定放在 PATH
搜索路徑中,因此你需要首先激活該虛擬環(huán)境。$ source ./venv/bin/activate$ make devserverpelican -lr /Users/craig/tmp/pelican/test-site/content o/Users/craig/tmp/pelican/test-site/output -s /Users/craig/tmp/pelican/test-site/pelicanconf.py-> Modified: theme, settings. regenerating...WARNING: No valid files found in content for the active readers: | BaseReader (static) | HTMLReader (htm, html) | RstReader (rst)Done: Processed 0 articles, 0 drafts, 0 pages, 0 hidden pages and 0 draft pages in 0.18 seconds.
在你最喜歡的瀏覽器中打開 http://localhost:8000 來查看你的簡單測試博客。welcome.rst
的文件添加到網(wǎng)站的 content
目錄中。在你喜歡的文本編輯器中,使用以下文本創(chuàng)建一個文件:$ pwd/Users/craig/tmp/pelican/test-site$ cat content/welcome.rstWelcome to my blog!###################:date: 20181216 08:30:tags: welcome:category: Intro:slug: welcome:author: Craig:summary: Welcome documentWelcome to my blog.This is a short page just to show how to put up a static page.
Pelican 會自動解析元數(shù)據(jù)行,包括日期、標(biāo)簽等。-> Modified: content. regenerating...Done: Processed 1 article, 0 drafts, 0 pages, 0 hidden pages and 0 draft pages in 0.10 seconds.
在瀏覽器中刷新你的測試網(wǎng)站來查看更改。$ cd ..$ git clone --recursive https://github.com/getpelican/pelicanthemesCloning into 'pelicanthemes'...
我喜歡藍(lán)色,那么試試 blueidea。pelicanconf.py
,添加以下行:THEME = '/Users/craig/tmp/pelican/pelican-themes/blueidea/'
開發(fā)服務(wù)器將重新生成你的輸出。在瀏覽器中刷新網(wǎng)頁來查看新主題。pelican-quickstart
輸出,你將看到使用 FTP、 SSH、S3 甚至 GitHub 頁面的選項,每個選項都有其優(yōu)點和缺點。但是,如果我必須選擇一個,那么我可能會選擇發(fā)布到 GitHub 頁面。關(guān)鍵詞:成器,靜態(tài),入門
微信公眾號
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。