Skip to content

Commit

Permalink
Merge pull request #111 from Holzhaus/multiple-news-authors
Browse files Browse the repository at this point in the history
plugins/news: Add support for multiple post authors
  • Loading branch information
rryan authored Jul 2, 2020
2 parents 15b7b2e + d99bbe9 commit 4e19364
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 44 deletions.
20 changes: 10 additions & 10 deletions pages/news.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ <h1>{% trans "News and Announcements" %}</h1>
<h2><a href="{% url post.path %}">{{ post.title }}</a></h2>
<p style="font-size: small;">
Posted on <time>{{ post.date|date:"Y-m-d" }}</time>
{% if post.author %}
{% if post.authors %}
by
{% for author in post.authors|slice:":-2" %}
<span class="author">{% if author.url %}<a href="{{ author.url }}">{{ author.name }}</a>{% else %}{{ author.name }}{% endif %}{% if author.github %} (<a href="https://github.com/{{ author.github }}">@{{ author.github }}</a>){% endif %}</span>,
{% endfor %}
{% for author in post.authors|slice:"-2:-1" %}
<span class="author">{% if author.url %}<a href="{{ author.url }}">{{ author.name }}</a>{% else %}{{ author.name }}{% endif %}{% if author.github %} (<a href="https://github.com/{{ author.github }}">@{{ author.github }}</a>){% endif %}</span> and
{% endfor %}
{% for author in post.authors|slice:"-1:" %}
<span class="author">
{% if post.author_url %}
<a href="{{ post.author_url }}">{{ post.author }}</a>
{% else %}
{{ post.author }}
{% endif %}
{% if post.author_github %}
(<a href="https://github.com/{{ post.author_github }}">@{{ post.author_github }}</a>)
{% endif %}
</span>
{% if author.url %}<a href="{{ author.url }}">{{ author.name }}</a>{% else %}{{ author.name }}{% endif %}{% if author.github %} (<a href="https://github.com/{{ author.github }}">@{{ author.github }}</a>){% endif %}</span>
{% endfor %}
{% endif %}
</p>

Expand Down
55 changes: 31 additions & 24 deletions plugins/news.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,9 @@
POSTS_PATH = "news/"
POSTS = []
AUTHOR_METADATA = {
'': {
'name': 'Mixxx Team',
'url': 'https://github.com/orgs/mixxxdj/people',
'email': 'core-team@mixxx.org',
},
'Mixxx': {
'name': 'Mixxx Team',
'url': 'https://github.com/orgs/mixxxdj/people',
"name": "Mixxx Team",
"url": "https://github.com/orgs/mixxxdj/people",
'email': 'core-team@mixxx.org',
},
'Be.': {
Expand Down Expand Up @@ -50,6 +45,7 @@
'email': 'amcrehan@gmail.com',
},
}
AUTHOR_METADATA[""] = AUTHOR_METADATA["Mixxx"]


def getNode(template, context, name="subject"):
Expand Down Expand Up @@ -83,8 +79,8 @@ def preBuild(site):

# Find a specific defined variable in the page context,
# and throw a warning if we're missing it.
def find(name, warn=True):
value = page.context().get(name, "")
def find(name, warn=True, fallback=""):
value = page.context().get(name, fallback)
if warn and not value:
logging.warning(
"Missing info '%s' for post %s" % (name, page.path)
Expand All @@ -94,21 +90,32 @@ def find(name, warn=True):
# Build a context for each post
postContext = {}
postContext["title"] = find("title")
postContext["author"] = find("author")
postContext["author_url"] = find("author_url", warn=False)
postContext["author_github"] = find("author_github", warn=False)
postContext["author_email"] = find("author_email", warn=False)
author_metadata = AUTHOR_METADATA.get(postContext["author"])
if author_metadata:
if "name" in author_metadata:
postContext["author"] = author_metadata["name"]
if not postContext["author_url"]:
postContext["author_url"] = author_metadata.get("url", "")
if not postContext["author_github"]:
postContext["author_github"] = author_metadata.get(
"github", "")
if not postContext["author_email"]:
postContext["author_email"] = author_metadata.get("email", "")

author = find("author", warn=False)
if "," in author:
authors = [{"name": name.strip()} for name in author.split(",")]
else:
authors = [{
"name": find("author"),
"url": find("author_url", warn=False),
"github": find("author_github", warn=False),
"email": find("author_email", warn=False),
}]

postContext["authors"] = []
for author in authors:
author_metadata = AUTHOR_METADATA.get(author["name"])
if author_metadata:
if "name" in author_metadata:
author["name"] = author_metadata["name"]
if not author.get("url"):
author["url"] = author_metadata.get("url", "")
if not author.get("github"):
author["github"] = author_metadata.get("github", "")
if not author.get("email"):
author["email"] = author_metadata.get("email", "")

postContext["authors"].append(author)

postContext["date"] = find("date")
postContext["path"] = posixpath.join("/", page.path)
Expand Down
20 changes: 10 additions & 10 deletions templates/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ <h1>{{ title }}</h1>
{# Post content #}
<p style="font-size: small;">
Posted on <time>{{ date|date:"Y-m-d" }}</time>
{% if author %}
{% if authors %}
by
{% for author in authors|slice:":-2" %}
<span class="author">{% if author.url %}<a href="{{ author.url }}">{{ author.name }}</a>{% else %}{{ author.name }}{% endif %}{% if author.github %} (<a href="https://github.com/{{ author.github }}">@{{ author.github }}</a>){% endif %}</span>,
{% endfor %}
{% for author in authors|slice:"-2:-1" %}
<span class="author">{% if author.url %}<a href="{{ author.url }}">{{ author.name }}</a>{% else %}{{ author.name }}{% endif %}{% if author.github %} (<a href="https://github.com/{{ author.github }}">@{{ author.github }}</a>){% endif %}</span> and
{% endfor %}
{% for author in authors|slice:"-1:" %}
<span class="author">
{% if author_url %}
<a href="{{ author_url }}">{{ author }}</a>
{% else %}
{{ author }}
{% endif %}
{% if author_github %}
(<a href="https://github.com/{{ author_github }}">@{{ author_github }}</a>)
{% endif %}
</span>
{% if author.url %}<a href="{{ author.url }}">{{ author.name }}</a>{% else %}{{ author.name }}{% endif %}{% if author.github %} (<a href="https://github.com/{{ author.github }}">@{{ author.github }}</a>){% endif %}</span>
{% endfor %}
{% endif %}
</p>
{% block post %}{% endblock %}
Expand Down

0 comments on commit 4e19364

Please sign in to comment.