时间:2023-07-21 11:21:01 | 来源:网站运营
时间:2023-07-21 11:21:01 来源:网站运营
Pelican 入门:一个 Python 静态网站生成器:Pelican 是那些想要自我托管简单网站或博客的 Python 用户的绝佳选择。如果你想创建一个自定义网站或博客,有很多选择。许多提供商可以托管你的网站并为你完成大部分工作。(WordPress 是一个非常受欢迎的选项。)但是使用托管方式,你会失去一些灵活性。作为一名软件开发人员,我更喜欢管理我自己的服务器,并在我的网站如何运行方面保持更多的自由。
$ 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 工具将创建基本布局和一些文件来帮助你开始,运行 pelican-quickstart
命令。为了简单起见,我输入了网站标题和作者的名字,并对 URL 前缀和文章分页选择了 “N”。(对于其它选项,我使用了默认值。)稍后在配置文件中更改这些设置非常容易。$ ./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
你需要启动的所有文件都准备好了。pelicanconf.py
文件,寻找 TIMEZONE
变量。TIMEZONE = 'Europe/Paris'
将其改为 UTC
。TIMEZONE = 'UTC'
要更新公共设置,在 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
命令将在你的计算机上启动一个开发服务器,以便你可以预览所有内容。Makefile
中使用的 CLI 命令假定放在 PATH
搜索路径中,因此你需要首先激活该虚拟环境。$ 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
的文件添加到网站的 content
目录中。在你喜欢的文本编辑器中,使用以下文本创建一个文件:$ 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 会自动解析元数据行,包括日期、标签等。-> Modified: content. regenerating...Done: Processed 1 article, 0 drafts, 0 pages, 0 hidden pages and 0 draft pages in 0.10 seconds.
在浏览器中刷新你的测试网站来查看更改。$ cd ..$ git clone --recursive https://github.com/getpelican/pelicanthemesCloning into 'pelicanthemes'...
我喜欢蓝色,那么试试 blueidea。pelicanconf.py
,添加以下行:THEME = '/Users/craig/tmp/pelican/pelican-themes/blueidea/'
开发服务器将重新生成你的输出。在浏览器中刷新网页来查看新主题。pelican-quickstart
输出,你将看到使用 FTP、 SSH、S3 甚至 GitHub 页面的选项,每个选项都有其优点和缺点。但是,如果我必须选择一个,那么我可能会选择发布到 GitHub 页面。关键词:成器,静态,入门