生成Atom提要的编辑器插件。
lektor-atom的Python项目详细描述
Lektor Atom插件
为基于Lektor的站点生成一个或多个AtomXML提要。
灵感来自于为Lektor官方博客撰写的atom-feed-support插件Armin Ronacher。
安装
从命令行将lektor atom添加到项目中:
lektor plugins add lektor-atom
见the Lektor documentation for more instructions on installing plugins。
配置
对于要发布的每个提要,向configs/atom.ini
添加一个节。例如,一个包含所有最近文章的源和一个关于咖啡的源的博客:
[blog]
name = My Blog
source_path = /
url_path = /feed.xml
items = site.query('/').filter(F.type == 'post')
item_model = blog-post
[coffee]
name = My Blog: Articles About Coffee
source_path = /
url_path = /category/coffee/feed.xml
items = site.query('/blog').filter(F.categories.contains('coffee'))
item_model = blog-post
节名,比如blog
和coffee
,只是用作内部标识符。
选项
Option | Default | Description |
---|---|---|
source_path | / | Where in the content directory to find items' parent source |
name | Feed name: default is section name | |
filename | feed.xml | Name of generated Atom feed file |
url_path | Feed's URL on your site: default is source's URL path plus the filename | |
blog_author_field | author | Name of source's author field |
blog_summary_field | summary | Name of source's summary field |
items | None | A query expression: default is the source's children |
limit | 50 | How many recent items to include |
item_title_field | title | Name of items' title field |
item_body_field | body | Name of items' content body field |
item_author_field | author | Name of items' author field |
item_date_field | pub_date | Name of items' publication date field |
item_model | None | Name of items' model |
为您的模型定制插件
使用field选项告诉lektor atom如何读取项目。例如,如果您的站点的模型是:
[model]
name = Blog
[fields.writer]
type = string
[fields.short_description]
type = string
然后添加到atom.ini:
[main]
blog_author_field = writer
blog_summary_field = short_description
有关完整的示例,请参见tests/demo-project/configs/atom.ini。
过滤项
默认情况下,lektor atom在source_path
处获取源,并在提要中包含其所有子级。如果设置了item_model
,lektor atom只包含具有该数据模型的子级。
将items
设置为任何查询表达式以覆盖默认值。如果items_model
也指定了,lektor atom会将其作为过滤器应用到items
。
在模板中使用
您可以链接到模板中的特定源。如果您的atom.ini
包含这样的提要:
[main]
source_path = /blog
在这样的模板中链接到源:
{{ 'blog@atom/main'|url }}
更改
2016-06-02:版本0.2。python 3兼容性(感谢dan bauman) 生成期间的彩色错误输出,修复标记格式的项目副标题。
2016-01-09:0.1版,首次发布。