Skip to content

Commit 3842a4e

Browse files
authored
Fix broken profile images on webmentions (#191)
1 parent 84c0154 commit 3842a4e

7 files changed

Lines changed: 19 additions & 8 deletions

File tree

src/_includes/macros.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@
367367
">
368368
<div class="webmention__author p-author h-card">
369369
{% if c.avatar %}
370-
<img class="webmention__author__photo u-photo" src="https://res.cloudinary.com/aarongustafson/image/fetch/c_fill,f_auto,q_auto,w_48,h_48/{{ c.avatar }}" width="48" height="48" alt="" title="{{ c.author }}" loading="lazy">
370+
<img class="webmention__author__photo u-photo" src="https://res.cloudinary.com/aarongustafson/image/fetch/c_fill,f_auto,q_auto,w_48,h_48/{{ c.avatar }}" width="48" height="48" alt="" title="{{ c.author }}" loading="lazy" data-responsiver="false">
371371
{% endif %}
372372
<b class="p-name">{{ c.author }}</b>
373373
</div>

src/_includes/partials/post/comment.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
">
66
<div class="webmention__author p-author h-card">
77
{% if comment.avatar %}
8-
<img class="webmention__author__photo u-photo" src="https://res.cloudinary.com/aarongustafson/image/fetch/c_fill,f_auto,q_auto,w_48,h_48/{{ comment.avatar }}" width="48" height="48" alt="" title="{{ comment.author }}" loading="lazy">
8+
<img class="webmention__author__photo u-photo" src="https://res.cloudinary.com/aarongustafson/image/fetch/c_fill,f_auto,q_auto,w_48,h_48/{{ comment.avatar }}" width="48" height="48" alt="" title="{{ comment.author }}" loading="lazy" data-responsiver="false">
99
{% endif %}
1010
<b class="p-name">{{ comment.author }}</b>
1111
</div>

src/_includes/partials/post/linkedface.njk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<div class="webmention__author p-author h-card">
22
<a class="u-url" href="{{ webmention.author.url }}" rel="nofollow">
3-
<img class="webmention__author__photo u-photo" src="https://res.cloudinary.com/aarongustafson/image/fetch/c_fill,f_auto,q_auto,w_48,h_48/{{ webmention.author.photo | replace('http://pbs.twimg.com', 'https://pbs.twimg.com') }}" width="48" height="48" alt="{% if show_name %}{% else %}{{ webmention.author.name }}{% endif %}" title="{{ webmention.author.name }}" loading="lazy">
3+
{% if webmention.author.photo %}
4+
<img class="webmention__author__photo u-photo" src="https://res.cloudinary.com/aarongustafson/image/fetch/c_fill,f_auto,q_auto,w_48,h_48/{{ webmention.author.photo | urlencode }}" width="48" height="48" alt="{% if show_name %}{% else %}{{ webmention.author.name }}{% endif %}" title="{{ webmention.author.name }}" loading="lazy" data-responsiver="false">
5+
{% endif %}
46
{% if show_name %}
57
<b class="p-name">{{ webmention.author.name }}</b>
68
{% endif %}

src/_includes/partials/webmentions/likes.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<li id="webmention-{{ webmention.id }}" class="webmentions__item webmention webmention--{{ webmention.type }}">
66
<div class="webmention__author p-author h-card">
77
<a class="u-url" href="{{ webmention.author.url }}">
8-
<img class="webmention__author__photo u-photo" src="https://res.cloudinary.com/aarongustafson/image/fetch/c_fill,f_auto,q_auto,w_48,h_48/{{ webmention.author.photo }}" alt="" title="{{ webmention.author.name }}" loading="lazy">
8+
<img class="webmention__author__photo u-photo" src="https://res.cloudinary.com/aarongustafson/image/fetch/c_fill,f_auto,q_auto,w_48,h_48/{{ webmention.author.photo | urlencode }}" alt="" title="{{ webmention.author.name }}" loading="lazy" data-responsiver="false">
99
</a>
1010
</div>
1111
</li>

src/_includes/partials/webmentions/reposts.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<li id="webmention-{{ webmention.id }}" class="webmentions__item webmention webmention--{{ webmention.type }}">
66
<div class="webmention__author p-author h-card">
77
<a class="u-url" href="{{ webmention.author.url }}">
8-
<img class="webmention__author__photo u-photo" src="https://res.cloudinary.com/aarongustafson/image/fetch/c_fill,f_auto,q_auto,w_48,h_48/{{ webmention.author.photo }}" alt="" title="{{ webmention.author.name }}" loading="lazy">
8+
<img class="webmention__author__photo u-photo" src="https://res.cloudinary.com/aarongustafson/image/fetch/c_fill,f_auto,q_auto,w_48,h_48/{{ webmention.author.photo | urlencode }}" alt="" title="{{ webmention.author.name }}" loading="lazy" data-responsiver="false">
99
</a>
1010
</div>
1111
</li>

src/_javascript/post/WebmentionIO.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,17 @@ WebmentionIO.types = {
295295
}
296296
}
297297

298-
// Process author photos
298+
// Process author photos - wrap in Cloudinary fetch to match server-side rendering
299+
var cloudinaryPrefix =
300+
"https://res.cloudinary.com/aarongustafson/image/fetch/c_fill,f_auto,q_auto,w_48,h_48/";
299301
var authorPhotos = temp.querySelectorAll("[data-mention-author-photo]");
300302
for (var k = 0; k < authorPhotos.length; k++) {
301303
var photoUrl = authorPhotos[k].getAttribute("data-mention-author-photo");
302304
if (photoUrl) {
303-
authorPhotos[k].setAttribute("src", photoUrl);
305+
authorPhotos[k].setAttribute(
306+
"src",
307+
cloudinaryPrefix + encodeURIComponent(photoUrl),
308+
);
304309
authorPhotos[k].removeAttribute("data-mention-author-photo");
305310
}
306311
}

src/_javascript/post/social-media-avatars.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
"use strict";
55

66
if ("addEventListener" in window && document.getElementById("webmentions")) {
7-
window.addEventListener("load", init, false);
7+
if (document.readyState === "complete") {
8+
init();
9+
} else {
10+
window.addEventListener("load", init, false);
11+
}
812
}
913

1014
function logDebug() {

0 commit comments

Comments
 (0)