gokerlek / goker-blog

goker-blog-git-main.gokerlek.vercel.app
1 stars 0 forks source link

add next post link #52

Closed onerzafer closed 3 years ago

onerzafer commented 3 years ago

As a user if I finish a post I'd like to navigate to the next post easily.

Acceptance Criteria

Implementation Suggestion In a blog post we can get all the posts and find the index of the current post in the list. If the index is smaller than the length of the posts array then we can get post at the array index one bigger than the current index. If current index is the last one then we don't show the link.

onerzafer commented 3 years ago

Here is a solution suggestion https://github.com/gokerlek/goker-blog/blob/62af663fa8082736c0939ed728f85b4d6ba86540/pages/posts/%5Bslug%5D.js#L28 after this part add

const posts = await getPosts();

update https://github.com/gokerlek/goker-blog/blob/62af663fa8082736c0939ed728f85b4d6ba86540/pages/posts/%5Bslug%5D.js#L29 as this

return {props: {...props, posts}}

then you can update https://github.com/gokerlek/goker-blog/blob/62af663fa8082736c0939ed728f85b4d6ba86540/pages/posts/%5Bslug%5D.js#L10 as like this

const BlogPost = ({ page, menu, footer, posts }) => {
const previousPost = usePreviousPost(page, posts);
const nextPost = useNextPost(page, posts);