Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
What's new
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Menu
Open sidebar
Nícolas F. R. A. Prado
nfraprado.gitlab.io
Commits
b6f481df
Commit
b6f481df
authored
Dec 11, 2020
by
Nícolas F. R. A. Prado
💬
Browse files
Add series pelican plugin
parent
76534d39
Changes
5
Hide whitespace changes
Inline
Side-by-side
pelican-plugins/series/__init__.py
0 → 100644
View file @
b6f481df
from
.series
import
*
pelican-plugins/series/series.py
0 → 100644
View file @
b6f481df
# -*- coding: utf-8 -*-
"""
This plugin extends the original series plugin
by FELD Boris <lothiraldan@gmail.com>
Copyright (c) Leonardo Giordani <giordani.leonardo@gmail.com>
Joins articles in a series and provides variables to
manage the series in the template.
"""
from
collections
import
defaultdict
from
operator
import
itemgetter
from
pelican
import
signals
def
aggregate_series
(
generator
):
series
=
defaultdict
(
list
)
# This cycles through all articles in the given generator
# and collects the 'series' metadata, if present.
# The 'series_index' metadata is also stored, if specified
for
article
in
generator
.
articles
:
if
'series'
in
article
.
metadata
:
article_entry
=
(
article
.
metadata
.
get
(
'series_index'
,
None
),
article
.
metadata
[
'date'
],
article
)
series
[
article
.
metadata
[
'series'
]].
append
(
article_entry
)
# This uses items() which on Python2 is not a generator
# but we are dealing with a small amount of data so
# there shouldn't be performance issues =)
for
series_name
,
series_articles
in
series
.
items
():
# This is not DRY but very simple to understand
forced_order_articles
=
[
art_tup
for
art_tup
in
series_articles
if
art_tup
[
0
]
is
not
None
]
date_order_articles
=
[
art_tup
for
art_tup
in
series_articles
if
art_tup
[
0
]
is
None
]
forced_order_articles
.
sort
(
key
=
itemgetter
(
0
))
date_order_articles
.
sort
(
key
=
itemgetter
(
1
))
all_articles
=
forced_order_articles
+
date_order_articles
ordered_articles
=
[
art_tup
[
2
]
for
art_tup
in
all_articles
]
enumerated_articles
=
enumerate
(
ordered_articles
)
for
index
,
article
in
enumerated_articles
:
article
.
series
=
dict
()
article
.
series
[
'name'
]
=
series_name
article
.
series
[
'index'
]
=
index
+
1
article
.
series
[
'all'
]
=
ordered_articles
article
.
series
[
'all_previous'
]
=
ordered_articles
[
0
:
index
]
article
.
series
[
'all_next'
]
=
ordered_articles
[
index
+
1
:]
if
index
>
0
:
article
.
series
[
'previous'
]
=
ordered_articles
[
index
-
1
]
else
:
article
.
series
[
'previous'
]
=
None
try
:
article
.
series
[
'next'
]
=
ordered_articles
[
index
+
1
]
except
IndexError
:
article
.
series
[
'next'
]
=
None
def
register
():
signals
.
article_generator_finalized
.
connect
(
aggregate_series
)
pelicanconf.py
View file @
b6f481df
...
...
@@ -37,7 +37,7 @@ FILENAME_METADATA = '(?P<trans_id>.*)-(?P<lang>br|en)'
ARTICLE_TRANSLATION_ID
=
'trans_id'
PLUGIN_PATHS
=
[
'pelican-plugins'
]
PLUGINS
=
[
'i18n_subsites'
]
PLUGINS
=
[
'i18n_subsites'
,
'series'
]
I18N_SUBSITES
=
{
'br'
:
{
...
...
theme/templates/article.html
View file @
b6f481df
...
...
@@ -19,6 +19,22 @@
{% endfor %}
{% endif %}
</div>
{% if article.series %}
<p>
{% trans %}Part of the{% endtrans %} "{{ article.series.name }}"{% trans %} series:{% endtrans %}
</p>
<ol
class=
"parts"
>
{% for part_article in article.series.all %}
{% if part_article == article %}
<li
class=
"active"
>
{{ part_article.title }}
</li>
{% else %}
<li>
<a
href=
'{{ SITEURL }}/{{ part_article.url }}'
>
{{ part_article.title }}
</a>
</li>
{% endif %}
{% endfor %}
</ol>
{% endif %}
</header>
<!-- .entry-content -->
<div
class=
"entry-content"
>
...
...
theme/translations/br/LC_MESSAGES/messages.po
View file @
b6f481df
...
...
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2020-12-
07 10:3
8-0300\n"
"POT-Creation-Date: 2020-12-
22 14:0
8-0300\n"
"PO-Revision-Date: 2020-05-25 22:20-0300\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: br\n"
...
...
@@ -22,6 +22,14 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.9.0\n"
#: templates/article.html:23
msgid "Part of the"
msgstr "Parte da série"
#: templates/article.html:23
msgid " series:"
msgstr ":"
#: templates/base.html:40 templates/base.html:43 templates/base.html:70
#: templates/tag.html:7 templates/tags.html:2 templates/tags.html:6
msgid "Tags"
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment