Skip to content

Commit

Permalink
Fix getnikola#3252 — add MULTIPLE_AUTHORS_PER_POST support
Browse files Browse the repository at this point in the history
  • Loading branch information
Kwpolska authored and devilgate committed Nov 15, 2020
1 parent 94292b6 commit 4aba4f5
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ New in master
Features
--------

* Support for multiple authors per post — comma-separated, enabled by
``MULTIPLE_AUTHORS_PER_POST`` setting (Issue #3252)
* Add ``navbar_custom_bg`` theme option to ``bootstrap4`` and document
options for ``bootstrap4`` better (Issue #3443)
* Add Marathi translation
Expand Down
1 change: 1 addition & 0 deletions docs/template-variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Name Type Descript
``messages`` dict<dict<str, str>> translated messages (``{language: {english: translated}}``)
``meta_generator_tag`` bool ``META_GENERATOR_TAG`` setting
``momentjs_locales`` defaultdict<str, str> dictionary of available Moment.js locales
``multiple_authors_per_post`` bool ``MULTIPLE_AUTHORS_PER_POST`` setting
``navigation_links`` TranslatableSetting ``NAVIGATION_LINKS`` setting
``navigation_alt_links`` TranslatableSetting ``NAVIGATION_ALT_LINKS`` setting
``needs_ipython_css`` bool whether or not Jupyter CSS is needed by this site
Expand Down
3 changes: 3 additions & 0 deletions nikola/conf.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,9 @@ HIDDEN_CATEGORIES = []
# Tag pages will still be generated.
HIDDEN_AUTHORS = ['Guest']

# Allow multiple, comma-separated authors for a post? (Requires theme support, present in built-in themes)
# MULTIPLE_AUTHORS_PER_POST = False

# Final location for the main blog page and sibling paginated pages is
# output / TRANSLATION[lang] / INDEX_PATH / index-*.html
# (translatable)
Expand Down
3 changes: 3 additions & 0 deletions nikola/data/themes/base/assets/css/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ html[dir="rtl"] #toptranslations {
.postlist li {
margin-bottom: .33em;
}
.byline a:not(:last-child):after {
content: ",";
}

/* Post and archive pagers */
.postindexpager .pager .next:before {
Expand Down
6 changes: 5 additions & 1 deletion nikola/data/themes/base/templates/index.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
<h1 class="p-name entry-title"><a href="${post.permalink()}" class="u-url">${post.title()|h}</a></h1>
<div class="metadata">
<p class="byline author vcard"><span class="byline-name fn" itemprop="author">
% if author_pages_generated:
% if author_pages_generated and multiple_authors_per_post:
% for author in post.authors():
<a href="${_link('author', author)}">${author|h}</a>
% endfor
% elif author_pages_generated:
<a href="${_link('author', post.author())}">${post.author()|h}</a>
% else:
${post.author()|h}
Expand Down
6 changes: 5 additions & 1 deletion nikola/data/themes/base/templates/post_header.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
${html_title()}
<div class="metadata">
<p class="byline author vcard p-author h-card"><span class="byline-name fn p-name" itemprop="author">
% if author_pages_generated:
% if author_pages_generated and multiple_authors_per_post:
% for author in post.authors():
<a class="u-url" href="${_link('author', author)}">${author|h}</a>
% endfor
% elif author_pages_generated:
<a class="u-url" href="${_link('author', post.author())}">${post.author()|h}</a>
% else:
${post.author()|h}
Expand Down
6 changes: 5 additions & 1 deletion nikola/data/themes/bootblog4/templates/index.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
<h1 class="p-name entry-title"><a href="${post.permalink()}" class="u-url">${post.title()|h}</a></h1>
<div class="metadata">
<p class="byline author vcard"><span class="byline-name fn" itemprop="author">
% if author_pages_generated:
% if author_pages_generated and multiple_authors_per_post:
% for author in post.authors():
<a href="${_link('author', author)}">${author|h}</a>
% endfor
% elif author_pages_generated:
<a href="${_link('author', post.author())}">${post.author()|h}</a>
% else:
${post.author()|h}
Expand Down
4 changes: 4 additions & 0 deletions nikola/data/themes/bootstrap4/assets/css/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ pre.code {
white-space: pre-wrap;
}

.byline a:not(:last-child):after {
content: ",";
}

/* Override incorrect Bootstrap 4 default */
html[dir="rtl"] body {
text-align: right;
Expand Down
2 changes: 2 additions & 0 deletions nikola/nikola.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ def __init__(self, **config):
'MATHJAX_CONFIG': '',
'METADATA_FORMAT': 'nikola',
'METADATA_MAPPING': {},
'MULTIPLE_AUTHORS_PER_POST': False,
'NEW_POST_DATE_PATH': False,
'NEW_POST_DATE_PATH_FORMAT': '%Y/%m/%d',
'OLD_THEME_SUPPORT': True,
Expand Down Expand Up @@ -1276,6 +1277,7 @@ def _set_global_context_from_config(self):
self._GLOBAL_CONTEXT['smartjoin'] = utils.smartjoin
self._GLOBAL_CONTEXT['colorize_str'] = utils.colorize_str
self._GLOBAL_CONTEXT['meta_generator_tag'] = self.config.get('META_GENERATOR_TAG')
self._GLOBAL_CONTEXT['multiple_authors_per_post'] = self.config.get('MULTIPLE_AUTHORS_PER_POST')

self._GLOBAL_CONTEXT.update(self.config.get('GLOBAL_CONTEXT', {}))

Expand Down
6 changes: 5 additions & 1 deletion nikola/plugins/task/authors.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def set_site(self, site):
"""Set Nikola site."""
super().set_site(site)
self.show_list_as_index = site.config['AUTHOR_PAGES_ARE_INDEXES']
self.more_than_one_classifications_per_post = site.config.get('MULTIPLE_AUTHORS_PER_POST', False)
self.template_for_single_list = "authorindex.tmpl" if self.show_list_as_index else "author.tmpl"
self.translation_manager = utils.ClassificationTranslationManager()

Expand All @@ -86,7 +87,10 @@ def is_enabled(self, lang=None):

def classify(self, post, lang):
"""Classify the given post for the given language."""
return [post.author(lang=lang)]
if self.more_than_one_classifications_per_post:
return post.authors(lang=lang)
else:
return [post.author(lang=lang)]

def get_classification_friendly_name(self, classification, lang, only_last_component=False):
"""Extract a friendly name from the classification."""
Expand Down
17 changes: 16 additions & 1 deletion nikola/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ def title(self, lang=None):
lang = nikola.utils.LocaleBorg().current_lang
return self.meta[lang]['title']

def author(self, lang=None):
def author(self, lang=None) -> str:
"""Return localized author or BLOG_AUTHOR if unspecified.
If lang is not specified, it defaults to the current language from
Expand All @@ -562,6 +562,21 @@ def author(self, lang=None):

return author

def authors(self, lang=None) -> list:
"""Return localized authors or BLOG_AUTHOR if unspecified.
If lang is not specified, it defaults to the current language from
templates, as set in LocaleBorg.
"""
if lang is None:
lang = nikola.utils.LocaleBorg().current_lang
if self.meta[lang]['author']:
author = [i.strip() for i in self.meta[lang]['author'].split(",")]
else:
author = [self.config['BLOG_AUTHOR'](lang)]

return author

def description(self, lang=None):
"""Return localized description."""
if lang is None:
Expand Down

0 comments on commit 4aba4f5

Please sign in to comment.