Skip to content

Commit

Permalink
added blog page
Browse files Browse the repository at this point in the history
  • Loading branch information
said7388 committed Apr 17, 2024
1 parent 621cb2d commit 78c0437
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
25 changes: 25 additions & 0 deletions app/blog/[slug]/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// @flow strict
import { personalData } from "@/utils/data/personal-data";

async function getBlog(slug) {
const res = await fetch(`https://dev.to/api/articles/${personalData.devUsername}/${slug}`)

if (!res.ok) {
throw new Error('Failed to fetch data')
}

const data = await res.json();
return data;
};

async function BlogDetails({params}) {
const slug = params.slug;
const blog = await getBlog(slug);

return (
<div>
</div>
);
};

export default BlogDetails;
9 changes: 3 additions & 6 deletions app/blog/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@
import { personalData } from "@/utils/data/personal-data";
import BlogCard from "../components/homepage/blog/blog-card";

async function getData() {
async function getBlogs() {
const res = await fetch(`https://dev.to/api/articles?username=${personalData.devUsername}`)

if (!res.ok) {
throw new Error('Failed to fetch data')
}

const data = await res.json();

const filtered = data.filter((item) => item?.cover_image).sort(() => Math.random() - 0.5);

return filtered;
return data;
};

async function page() {
const blogs = await getData();
const blogs = await getBlogs();

return (
<div className="py-8">
Expand Down

0 comments on commit 78c0437

Please sign in to comment.