-
Notifications
You must be signed in to change notification settings - Fork 844
/
multi_part.py
42 lines (28 loc) · 1016 Bytes
/
multi_part.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
"""
Copyright (c) FELD Boris <lothiraldan@gmail.com>
Multiple part support
=====================
Create a navigation menu for multi-part related_posts
"""
from collections import defaultdict
from pelican import signals
import logging
log = logging.getLogger(__name__)
warning_message = """multi_part plugin: this plugin has been deprecated.
The 'series' plugin provides better support for multi part articles.
"""
def aggregate_multi_part(generator):
log.warning(warning_message)
multi_part = defaultdict(list)
for article in generator.articles:
if 'parts' in article.metadata:
multi_part[article.metadata['parts']].append(article)
for part_id in multi_part:
parts = multi_part[part_id]
# Sort by date
parts.sort(key=lambda x: x.metadata['date'])
for article in parts:
article.metadata['parts_articles'] = parts
def register():
signals.article_generator_finalized.connect(aggregate_multi_part)