Skip to content
This repository was archived by the owner on Jul 20, 2023. It is now read-only.

rlaboiss/pelican-avatar

Repository files navigation

Avatar: A Plugin for Pelican

Note
The code in this repository has been moved into the avatar repository, which is maintained under the auspices of the Pelican-plugins organization. The present repository is archived and preserved here for historical purposes.

Build Status PyPI Version License

This plugin allows the inclusion of Libravatar or Gravatar user profile pictures, according to the email address of the article's author.

Installation

This plugin can be installed via:

python -m pip install pelican-avatar

Usage

Specifying the author's email address

The default email address is taken from the AVATAR_AUTHOR_EMAIL variable in the Pelican configuration fileThis default value can be overridden in a per-article basis, according to the email address found in the article's metadata.

In ReSTructuredText:

In Markdown:

The avatar image corresponding to the specified email is searched at Libravatar. If it is not found there, it is searched (transparently) at Gravatar. If the avatar for the specified email address is not found at any of those services, a default picture is shown. The default for the "missing picture" can be defined in the configuration variable AVATAR_MISSING.

Adjusting the template

This plugin assigns the author_avatar variable to the Libravatar URL and makes the variable available within the article's context. For instance, you can add the following to a template file (for example, to the article_infos.html template file), just before the information about the author:

{% if article.author_avatar %}
<div align="center">
        <img src="{{ article.author_avatar }}">
</div>
{% endif %}

This will yield the following result (with the notmyidea theme):

figure

Page templates work in a similar way:

{% if page.author_avatar %}
<div align="center">
        <img src="{{ page.author_avatar }}">
</div>
{% endif %}

To use in common templates, such as base.html, you can do something like this:

{% if author_avatar %}
<div align="center">
        <img src="{{ author_avatar }}">
</div>
{% endif %}

Or if you want to support optional overriding of the email in articles or pages, while still taking the global configuration if neither is available:

{% if article and article.author_avatar %}
  {% set author_avatar = article.author_avatar %}
{% elif page and page.author_avatar %}
  {% set author_avatar = page.author_avatar %}
{% endif %}
{% if author_avatar %}
<div align="center">
        <img src="{{ author_avatar }}">
</div>
{% endif %}

Configuration

The following variables can be set in the Pelican configuration file:

  • AVATAR_AUTHOR_EMAIL: site-wide default for the author's email address.

  • AVATAR_MISSING: The default for the missing picture. This can be either a url (e.g. "http://example.com/nobody.png") or the name of a library of logos (e.g. "wavatar"; for the full set of alternativas, see the Libravatar API).

  • AVATAR_SIZE: The size, in pixels, of the profile picture (it is always square, so the height is equal to the width). If not specified, the default size (80×80) is returned by Libravatar.

  • AVATAR_USE_GRAVATAR: By default, the avatar is searched at the Libravatar service. Search at the Gravatar service can be forced by setting this configuration variable to True.

Credits

Inspiration for this plugin came from the gravatar plugin.

Contributing

Contributions are welcome and much appreciated. Every little bit helps. You can contribute by improving the documentation, adding missing features, and fixing bugs. You can also help out by reviewing and commenting on existing issues.

To start contributing to this plugin, review the Contributing to Pelican documentation, beginning with the Contributing Code section.

Acknowledgments

Thanks to Troy Curtis for adding support for page generator and global generator context and for making improvements in the Poetry workflow.

Author

Copyright (C) 2015, 2021 Rafael Laboissière ([email protected])

License

This project is licensed under the AGPL-3.0 license.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages