Skip to content

Commit d0034e8

Browse files
authored
Merge pull request #24 from imranhsayed/feature/add-disqus-comments
Add disqus comment
2 parents f295d8e + 1214473 commit d0034e8

File tree

9 files changed

+41
-6
lines changed

9 files changed

+41
-6
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ docker-compose -f backend/docker-compose.yml up -d
1717

1818
Backend will be available on port `http://localhost:8020`
1919

20+
* If you happen to use your own WordPress setup, be sure to install and activate plugins from composer.json and add your own WordPress site URL
21+
in an .env file, You can check the .env-example file for reference.
22+
2023
## [Frontend](https://github.com/imranhsayed/nextjs-headless-wordpress/tree/master/frontend)
2124
Run this from root for the first time.
2225
```bash
2326
cd frontend; npm i && npm run dev
2427
```
2528

26-
* If you happen to use your own WordPress setup, be sure to install and activate plugins from composer.json and add your own WordPress site URL
27-
in an .env file, You can check the .env-example file for reference.
28-
2929
### During development
3030
```bash
3131
cd frontend; npm run dev
@@ -34,7 +34,7 @@ cd frontend; npm run dev
3434
Frontend will be available on port `http://localhost:3000`
3535

3636
### Evironment vars.
37-
rename .env-example to .env inside frontend directory and add your WordPress Site URL ( for local developent pull `http://localhost:8020` as your WordPress URL)
37+
Create a `.env` file taking reference from `.env-example` inside frontend directory and add your WordPress Site URL ( for local development put `http://localhost:8020` as your WordPress URL)
3838

3939
## Development ( Developers only )
4040

frontend/.env-example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
NEXT_PUBLIC_WORDPRESS_SITE_URL=http://localhost:8020
2+
NEXT_PUBLIC_NEXTJS_SITE_URL=http://localhost:3000
3+
NEXT_PUBLIC_DISQUS_SHORTNAME=xxxx

frontend/package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"homepage": "https://github.com/imranhsayed/nextjs-wordpress-theme#readme",
2323
"dependencies": {
2424
"@apollo/client": "^3.1.4",
25+
"disqus-react": "^1.0.10",
2526
"dompurify": "^2.0.15",
2627
"graphql": "^15.3.0",
2728
"lodash": "^4.17.20",

frontend/pages/blog/[slug].js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Layout from "../../src/components/layout";
44
import { GET_POST_SLUGS } from "../../src/queries/get-posts";
55
import { sanitize } from "../../src/utils/functions";
66
import Image from "../../src/components/image";
7+
import DisqusComment from "../../src/components/blog/discuss-comments";
78

89
const SingleBlog = ({menus, post, path}) => {
910
return (
@@ -18,6 +19,7 @@ const SingleBlog = ({menus, post, path}) => {
1819
</div>
1920
<div className="w-1/4"/>
2021
</div>
22+
<DisqusComment post={post}/>
2123
</Layout>
2224
)
2325
}
@@ -48,6 +50,8 @@ export async function getStaticPaths() {
4850

4951
const pathsData = [];
5052

53+
console.warn( 'pathsData', pathsData );
54+
5155
data.posts.edges.map( post => {
5256
pathsData.push(
5357
{ params: { slug: post.node.slug } }
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {DiscussionEmbed} from "disqus-react"
2+
3+
const DisqusComment = ({ post }) => {
4+
const disqusShortname = process.env.NEXT_PUBLIC_DISQUS_SHORTNAME;
5+
const disqusConfig = {
6+
url: `${process.env.NEXT_PUBLIC_NEXTJS_SITE_URL}/blog/${post?.slug}`,
7+
identifier: post.id,
8+
title: post.title
9+
}
10+
11+
return (
12+
<div>
13+
<DiscussionEmbed
14+
shortname={disqusShortname}
15+
config={disqusConfig}
16+
/>
17+
</div>
18+
)
19+
}
20+
21+
export default DisqusComment;

frontend/src/components/blog/posts/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ const Posts = ({posts}) => {
1212
{
1313
( posts?.edges ?? []).map((post) => {
1414
return (
15-
<div className="w-1/3 mb-4 px-2">
16-
<Post key={post?.node?.id ?? ""} post={post.node}/>
15+
<div key={post?.node?.id ?? ""} className="w-1/3 mb-4 px-2">
16+
<Post post={post?.node}/>
1717
</div>
1818
);
1919
})

frontend/src/queries/get-post.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const GET_POST = gql`
2828
title
2929
excerpt
3030
content
31+
slug
3132
large: featuredImage {
3233
node {
3334
...ImageLargeFragment

frontend/src/queries/get-posts.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const GET_POSTS = gql`
2929
id
3030
title
3131
excerpt
32+
slug
3233
mediumLarge: featuredImage {
3334
node {
3435
...ImageMediumLargeFragment

0 commit comments

Comments
 (0)