Skip to content

Commit e2f5f31

Browse files
committed
blog: add webmention text, remove webmentions from bloglist
1 parent 8d34f2c commit e2f5f31

File tree

4 files changed

+48
-21
lines changed

4 files changed

+48
-21
lines changed

src/theme/BlogPostItem/Footer/LikesAndComments/index.js

-19
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React, {useState, useEffect} from 'react';
2+
import './style.css';
3+
4+
function Spacer() {
5+
return <p></p>;
6+
}
7+
export default function Webmentions(props) {
8+
const [webmentions, setWebmentions] = useState({});
9+
const baseUrl = 'https://webmention.io/api';
10+
const countEndpoint = (target) => `${baseUrl}/count?target=${target}`;
11+
const mentionEndpoint = (target) => `${baseUrl}/mentions.jf2?target=${target}`;
12+
const postUrl = window.location.href;
13+
14+
useEffect(() => {
15+
const webmentionCount = fetch(countEndpoint(postUrl))
16+
.then(response => response.json())
17+
.then(data => data.count)
18+
.catch(error => console.log(error))
19+
20+
const webmentionAuthors = fetch(mentionEndpoint(postUrl))
21+
.then(response => response.json())
22+
.then(data => data.children)
23+
.then(mentions => mentions.map(mention => mention.author))
24+
.catch(error => console.log(error))
25+
26+
Promise.all([webmentionCount, webmentionAuthors])
27+
.then(([count, authors]) => setWebmentions({
28+
'count': count,
29+
'authors': authors
30+
}))
31+
.catch(error => console.log(error))
32+
}, [])
33+
34+
return (
35+
<>
36+
<Spacer />
37+
{webmentions.count > 0 && (
38+
<div className='webmentions'>
39+
<p className='webmention-counter'>Mentioned by <b>{webmentions.authors[0].name}</b></p>
40+
</div>
41+
)}
42+
</>
43+
)
44+
}
+4-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import React from 'react';
22
import Footer from '@theme-original/BlogPostItem/Footer';
3-
import LikesAndComments from '@site/src/theme/BlogPostItem/Footer/LikesAndComments';
3+
import Webmentions from '@site/src/theme/BlogPostItem/Footer/Webmentions';
4+
import {useBlogPost} from '@docusaurus/theme-common/internal';
45

56
export default function FooterWrapper(props) {
7+
const {metadata, isBlogPostPage} = useBlogPost();
68
return (
79
<>
810
<Footer {...props} />
9-
<LikesAndComments {...props} />
11+
{isBlogPostPage && (<Webmentions />)}
1012
</>
1113
);
1214
}

0 commit comments

Comments
 (0)