Skip to content

Commit a8f725d

Browse files
committed
api endpoint changed
1 parent ac92526 commit a8f725d

File tree

8 files changed

+46
-39
lines changed

8 files changed

+46
-39
lines changed

gatsby-node.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,20 @@ exports.createPages = ({ actions }) => {
108108
},
109109
component: topicPageTemplate,
110110
})
111-
// res.data[topic].map((item, index) => {
112-
// const post = `post-${index}`
113-
// createPage({
114-
// path: `/${topic}/${post}`,
115-
// context: {
116-
// id: index,
117-
// data: item,
118-
// allData: data,
119-
// },
120-
// component: postPageTemplate,
121-
// })
122-
// })
111+
console.log('Hello World')
112+
console.log(res.data[topic])
113+
res.data[topic].map((item, index) => {
114+
const post = `post-${index}`
115+
createPage({
116+
path: `/${topic}/${post}`,
117+
context: {
118+
id: index,
119+
data: item,
120+
allData: res.data,
121+
},
122+
component: postPageTemplate,
123+
})
124+
})
123125
})
124126
})
125127
.catch(err => {

src/components/category.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Card from './card'
66

77
import './category.css'
88

9-
const Category = ({ id, topic, data }) => {
9+
const Category = ({ topic, data }) => {
1010
return (
1111
<div key={topic} className="topic">
1212
<div className="title">
@@ -20,8 +20,14 @@ const Category = ({ id, topic, data }) => {
2020
</h3>
2121
</div>
2222
<ul>
23-
{data.map(({ id, title }, index) => (
24-
<Card key={id} id={index} title={title} index={index} topic={topic} />
23+
{data.map(({ title }, index) => (
24+
<Card
25+
key={title}
26+
id={index}
27+
title={title}
28+
index={index}
29+
topic={topic}
30+
/>
2531
))}
2632
</ul>
2733
</div>

src/components/search.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const Search = ({ input, dataTitle }) => {
1818
key={item.id}
1919
id={item.id}
2020
topic={item.topic}
21-
title={item.title.rendered}
21+
title={item.title}
2222
index={index}
2323
/>
2424
))}

src/components/topic.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@ const Topic = ({ category, topics, curCategory, curPost }) => {
1818
</h4>
1919
{open && (
2020
<ul>
21-
{topics.map(({ id, title }) => (
22-
<li key={id}>
23-
{id === Number(curPost) && <span />}
21+
{topics.map(({ title, date }, index) => (
22+
<li key={String(date)}>
23+
{`${category}/post-${index}` === `${curCategory}/${curPost}` && (
24+
<span />
25+
)}
2426
<Link
25-
className={`${id === Number(curPost) ? `current-post` : ''}`}
26-
to={`/${category}/${id}`}
27-
dangerouslySetInnerHTML={{ __html: sliceCat(title.rendered) }}
27+
className={`${
28+
`${category}/post-${index}` === `${curCategory}/${curPost}`
29+
? `current-post`
30+
: ''
31+
}`}
32+
to={`/${category}/post-${index}`}
33+
dangerouslySetInnerHTML={{ __html: sliceCat(title) }}
2834
/>
2935
</li>
3036
))}

src/templates/PostPage.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { handleLastRead, logInstruction } from '../utils'
99
import './postpage.css'
1010

1111
const PostPage = ({ path, pageContext: { id, data, allData } }) => {
12-
window.log = allData
1312
useEffect(() => {
1413
logInstruction()
1514
handleLastRead({
@@ -20,11 +19,7 @@ const PostPage = ({ path, pageContext: { id, data, allData } }) => {
2019
})
2120
return (
2221
<Layout>
23-
<p>PostPage</p>
24-
{/* <SEO
25-
title={data.title}
26-
description={'একটা শর্টে লেখার অংশবিশেষ'}
27-
/>
22+
<SEO title={data.title} description={'একটা শর্টে লেখার অংশবিশেষ'} />
2823
<div className="post-area">
2924
<Post
3025
allData={allData}
@@ -33,7 +28,7 @@ const PostPage = ({ path, pageContext: { id, data, allData } }) => {
3328
content={data.content}
3429
/>
3530
<Catalog path={path} topics={allData} />
36-
</div> */}
31+
</div>
3732
</Layout>
3833
)
3934
}

src/templates/TopicPage.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { topicTranslation } from '../utils'
77
import './topicpage.css'
88

99
const TopicPage = ({ path, pageContext: { data } }) => {
10-
console.log(data)
1110
const topic = path.replace('/', '')
1211
return (
1312
<Layout>

src/utils/findPrevNextPost.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,28 @@ export const findPrevNextPost = (allData, currentData) => {
66
let nextPost = null
77

88
for (let i = 0; i < allData[category].length; i++) {
9-
if (allData[category][i].id === Number(id)) {
10-
if (allData[category][0].id === Number(id)) {
9+
if (`post-${i}` === id) {
10+
if (`post-${0}` === id) {
1111
prevPost = null
1212
} else {
1313
prevPost = {
14-
id: allData[category][i - 1].id,
14+
id: `post-${i - 1}`,
1515
title: allData[category][i - 1].title,
1616
category: category,
1717
}
1818
}
19-
if (allData[category][allData[category].length - 1].id === Number(id)) {
19+
if (`post-${allData[category].length - 1}` === id) {
2020
nextPost = null
2121
} else {
2222
nextPost = allData[category][i + 1] && {
23-
id: allData[category][i + 1].id,
23+
id: `post-${i + 1}`,
2424
title: allData[category][i + 1].title,
2525
category: category,
2626
}
2727
}
2828
break
2929
}
3030
}
31-
3231
return [prevPost, nextPost]
3332
} else {
3433
return [null, null]

src/utils/searchMatch.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
export const searchMatch = (allData, term) => {
22
return Object.keys(allData)
33
.map(key =>
4-
allData[key].map(item => {
4+
allData[key].map((item, index) => {
55
if (
6-
String(item.title.rendered)
6+
String(item.title)
77
.toLowerCase()
88
.includes(term)
99
) {
1010
return {
1111
title: item.title,
1212
topic: key,
13-
id: item.id,
13+
id: index,
1414
}
1515
}
1616
return 0

0 commit comments

Comments
 (0)