Skip to main content

Libravatar/Gravatar plugin for Pelican

Project description

Avatar: A Plugin for Pelican

Build Status PyPI Version Downloads License

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

Installation

This plugin can be installed via:

python -m pip install pelican-avatar

As long as you have not explicitly added a PLUGINS setting to your Pelican settings file, then the newly-installed plugin should be automatically detected and enabled. Otherwise, you must add avatar to your existing PLUGINS list. For more information, please see the How to Use Plugins documentation.

Usage

Specifying the Author's Email Address

The default email address is taken from the AVATAR_AUTHOR_EMAIL variable in the Pelican settings file. This default value can be overridden on a per-article basis by specifying an email address in the article's metadata:

For reStructuredText:

:email: bart.simpson@example.com

For Markdown:

Email: bart.simpson@example.com

The plugin first tries to find an avatar image corresponding to the specified email at Libravatar. If it is not found there, the plugin then searches Gravatar. If an 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 avatar image URL and makes that 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 address in articles or pages, while still using 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 settings 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 alternatives, 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: The plugin looks up avatars via the Libravatar service by default. Searching 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 Justin Mayer for helping with migration of this plugin under the Pelican Plugins organization, to Troy Curtis for adding support for page generator and global generator context and for making improvements in the Poetry workflow, to Lucas Cimon for fixes in the test suit and in the CI support, and to Christian Clauss for Python 3 porting.

Author

Copyright (C) 2015, 2021-2024 Rafael Laboissière (rafael@laboissiere.net)

License

This project is licensed under the terms of the AGPL 3.0 license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pelican_avatar-1.0.10.tar.gz (142.4 kB view details)

Uploaded Source

Built Distribution

pelican_avatar-1.0.10-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file pelican_avatar-1.0.10.tar.gz.

File metadata

  • Download URL: pelican_avatar-1.0.10.tar.gz
  • Upload date:
  • Size: 142.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for pelican_avatar-1.0.10.tar.gz
Algorithm Hash digest
SHA256 a05f3a082b5383c6ebe46ca6862b2bb53caa2ed20160bd2e2388bbe09e5cf40d
MD5 48b31d1555235c23386a2ff97c38dbaf
BLAKE2b-256 28b91b9786633abeeb215f606a64d9966c9cf7f417eb303b0d7621ed519717bf

See more details on using hashes here.

File details

Details for the file pelican_avatar-1.0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for pelican_avatar-1.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 badbc26711e6ac30d5c4ae1d57ff3d0fb6e25a6031fc98e2eb4c72630f1fb215
MD5 936b41da0cd04683fc5e5e5613f56747
BLAKE2b-256 937680d560133cbe75832ed04d2fc13e7d3fd9893c5991d1b0462dfc32f7aa59

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page