Merge pull request #317 from benjhess/feature/gravatar-support

Feature/gravatar support
This commit is contained in:
Benoît Latinier 2018-04-25 22:54:50 +02:00 committed by GitHub
commit b21f2e4aaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 53 additions and 4 deletions

View File

@ -108,6 +108,14 @@ scheme is based in `this color palette <http://colrd.com/palette/19308/>`_.
Multiple colors must be separated by space. If you use less than eight colors Multiple colors must be separated by space. If you use less than eight colors
and not a multiple of 2, the color distribution is not even. and not a multiple of 2, the color distribution is not even.
data-isso-gravatar
------------------
Uses gravatar images instead of generating svg images. You have to set
"data-isso-avatar" to **false** when you want to use this. Otherwise
both the gravatar and avatar svg image will show up. Please also set
option "gravatar" to **true** in the server configuration...
data-isso-vote data-isso-vote
-------------- --------------

View File

@ -91,6 +91,18 @@ notify
log-file log-file
Log console messages to file instead of standard out. Log console messages to file instead of standard out.
gravatar
When set to ``true`` this will add the property "gravatar_image"
containing the link to a gravatar image to every comment. If a comment
does not contain an email address, gravatar will render a random icon.
This is only true when using the default value for "gravatar-url"
which contains the query string param ``d=identicon`` ...
gravatar-url
Url for gravatar images. The "{}" is where the email hash will be placed.
Defaults to "https://www.gravatar.com/avatar/{}?d=identicon"
.. _CORS: https://developer.mozilla.org/en/docs/HTTP/Access_control_CORS .. _CORS: https://developer.mozilla.org/en/docs/HTTP/Access_control_CORS

View File

@ -10,6 +10,7 @@ define(function() {
"max-comments-top": "inf", "max-comments-top": "inf",
"max-comments-nested": 5, "max-comments-nested": 5,
"reveal-on-click": 5, "reveal-on-click": 5,
"gravatar": false,
"avatar": true, "avatar": true,
"avatar-bg": "#f0f0f0", "avatar-bg": "#f0f0f0",
"avatar-fg": ["#9abf88", "#5698c4", "#e279a3", "#9163b6", "avatar-fg": ["#9abf88", "#5698c4", "#e279a3", "#9163b6",

View File

@ -247,7 +247,7 @@ define(["app/dom", "app/utils", "app/config", "app/api", "app/jade", "app/i18n",
$("a.edit", footer).toggle("click", $("a.edit", footer).toggle("click",
function(toggler) { function(toggler) {
var edit = $("a.edit", footer); var edit = $("a.edit", footer);
var avatar = config["avatar"] ? $(".avatar", el, false)[0] : null; var avatar = config["avatar"] || config["gravatar"] ? $(".avatar", el, false)[0] : null;
edit.textContent = i18n.translate("comment-save"); edit.textContent = i18n.translate("comment-save");
edit.insertAfter($.new("a.cancel", i18n.translate("comment-cancel"))).on("click", function() { edit.insertAfter($.new("a.cancel", i18n.translate("comment-cancel"))).on("click", function() {
@ -275,7 +275,7 @@ define(["app/dom", "app/utils", "app/config", "app/api", "app/jade", "app/i18n",
}, },
function(toggler) { function(toggler) {
var textarea = $(".textarea", text); var textarea = $(".textarea", text);
var avatar = config["avatar"] ? $(".avatar", el, false)[0] : null; var avatar = config["avatar"] || config["gravatar"] ? $(".avatar", el, false)[0] : null;
if (! toggler.canceled && textarea !== null) { if (! toggler.canceled && textarea !== null) {
if (utils.text(textarea.innerHTML).length < 3) { if (utils.text(textarea.innerHTML).length < 3) {

View File

@ -1,4 +1,7 @@
div(class='isso-comment' id='isso-#{comment.id}') div(class='isso-comment' id='isso-#{comment.id}')
if conf.gravatar
div(class='avatar')
img(src='#{comment.gravatar_image}')
if conf.avatar if conf.avatar
div(class='avatar') div(class='avatar')
svg(data-hash='#{comment.hash}') svg(data-hash='#{comment.hash}')

View File

@ -322,6 +322,7 @@ class TestComments(unittest.TestCase):
rv = loads(rv.data) rv = loads(rv.data)
for key in comments.API.FIELDS: for key in comments.API.FIELDS:
if key in rv:
rv.pop(key) rv.pop(key)
self.assertListEqual(list(rv.keys()), []) self.assertListEqual(list(rv.keys()), [])

View File

@ -110,3 +110,4 @@ def new(conf):
sha1 = Hash(func="sha1").uhash sha1 = Hash(func="sha1").uhash
md5 = Hash(func="md5").uhash

View File

@ -26,6 +26,7 @@ from isso.utils import (http, parse,
render_template) render_template)
from isso.views import requires from isso.views import requires
from isso.utils.hash import sha1 from isso.utils.hash import sha1
from isso.utils.hash import md5
try: try:
from urlparse import urlparse from urlparse import urlparse
@ -92,7 +93,7 @@ def xhr(func):
class API(object): class API(object):
FIELDS = set(['id', 'parent', 'text', 'author', 'website', FIELDS = set(['id', 'parent', 'text', 'author', 'website',
'mode', 'created', 'modified', 'likes', 'dislikes', 'hash']) 'mode', 'created', 'modified', 'likes', 'dislikes', 'hash', 'gravatar_image'])
# comment fields, that can be submitted # comment fields, that can be submitted
ACCEPT = set(['text', 'author', 'website', 'email', 'parent', 'title']) ACCEPT = set(['text', 'author', 'website', 'email', 'parent', 'title'])
@ -303,6 +304,8 @@ class API(object):
self.cache.set( self.cache.set(
'hash', (rv['email'] or rv['remote_addr']).encode('utf-8'), rv['hash']) 'hash', (rv['email'] or rv['remote_addr']).encode('utf-8'), rv['hash'])
rv = self._add_gravatar_image(rv)
for key in set(rv.keys()) - API.FIELDS: for key in set(rv.keys()) - API.FIELDS:
rv.pop(key) rv.pop(key)
@ -729,7 +732,17 @@ class API(object):
comment['replies'] = self._process_fetched_list(replies, plain) comment['replies'] = self._process_fetched_list(replies, plain)
return JSON(rv, 200) return JSON(rv, 200)
def _add_gravatar_image(self, item):
if not self.conf.getboolean('gravatar'):
return item
email = item['email'] or ""
email_md5_hash = md5(email)
gravatar_url = self.conf.get('gravatar-url')
item['gravatar_image'] = gravatar_url.format(email_md5_hash)
return item
def _process_fetched_list(self, fetched_list, plain=False): def _process_fetched_list(self, fetched_list, plain=False):
for item in fetched_list: for item in fetched_list:
@ -742,6 +755,8 @@ class API(object):
item['hash'] = val item['hash'] = val
item = self._add_gravatar_image(item)
for key in set(item.keys()) - API.FIELDS: for key in set(item.keys()) - API.FIELDS:
item.pop(key) item.pop(key)

View File

@ -46,6 +46,14 @@ notify = stdout
# Log console messages to file instead of standard output. # Log console messages to file instead of standard output.
log-file = log-file =
# adds property "gravatar_image" to json response when true
# will automatically build md5 hash by email and use "gravatar_url" to build
# the url to the gravatar image
gravatar = false
# default url for gravatar. {} is where the hash will be placed
gravatar-url = https://www.gravatar.com/avatar/{}?d=identicon
# Admin access password # Admin access password
admin_password = please_choose_a_strong_password admin_password = please_choose_a_strong_password