用于计算平均读取时间的鹈鹕插件。
pelican-readtime的Python项目详细描述
计算内容读取时间的Pelican插件。
它将readtime和readtime_string属性添加到 文章和/或页面,以及阅读文章的时间估计。
设置
将“readtime”添加到插件列表:
在鹈鹕conf.py中:
PLUGINS=[...,'readtime']
一。每分钟字数
在您的设置中,您可以使用将READTIME_WPM变量分配给 这样的整数:
在鹈鹕conf.py中:
READTIME_WPM=180
每一篇文章的阅读时间都是用这个平均值来计算的 每分钟计数。(有关如何使用计算出的 在模板中读取时间)。这是最简单的读取时间方法。
2.每种语言每分钟字数
如果要处理多种语言,这是首选方法。 查看以下设置
在鹈鹕conf.py中:
READTIME_WPM={'default':{'wpm':200,'min_singular':'minute','min_plural':'minutes','sec_singular':'second','sec_plural':'seconds'},'es':{'wpm':220,'min_singular':'minuto','min_plural':'minutos','sec_singular':'segundo','sec_plural':'segundos'}}
在本例中,所有文章的默认阅读时间为200字 每分钟。任何西班牙语的文章都将以每分钟220英镑计算。这个 对于信息密集型语言(读取时间变化)很有用 很快。
平均阅读时间不会因语言的不同而变化太快 但是,使用此方法还可以设置复数 从长远来看模板制作更容易。
用法
通过读取时间插件可以访问四个变量: readtime,readtime_string,readtime_with_seconds,以及readtime_string_with_seconds
{% if article.readtime %} This article takes {{article.readtime}} minute(s) to read.{% endif %} // This article takes 4 minute(s) to read.
{% if article.readtime_string %} This article takes {{article.readtime_string}} to read.{% endif %} // This article takes 4 minutes to read.
{% if article.readtime_with_seconds %} This article takes {{article.read_with_seconds[0]}} minutes(s) and {{article.read_with_seconds[1]}} second(s) to read. {% endif %} // This article takes 4 minutes and 21 second(s) to read.
{% if article.readtime_string_with_seconds %} This article takes {{article.readtime_string_with_seconds}} to read.{% endif %} // This article takes 4 minutes, 1 second to read.