File tree 4 files changed +48
-21
lines changed
4 files changed +48
-21
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change
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
+ }
File renamed without changes.
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
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' ;
4
5
5
6
export default function FooterWrapper ( props ) {
7
+ const { metadata, isBlogPostPage} = useBlogPost ( ) ;
6
8
return (
7
9
< >
8
10
< Footer { ...props } />
9
- < LikesAndComments { ... props } />
11
+ { isBlogPostPage && ( < Webmentions /> ) }
10
12
</ >
11
13
) ;
12
14
}
You can’t perform that action at this time.
0 commit comments