diff --git a/pages/blog.js b/pages/blog.js index d3599b4..8c79c12 100644 --- a/pages/blog.js +++ b/pages/blog.js @@ -15,21 +15,28 @@ const Blog = () => { pagination(".single_box_", sort, active); let list = document.querySelectorAll(".single_box_"); setstate(getPagination(list.length, sort)); + window.scrollTo({ + top: 0, + behavior: "smooth" // smooth scrolling effect + }); + }, [active]); - + const sortedBlogs = [...BlogData].sort((a, b) => new Date(b.date) - new Date(a.date)); return ( <> - +
{ - BlogData?.map((blog) => { + sortedBlogs?.map((blog) => { return (
diff --git a/src/components/Home/BlogSection.js b/src/components/Home/BlogSection.js index 8d83f40..be50db1 100644 --- a/src/components/Home/BlogSection.js +++ b/src/components/Home/BlogSection.js @@ -2,6 +2,9 @@ import { BlogData } from "@/utils/constant.utils"; import Link from "next/link"; const BlogSection = () => { + + const sortedBlogs = [...BlogData].sort((a, b) => new Date(b.date) - new Date(a.date)).slice(0, 3); + return (
@@ -15,7 +18,7 @@ const BlogSection = () => {
{ - BlogData?.slice(0, 3)?.map((blog) => { + sortedBlogs?.map((blog) => { return (
@@ -26,9 +29,11 @@ const BlogSection = () => { {blog?.slug}
*/}
-

{blog?.title.length > 50 - ? blog.title.substring(0, 50) + '...' - : blog.title}

+

+ {blog?.title.length > 50 + ? blog.title.substring(0, 50) + '...' + : blog.title} +

{blog?.date}