Skip to content

Commit f0c2fae

Browse files
authored
Merge pull request #52 from ansidev/feature/disqus-comment
Feature: Component Disqus for comment
2 parents c61dfe0 + 59623de commit f0c2fae

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed

.github/workflows/deploy_to_netlify.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,15 @@ jobs:
120120
SITE_GA_ID: ${{ vars.SITE_GA_ID }}
121121
SITE_SWETRIX_ID: ${{ vars.SITE_SWETRIX_ID }}
122122
SITE_COUNTER_ANALYTICS_ID: ${{ vars.SITE_COUNTER_ANALYTICS_ID }}
123+
SITE_DISQUS_ID: ${{ vars.SITE_DISQUS_ID }}
123124
shell: bash
124125
run: |
125126
set -e
126127
[[ ${PROD:-false} == "true" ]] && \
127128
OUTPUT=$(GA_ID=$SITE_GA_ID \
128129
SWETRIX_ID=$SITE_SWETRIX_ID \
129130
COUNTER_ANALYTICS_ID=$SITE_COUNTER_ANALYTICS_ID \
131+
DISQUS_ID=$SITE_DISQUS_ID \
130132
pnpm netlify deploy \
131133
--auth ${{ env.NETLIFY_AUTH_TOKEN }} \
132134
--site ${{ env.NETLIFY_SITE_ID }} \

src/components/Disqus.astro

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
interface Props {
3+
siteId: string
4+
pageURL: string
5+
pageIdentifier: string
6+
}
7+
8+
const { siteId, pageURL, pageIdentifier } = Astro.props
9+
---
10+
11+
<div id="disqus_thread"></div>
12+
<script define:vars={{ siteId, pageURL, pageIdentifier }}>
13+
var disqus_config = function () {
14+
this.page.url = pageURL
15+
this.page.identifier = pageIdentifier
16+
}
17+
;(function () {
18+
// DON'T EDIT BELOW THIS LINE
19+
var d = document,
20+
s = d.createElement('script')
21+
s.src = `https://${siteId}.disqus.com/embed.js`
22+
s.setAttribute('data-timestamp', new Date().toString())
23+
;(d.head || d.body).appendChild(s)
24+
})()
25+
</script>
26+
<noscript>
27+
Please enable JavaScript to view the
28+
<a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>
29+
</noscript>

src/configs/site.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,8 @@ export default {
4949
swetrix: {
5050
projectId: env.SWETRIX_ID,
5151
},
52+
disqus: {
53+
siteId: env.DISQUS_ID,
54+
},
5255
}
5356
}

src/layouts/PostLayout.astro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ const { author } = siteConfig
3131
<div class="prose p-4 border max-w-5xl">
3232
<slot />
3333
</div>
34+
<div class="py-8 max-w-5xl">
35+
<slot name="post-footer" />
36+
</div>
3437
</article>
3538
</AppLayout>
3639

src/pages/[slug].astro

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
---
22
import { CollectionEntry, getCollection } from 'astro:content'
33
4+
import Disqus from '@/components/Disqus.astro'
45
import PostLayout from '@/layouts/PostLayout.astro'
6+
import { getPluginConfig, isPluginEnabled } from '@/utils/plugin'
57
68
export async function getStaticPaths() {
79
const allPosts = await getCollection('leetcode-solutions')
@@ -23,4 +25,14 @@ const { Content } = await entry.render()
2325

2426
<PostLayout frontmatter={entry.data}>
2527
<Content />
28+
{
29+
isPluginEnabled('disqus') && (
30+
<Disqus
31+
slot="post-footer"
32+
{...getPluginConfig('disqus')}
33+
pageURL={Astro.url.href}
34+
pageIdentifier={Astro.url.pathname}
35+
/>
36+
)
37+
}
2638
</PostLayout>

0 commit comments

Comments
 (0)