Pelican 的一些插件

Page content

  Pelican 的一些插件。

1、Control Category Display Order

https://github.com/jhshi/pelican.plugins.category_order

默认情况下,只能按字母顺序设置category或tag。该插件提供按该category或tag中的文章数量对它们进行排序的功能。http://jhshi.me/blog/categories/index.html查看演示。

配置:

CATEGORIES_ORDER_BY:可以是sizesize-revalphabetic-revalphabetic

TAGS_ORDER_BY:可以是sizesize-revalphabetic-revalphabetic

'size-rev':按照分类或标签下的文章数量从大到小排序。
'size':按照分类或标签下的文章数量从小到大排序。
'alphabetic-rev':按照分类或标签的名称字母顺序从大到小排序。
'alphabetic':按照分类或标签的名称字母顺序从小到大排序。

这两个设置的默认值为 size-rev

安装配置:

下载源代码、将文件夹category_order复制到plugins文件夹,在pelicanconf.py文件中加入:

PLUGINS = [
    "plugins.category_order",
]
CATEGORIES_ORDER_BY = "size"
TAGS_ORDER_BY = "size"
在模板中使用:

会在模板中添加两个变量:categoriestags

{% for category ,articles in categories %}
分类:{{ category }},共有{{ articles|count }}篇文章。
<br>
分类链接:{{ category.url }}
<br>
{% for article in articles %}
文章名:{{ article.title }},链接:{{ article.url }}
<br>
{% endfor %}
<br>
{% endfor %}


{% for tag ,articles in tags %}
分类:{{ tag }} ,共有{{ articles|count }}篇文章。
<br>
分类链接:{{ tag.url }}
<br>
{% for article in articles %}
文章名:{{ article.title }},链接:{{ article.url }}
<br>
{% endfor %}
<br>
{% endfor %}

2、Related Posts

https://github.com/pelican-plugins/related-posts Related Posts 通过在文章的上下文中添加 related_posts 变量来将相关帖子列表添加到文章中。

安装配置:
pip install pelican-related-posts

默认情况下,最多列出 5 篇相关文章。可以通过在pelicanconf.py文件中定义RELATED_POSTS_MAX来自定义此值:

# pelican.plugins导入
from pelican.plugins import  related_posts
PLUGINS = [
    "related_posts",
]
RELATED_POSTS_MAX = 10
RELATED_POSTS_SKIP_SAME_CATEGORY = True #使用此设置时,article.related_posts将仅包含来自原始文章类别以外的相关文章。
在模板中使用:

使用 article.related_posts 变量:

{% if article.related_posts %}
    <ul>
    {% for related_post in article.related_posts %}
        <li><a href="{{ SITEURL }}/{{ related_post.url }}">{{ related_post.title }}</a></li>
    {% endfor %}
    </ul>
{% endif %}

2、similar-posts

https://github.com/pelican-plugins/similar-posts

similar-posts它将 similar_posts 变量添加到每篇已发布文章的上下文中,功能和related-posts类似,不过使用相似性测量算法,结果应该更准确。

安装配置:

注意:此插件与 Python 3.8 到 3.11 兼容。Python 3.12+ 目前不受支持,因为与下面列出的一个或多个依赖项不兼容。

pip install pelican-similar-posts

默认情况下,最多列出 5 篇相关文章。可以通过在pelicanconf.py文件中定义SIMILAR_POSTS_MAX_COUNT来自定义此值:

# pelican.plugins导入
from pelican.plugins import  similar_posts
PLUGINS = [
    "similar_posts",
]
#或者
PLUGINS = [
    "pelican.plugins.similar_posts",
]

SIMILAR_POSTS_MAX_COUNT = 10

SIMILAR_POSTS_MIN_SCORE = 0.5 #默认值为 .0001。值为 1.0 会将类似帖子的列表限制为具有相同标签集的文章。任何大于 0.0 的值都充当相似性阈值,但要使用此功能,您可能需要根据经验找到合适的值。
在模板中使用:

使用 article.similar_posts 变量:

{% if article.similar_posts %}
    <ul>
    {% for similar in article.similar_posts %}
        <li><a href="{{ SITEURL }}/{{ similar.url }}">{{ similar.title }}</a></li>
    {% endfor %}
    </ul>
{% endif %}

3、pelican-seo

https://github.com/MaevaBrunelles/pelican-seo seo插件,以后再研究使用方法

4、Sitemap

https://github.com/pelican-plugins/sitemapp

安装配置:

pip install pelican-sitemap

站点地图保存在:<output_path>/sitemap.<format> 默认设置pelicanconf.py:

# pelican.plugins导入
from pelican.plugins import  sitemap
PLUGINS = [
    "sitemap",
]
#或者
PLUGINS = [
    "pelican.plugins.sitemap",
]

SITEMAP = {
    "format": "xml",
    "priorities": {
        "articles": 0.5,
        "indexes": 0.5,
        "pages": 0.5
    },
    "changefreqs": {
        "articles": "monthly",
        "indexes": "daily",
        "pages": "monthly"
    }
}

5、pagination

https://github.com/stemoretti/pagination 此插件添加了一个过滤函数pagination,该分页返回从 1 到 n 的数字列表,如果太长,则缩写为 0。

这个插件是5年前编写的,现在使用有问题,暂时没找到解决办法

安装配置:

下载源代码、将文件夹pagination复制到plugins文件夹,在pelicanconf.py文件中加入:

PLUGINS = [
    "pagination",
]
CATEGORIES_ORDER_BY = "size"
TAGS_ORDER_BY = "size"
在模板中使用:
<ul>
{% for cpage articles_paginator.num_pages | pagination(articles_page.number) %}
  <li>
  {% if cpage != 0 %}
    <a href="{{ articles_paginator.page(cpage).url }}">{{ cpage }}</a>
  {% else %}
    <span>...</span>
  {% endif %}
  </li>
{% endfor %}
</ul>

https://github.com/fangpsh/another_read_more_link “在你的帖子中插入 评论将阻止此标记下方的帖子内容显示在博客文章的索引页面上,一个”继续→“按钮链接到完整的帖子。”

安装配置:

下载源代码、将文件夹another_read_more_link复制到plugins文件夹,在pelicanconf.py文件中加入:

ANOTHER_READ_MORE_LINK = "Read more"
ANOTHER_READ_MORE_LINK_FORMAT = '<a class="another-read-more-link" href="{url}">{text}</a>'

添加css样式: css:

.another-read-more-link {
    background: #eee;
    display: inline-block;
    padding: .4em .4em;
    margin-right: .5em;
    text-decoration: none;
    color: #737373;
    transition: background-color 0.5s;
}