Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect Single Blog Post UI with dev.to and route users to corresponding single blog post page #216

Closed
mariana-caldas opened this issue Jun 13, 2024 · 2 comments · Fixed by #217

Comments

@mariana-caldas
Copy link
Member

What do we need to build or fix?
We need to implement the logic to connect our single blog post UI with dev.to. This involves automatically pulling content data from dev.to and ensuring users are directed to the corresponding single post page on our Next.js website instead of being redirected to dev.to. This will help keep users on our website longer.

Technical details
1. Set Up API Call to dev.to:

  • Extend the getStaticProps function in pages/blog/posts/[id].js to fetch detailed post content from dev.to using their API.
  • Use the dev.to API to fetch the content for individual blog posts based on their id.

2. Update Single Blog Post UI:

  • Utilize the fetched data in the BlogPostContainer component.
  • Pass the necessary data (title, content, author, etc.) to the BlogPostContainer and PostContent.

3. Routing Logic:

  • Ensure that clicking on a blog post link in the blog post list routes to the new single blog post page using dynamic routing.
  • Update BlogPostsContainer to link to the new [id].js page.

Approach suggestions

import BlogPostContainer from '@/components/blog/BlogPostContainer';
import { useRouter } from 'next/router';

const BlogPost = ({ post }) => {
  const router = useRouter();
  if (router.isFallback) {
    return <div>Loading...</div>;
  }
  return <BlogPostContainer post={post} />;
};

export default BlogPost;

export async function getStaticPaths() {
  const res = await fetch('https://dev.to/api/articles?username=wdp');
  const posts = await res.json();

  const paths = posts.map(post => ({
    params: { id: post.id.toString() },
  }));

  return { paths, fallback: true };
}

export async function getStaticProps({ params }) {
  const res = await fetch(`https://dev.to/api/articles/${params.id}`);
  const post = await res.json();
  const userSummary = post.user.summary;

  return {
    props: {
      post: {
        id: post.id,
        title: post.title,
        cover_image: post.cover_image,
        published_at: post.published_at,
        user: {
          name: post.user.name,
          summary: userSummary,
        },
        body_html: post.body_html,
      },
    },
    revalidate: blogRevalidate,
  };
}

Deadline
Please keep in mind that once you assign this task to yourself, you'll need to complete it in 15 days.

Acceptance criteria

  • Test the routing logic to ensure users are correctly navigated to the single post pages on our website.
  • Test the page and components in many screen sizes, you can use the Inspect tool for that.
  • Please test if the new changes added to the components do not affect the other instances.
  • Test the feature in many browsers, such as Chrome, Firefox, Edge, and Safari (MAC).
  • If there are any build problems when submitting your PR, run yarn build locally to solve the issues and commit the changes.
  • Update the CHANGELOG.md file.
@mariana-caldas mariana-caldas added the help wanted Extra attention is needed label Jun 13, 2024
@mariana-caldas mariana-caldas changed the title Implement Logic to Connect Single Blog Post UI with dev.to and Route Users to Corresponding Page on Next.js Website Connect Single Blog Post UI with dev.to and route users to corresponding single blog post page Jun 13, 2024
@mariana-caldas
Copy link
Member Author

Blocked by PR #215 merge

@cherylli
Copy link
Member

Should we use the slug instead of the id for the URL? It would look nicer and better for seo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants