Web-Dev-Path / web-dev-path

The Web Dev Path platform. Progressive Web App (PWA). Next.js rules!
https://webdevpath.co
GNU General Public License v3.0
33 stars 11 forks source link

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

Closed mariana-caldas closed 1 month ago

mariana-caldas commented 3 months ago

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:

2. Update Single Blog Post UI:

3. Routing Logic:

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

mariana-caldas commented 3 months ago

Blocked by PR #215 merge

cherylli commented 3 months ago

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