diff --git a/src/theme/BlogPostItem/Footer/LikesAndComments/index.js b/src/theme/BlogPostItem/Footer/LikesAndComments/index.js deleted file mode 100644 index af8562e..0000000 --- a/src/theme/BlogPostItem/Footer/LikesAndComments/index.js +++ /dev/null @@ -1,19 +0,0 @@ -import React, {useState, useEffect} from 'react'; -import './style.css'; - -export default function LikesAndComments(props) { - const [webmentionCount, setWebmentionCount] = useState(0); - - useEffect(() => { - fetch(`https://webmention.io/api/count?target=${window.location.href}`) - .then(response => response.json()) - .then(data => setWebmentionCount(data.count)) - .catch(error => console.log(error)) - }, []) - - return ( - <> -
{webmentionCount}
- > - ) -} diff --git a/src/theme/BlogPostItem/Footer/Webmentions/index.js b/src/theme/BlogPostItem/Footer/Webmentions/index.js new file mode 100644 index 0000000..f5983b5 --- /dev/null +++ b/src/theme/BlogPostItem/Footer/Webmentions/index.js @@ -0,0 +1,44 @@ +import React, {useState, useEffect} from 'react'; +import './style.css'; + +function Spacer() { + return ; +} +export default function Webmentions(props) { + const [webmentions, setWebmentions] = useState({}); + const baseUrl = 'https://webmention.io/api'; + const countEndpoint = (target) => `${baseUrl}/count?target=${target}`; + const mentionEndpoint = (target) => `${baseUrl}/mentions.jf2?target=${target}`; + const postUrl = window.location.href; + + useEffect(() => { + const webmentionCount = fetch(countEndpoint(postUrl)) + .then(response => response.json()) + .then(data => data.count) + .catch(error => console.log(error)) + + const webmentionAuthors = fetch(mentionEndpoint(postUrl)) + .then(response => response.json()) + .then(data => data.children) + .then(mentions => mentions.map(mention => mention.author)) + .catch(error => console.log(error)) + + Promise.all([webmentionCount, webmentionAuthors]) + .then(([count, authors]) => setWebmentions({ + 'count': count, + 'authors': authors + })) + .catch(error => console.log(error)) + }, []) + + return ( + <> +Mentioned by {webmentions.authors[0].name}
+