Skip to content

Commit 2849ea5

Browse files
authored
Merge pull request #133 from 5ym/main
Fix CORS Error for disqus
2 parents 4e7a3c4 + 53a7617 commit 2849ea5

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

.changeset/light-maps-remain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'pliny': patch
3+
---
4+
5+
Corrected cors error in disqus

packages/pliny/src/comments/Disqus.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useTheme } from 'next-themes'
12
import { useEffect, useCallback } from 'react'
23

34
export interface DisqusConfig {
@@ -12,28 +13,25 @@ export type DisqusProps = DisqusConfig['disqusConfig'] & {
1213
}
1314

1415
export const Disqus = ({ shortname, slug }: DisqusProps) => {
16+
const { theme } = useTheme()
17+
1518
const COMMENTS_ID = 'disqus_thread'
1619

1720
const LoadComments = useCallback(() => {
18-
//@ts-ignore
1921
window.disqus_config = function () {
2022
this.page.url = window.location.href
2123
this.page.identifier = slug
2224
}
23-
//@ts-ignore
2425
if (window.DISQUS === undefined) {
2526
const script = document.createElement('script')
2627
script.src = 'https://' + shortname + '.disqus.com/embed.js'
27-
// @ts-ignore
28-
script.setAttribute('data-timestamp', +new Date())
29-
script.setAttribute('crossorigin', 'anonymous')
28+
script.setAttribute('data-timestamp', Date.now().toString())
3029
script.async = true
3130
document.body.appendChild(script)
3231
} else {
33-
//@ts-ignore
34-
window.DISQUS.reset({ reload: true })
32+
;(window as any).DISQUS.reset({ reload: true })
3533
}
36-
}, [shortname, slug])
34+
}, [shortname, slug, theme])
3735

3836
useEffect(() => {
3937
LoadComments()

0 commit comments

Comments
 (0)