mirror of
https://github.com/BradNut/awesome-uses
synced 2025-09-08 17:40:31 +00:00
Utilizing Webfinger to pull avatars from Mastodon
This commit is contained in:
parent
1915628371
commit
7ba14d560f
1 changed files with 16 additions and 4 deletions
|
|
@ -9,15 +9,27 @@ export default function Person({ person }) {
|
||||||
const twitter = person.twitter
|
const twitter = person.twitter
|
||||||
? `https://unavatar.io/${person.twitter.replace('@', '')}`
|
? `https://unavatar.io/${person.twitter.replace('@', '')}`
|
||||||
: null;
|
: null;
|
||||||
const mastodonArr = person.mastodon
|
|
||||||
? person.mastodon.replace('@', '').split('@')
|
|
||||||
: null;
|
|
||||||
const website = `https://unavatar.io/${url.host}`;
|
const website = `https://unavatar.io/${url.host}`;
|
||||||
const unavatar = person.twitter
|
const unavatar = person.twitter
|
||||||
? `${twitter}?fallback=${website}&ttl=28d`
|
? `${twitter}?fallback=${website}&ttl=28d`
|
||||||
: website;
|
: website;
|
||||||
// const img = `https://images.weserv.nl/?url=${unavatar}&w=100&l=9&af&il&n=-1`;
|
// const img = `https://images.weserv.nl/?url=${unavatar}&w=100&l=9&af&il&n=-1`;
|
||||||
const img = unavatar;
|
const mastodonArr = person.mastodon
|
||||||
|
? person.mastodon.replace('@', '').split('@')
|
||||||
|
: null;
|
||||||
|
const webfinger =
|
||||||
|
person.mastodon
|
||||||
|
? JSON.parse(`https://${mastodonArr[0]}/.well-known/webfinger?resource=https://${mastodonArr[0]}/@${mastodonArr[1]}`)
|
||||||
|
: null;
|
||||||
|
const wfIndex =
|
||||||
|
person.mastodon && webfinger
|
||||||
|
? webfinger.links.findIndex((link) => link.rel === 'http://webfinger.net/rel/avatar')
|
||||||
|
: null;
|
||||||
|
const wfAvatar =
|
||||||
|
person.mastodon && wfIndex
|
||||||
|
? webfinger.links[wfIndex].href
|
||||||
|
: website;
|
||||||
|
const img = person.twitter ? unavatar : (person.mastodon ? wfAvatar : website);
|
||||||
const { tag: currentTag } = useParams();
|
const { tag: currentTag } = useParams();
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue