diff --git a/app/api/blogs/route.js b/app/api/blogs/route.js
new file mode 100644
index 0000000..03e2085
--- /dev/null
+++ b/app/api/blogs/route.js
@@ -0,0 +1,16 @@
+import { NextResponse } from "next/server";
+import axios from "axios";
+import { backendUrl } from "@/utils/axios";
+
+export async function GET() {
+ try {
+ const response = await axios.get(`${backendUrl}/blogs/`);
+ return NextResponse.json(response.data);
+ } catch (error) {
+ console.error("Error fetching blogs:", error);
+ return NextResponse.json(
+ { error: "Failed to fetch blog data" },
+ { status: 500 }
+ );
+ }
+}
diff --git a/app/api/blogs[slug]/route.js b/app/api/blogs[slug]/route.js
new file mode 100644
index 0000000..80e0353
--- /dev/null
+++ b/app/api/blogs[slug]/route.js
@@ -0,0 +1,19 @@
+import { NextResponse } from "next/server";
+import axios from "axios";
+import { backendUrl } from "@/utils/axios";
+
+export async function GET(request, { params }) {
+ const { slug } = params;
+
+ try {
+ console.log(`API route fetching blog with slug: ${slug}`);
+ const response = await axios.get(`${backendUrl}/blogs/${slug}/`);
+ return NextResponse.json(response.data);
+ } catch (error) {
+ console.error(`Error fetching blog with slug ${slug}:`, error);
+ return NextResponse.json(
+ { error: `Failed to fetch blog: ${error.message}` },
+ { status: error.response?.status || 500 }
+ );
+ }
+}
diff --git a/app/blogs/blog[slug]/page.jsx b/app/blogs/blog[slug]/page.jsx
new file mode 100644
index 0000000..6a6c6e6
--- /dev/null
+++ b/app/blogs/blog[slug]/page.jsx
@@ -0,0 +1,14 @@
+"use client";
+import React from "react";
+import SingleBlog from "@/components/blog/SingleBlog";
+import { useParams } from "next/navigation";
+
+export default function BlogPage() {
+ const params = useParams();
+ const slug = params?.["blog-id"];
+
+ console.log("BlogPage params:", params);
+ console.log("BlogPage slug:", slug);
+
+ return ;
+}
diff --git a/app/dummyData.js b/app/dummyData.js
index c3b60c2..cb5371f 100644
--- a/app/dummyData.js
+++ b/app/dummyData.js
@@ -2,11 +2,11 @@ export const DASHBOARD = {
"images": [
{
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
{
"id": 2,
- "path": "page_images/2.jpg",
+ "path": "/page_images/2.jpg",
},
],
"heading1": "Explore Gupta Rudraksha",
@@ -19,35 +19,35 @@ export const DASHBOARD = {
"title": "Since 1973",
"image": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
},
{
"title": "Vedic Energization",
"image": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
},
{
"title": "Lab Certification",
"image": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
},
{
"title": "ISO 9001:2015 certified",
"image": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
},
{
"title": "Secure Payment",
"image": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
},
],
@@ -58,21 +58,21 @@ export const DASHBOARD = {
{
"image": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
"title": "Spirituality",
},
{
"image": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
"title": "Meditation",
},
{
"image": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
"title": "Wellness",
},
@@ -84,11 +84,11 @@ export const DASHBOARD = {
"heading8": "Gupta Rudraksha - The Only Vendor in the World To 100% Lifetime Money Back Authenticity Guarantee.",
"footer_image1": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
"footer_image2": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
}
@@ -112,7 +112,7 @@ export const CONSULTATION = {
"description": "Enhance personal growth, gain clarity, and overcome obstacles.",
"image": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
},
{
@@ -120,7 +120,7 @@ export const CONSULTATION = {
"description": "Scale your business, improve operations, and navigate challenges.",
"image": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
},
{
@@ -128,7 +128,7 @@ export const CONSULTATION = {
"description": "Plan your career, enhance job search strategies, and build professional skills.",
"image": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
},
{
@@ -136,7 +136,7 @@ export const CONSULTATION = {
"description": "Navigate significant life changes and find new directions for personal fulfillment.",
"image": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
},
{
@@ -144,7 +144,7 @@ export const CONSULTATION = {
"description": "Optimize health, wellness, and live a balanced lifestyle.",
"image": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
},
{
@@ -152,7 +152,7 @@ export const CONSULTATION = {
"description": "Resolve conflicts, improve communication, and build healthier relationships.",
"image": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
},
{
@@ -160,7 +160,7 @@ export const CONSULTATION = {
"description": "Optimize finances, plan for retirement, and grow wealth.",
"image": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
},
{
@@ -168,7 +168,7 @@ export const CONSULTATION = {
"description": "Overcome feeling stuck, gain perspective, and find purpose.",
"image": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
},
],
@@ -179,11 +179,11 @@ export const CONSULTATION = {
"description": "Consultation provides access to expert advice and guidance from professionals who have in-depth knowledge and experience in their respective fields. We can offer valuable insights, strategies, and solutions tailored to your specific needs.",
"image1": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
"image2": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
},
{
@@ -191,11 +191,11 @@ export const CONSULTATION = {
"description": "Rudraksha experts can recommend specific mantras that align with your spiritual goals and intentions. Mantras are considered powerful tools for spiritual growth, and the right mantra can enhance the effectiveness of your Rudraksha.",
"image1": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
"image2": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
},
{
@@ -203,11 +203,11 @@ export const CONSULTATION = {
"description": "Rudraksha experts may also have knowledge of Vedic astrology. By analyzing your birth chart, they can provide insights into the planetary influences on your life and suggest Rudraksha combinations that may help balance and harmonize these influences.",
"image1": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
"image2": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
},
{
@@ -215,11 +215,11 @@ export const CONSULTATION = {
"description": "Understanding the birth charts of family members can offer a holistic view of the energy dynamics within the family. Rudraksha experts can provide guidance on selecting Rudraksha beads that complement the energy of the entire family, fostering a harmonious environment.",
"image1": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
"image2": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
},
{
@@ -227,11 +227,11 @@ export const CONSULTATION = {
"description": "Understanding the birth charts of family members can offer a holistic view of the energy dynamics within the family. Rudraksha experts can provide guidance on selecting Rudraksha beads that complement the energy of the entire family, fostering a harmonious environment.",
"image1": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
"image2": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
},
{
@@ -239,11 +239,11 @@ export const CONSULTATION = {
"description": "Understanding the birth charts of family members can offer a holistic view of the energy dynamics within the family. Rudraksha experts can provide guidance on selecting Rudraksha beads that complement the energy of the entire family, fostering a harmonious environment.",
"image1": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
"image2": {
"id": 1,
- "path": "page_images/1.jpg",
+ "path": "/page_images/1.jpg",
},
},
],
diff --git a/components/blog/BlogHome.jsx b/components/blog/BlogHome.jsx
index 16d0653..825540b 100644
--- a/components/blog/BlogHome.jsx
+++ b/components/blog/BlogHome.jsx
@@ -1,39 +1,55 @@
"use client";
-import React, { useState } from "react";
+import React, { useState, useEffect } from "react";
import { Card, CardHeader, CardContent } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import Link from "next/link";
import Image from "next/image";
+import axios from "axios";
+import { backendUrl } from "@/utils/axios";
+import DOMPurify from 'dompurify';
-const BlogPost = ({ title, author, date, excerpt, imageUrl }) => (
-
-
-
-
{
+ const sanitizedExcerpt = DOMPurify.sanitize(excerpt);
+
+ const formattedImageUrl = imageUrl !== "NA"
+ ? (imageUrl.startsWith('http') ? imageUrl : `${backendUrl}${imageUrl}`)
+ : "/api/placeholder/300/200";
+
+ return (
+
+
+
+
+
+
+
+
+
{title}
+
+
+ {author} | {date}
+
+
-
+
-
-
-
{title}
-
-
- {author} | {date}
-
-
{excerpt}
-
-
-);
+ );
+};
-const PopularArticle = ({ title, author, date }) => (
+const PopularArticle = ({ title, author, date, slug }) => (
-
{title}
+
+
{title}
+
{author} | {date}
@@ -42,63 +58,77 @@ const PopularArticle = ({ title, author, date }) => (
const BlogHome = () => {
const [currentPage, setCurrentPage] = useState(1);
+ const [blogData, setBlogData] = useState({
+ recentBlogPosts: [],
+ popularArticles: []
+ });
+ const [loading, setLoading] = useState(true);
+ const [error, setError] = useState(null);
const postsPerPage = 3;
- const recentBlogPosts = [
- {
- title: "Benefits of Wearing Rudraksha Mala",
- author: "Gupta Rudraksha",
- date: "29 August, 2024",
- excerpt:
- "Rudraksha are sacred beads of great significance in Hinduism and various spiritual practices. The term Rudraksha combines two Sanskrit words: 'Rudra,' another name for Lord Sh...",
- imageUrl: "/blogs/significance-of-dhanteras.webp",
- },
- {
- title: "Shravan Maas for Spiritual Growth and Divine Connection",
- author: "Gupta Rudraksha",
- date: "04 September, 2024",
- excerpt:
- "Shrawan Mass, a sacred month in the Hindu calendar, holds deep spiritual significance for millions of devotees. But what exactly is Shravan Maas, and why is it so important? Let...",
- imageUrl: "/blogs/navaratri-siginificance.webp",
- },
- {
- title: "The Complete Guide to Rudraksha Energization",
- author: "Gupta Rudraksha",
- date: "28 August, 2024",
- excerpt:
- "For centuries, Rudraksha beads have been valued not only for their aesthetic beauty, but also for their powerful spiritual and healing properties. Whether you're a seasoned prac...",
- imageUrl: "/blogs/rudraksha-pran-pratishtha-pooja.webp",
- },
- {
- title: "Strengthening Planetary Forces with Rudraksha",
- author: "Gupta Rudraksha",
- date: "26 April, 2024",
- excerpt:
- "In the vast universe, planets hold immense power over our lives, influencing everything from our moods to our destinies. However, Rudraksha beads, ancient treasures from the ear...",
- imageUrl: "/api/placeholder/300/200",
- },
- ];
+ useEffect(() => {
+ const fetchBlogData = async () => {
+ try {
+ setLoading(true);
+ const response = await axios.get(`${backendUrl}/blogs/`);
+ setBlogData(response.data);
+ setLoading(false);
+ } catch (err) {
+ console.error("Error fetching blog data:", err);
+ setError("Failed to load blog data. Please try again later.");
+ setLoading(false);
+ }
+ };
- const popularArticles = [
- {
- title: "Dhanteras Significance and How Rudraksha Brings Prosperity",
- author: "Gupta Rudraksha",
- date: "30 September, 2024",
- },
- {
- title:
- "Certified Rudraksha: Nepal's 1st ISO 9001:2015 Certified Organization",
- author: "Gupta Admin",
- date: "30 September, 2024",
- },
- ];
+ fetchBlogData();
+ }, []);
+
+ // Get featured blog (first blog from recent posts)
+ const featuredBlog = blogData.recentBlogPosts && blogData.recentBlogPosts.length > 0
+ ? blogData.recentBlogPosts[0]
+ : null;
+
+ // Get remaining blogs for pagination
+ const remainingBlogs = blogData.recentBlogPosts && blogData.recentBlogPosts.length > 0
+ ? blogData.recentBlogPosts.slice(1)
+ : [];
const indexOfLastPost = currentPage * postsPerPage;
const indexOfFirstPost = indexOfLastPost - postsPerPage;
- const currentPosts = recentBlogPosts.slice(indexOfFirstPost, indexOfLastPost);
+ const currentPosts = remainingBlogs.slice(indexOfFirstPost, indexOfLastPost);
const paginate = (pageNumber) => setCurrentPage(pageNumber);
+ const featuredImageUrl = featuredBlog && featuredBlog.imageUrl !== "NA"
+ ? (featuredBlog.imageUrl.startsWith('http') ? featuredBlog.imageUrl : `${backendUrl}${featuredBlog.imageUrl}`)
+ : "/api/placeholder/300/200";
+
+ if (loading) {
+ return
Loading blogs...
;
+ }
+
+ if (error) {
+ return
{error}
;
+ }
+
+ // Check if there are no blogs at all
+ if (!blogData.recentBlogPosts || blogData.recentBlogPosts.length === 0) {
+ return (
+
+
+ Insights from Gupta Rudraksha
+
+
+
No Blogs Found
+
+ We're currently working on creating insightful content for you.
+ Please check back later for updates on Rudraksha and spiritual practices.
+
+
+
+ );
+ }
+
return (
@@ -108,73 +138,88 @@ const BlogHome = () => {
Explore our latest articles on the spiritual, cultural, and healing
aspects
- {/* top container for one blog card */}
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+ {featuredBlog.title}
+
+
+
+ {featuredBlog.author} | {featuredBlog.date}
+
+
-
+
-
-
-
- Dhanteras Significance and How Rudraksha Brings Prosperity and
- Protection
-
-
-
- Gupta Rudraksha | 30 September, 2024
-
-
- Dhanteras, the first day of Diwali festival, marks a unique
- celebration of wealth and prosperity in Hindu tradition. As the
- name suggests - 'Dhan' meaning wealth and
- 'Teras' ref
-
-
-
-
-
Popular Articles
- {popularArticles.map((article, index) => (
-
- ))}
-
-
-
-
-
-
Recent Blogs
- {currentPosts.map((post, index) => (
-
- ))}
-
- {[...Array(Math.ceil(recentBlogPosts.length / postsPerPage))].map(
- (_, index) => (
-
paginate(index + 1)}
- variant={currentPage === index + 1 ? "default" : "outline"}
- >
- {index + 1}
-
- )
+
+
Popular Articles
+ {blogData.popularArticles && blogData.popularArticles.length > 0 ? (
+ blogData.popularArticles.map((article, index) => (
+
+ ))
+ ) : (
+
No popular articles available
)}
+ )}
+
+
+
+
Recent Blogs
+ {currentPosts.length > 0 ? (
+ currentPosts.map((post, index) => (
+
+ ))
+ ) : (
+
No recent blogs available
+ )}
+
+ {remainingBlogs.length > postsPerPage && (
+
+ {[...Array(Math.ceil(remainingBlogs.length / postsPerPage))].map(
+ (_, index) => (
+ paginate(index + 1)}
+ variant={currentPage === index + 1 ? "default" : "outline"}
+ >
+ {index + 1}
+
+ )
+ )}
+
+ )}
+
Popular Articles
- {popularArticles.map((article, index) => (
-
- ))}
+ {blogData.popularArticles && blogData.popularArticles.length > 0 ? (
+ blogData.popularArticles.map((article, index) => (
+
+ ))
+ ) : (
+
No popular articles available
+ )}
diff --git a/components/blog/SingleBlog.jsx b/components/blog/SingleBlog.jsx
index 9e81bbb..0ca1b0f 100644
--- a/components/blog/SingleBlog.jsx
+++ b/components/blog/SingleBlog.jsx
@@ -2,43 +2,120 @@
import Image from "next/image";
import React, { useEffect, useState } from "react";
import "./blog.css";
+import axios from "axios";
+import { backendUrl } from "@/utils/axios";
+import DOMPurify from 'dompurify';
+import { useParams } from "next/navigation";
+
+
const SingleBlog = () => {
- const [blogResData, setResData] = useState(null);
+ const [blog, setBlog] = useState(null);
+ const [loading, setLoading] = useState(true);
+ const [error, setError] = useState(null);
+
+ // Debug log to check if slug is received
+ const params = useParams();
+
+ console.log("BlogPage params:", params);
+ console.log("SingleBlog received slug:", params?.["blog-id"]);
+ const slug = params?.["blog-id"]
useEffect(() => {
- const fetchData = async () => {
+ const fetchBlogData = async () => {
+ if (!slug) {
+ console.error("No slug provided");
+ setError("Blog not found. Missing identifier.");
+ setLoading(false);
+ return;
+ }
+
try {
- const response = await fetch("/api/blog");
- const blog = await response.json();
- setResData(blog.blogdata);
- } catch (error) {
- console.error("Error fetching blog data:", error);
+ console.log(`Fetching blog with slug: ${slug}`);
+ setLoading(true);
+
+ // Log the full URL being called for debugging
+ const url = `${backendUrl}/blogs/${slug}/`;
+ console.log(`Making API call to: ${url}`);
+
+ const response = await axios.get(url);
+ console.log("API response:", response.data);
+
+ if (response.data) {
+ setBlog(response.data);
+ } else {
+ setError("No blog data received from server");
+ }
+ setLoading(false);
+ } catch (err) {
+ console.error("Error fetching blog data:", err);
+ setError(`Failed to load blog content: ${err.message || "Unknown error"}`);
+ setLoading(false);
}
};
- fetchData();
- }, []);
+
+ fetchBlogData();
+ }, [slug]);
+
+ if (loading) {
+ return (
+
+
Loading blog content for slug: {slug}...
+
+ );
+ }
+
+ if (error) {
+ return (
+
+ );
+ }
+
+ if (!blog) {
+ return (
+
+
Blog not found for slug: {slug}
+
+ );
+ }
+
+ // Format the image URL
+ const imageUrl = blog.imageUrl !== "NA"
+ ? (blog.imageUrl.startsWith('http') ? blog.imageUrl : `${backendUrl}${blog.imageUrl}`)
+ : "/api/placeholder/800/500";
+
+ // Sanitize the blog description
+ const sanitizedDescription = DOMPurify.sanitize(blog.description);
return (
+ {/* Blog Title */}
+
{blog.title}
+
+ {/* Blog Meta Information */}
+
+
{blog.author} | {blog.date}
+
+
{/* Blog Image */}
{/* Blog Content */}
- {blogResData ? (
-
- ) : (
-
Loading blog content...
- )}
+
);
diff --git a/package-lock.json b/package-lock.json
index 8809f07..a3a09b1 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -19,6 +19,7 @@
"axios": "^1.7.9",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
+ "dompurify": "^3.2.5",
"embla-carousel-autoplay": "^8.3.0",
"embla-carousel-react": "^8.3.0",
"framer-motion": "^12.0.6",
@@ -1807,6 +1808,13 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/@types/trusted-types": {
+ "version": "2.0.7",
+ "resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.7.tgz",
+ "integrity": "sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==",
+ "license": "MIT",
+ "optional": true
+ },
"node_modules/@typescript-eslint/eslint-plugin": {
"version": "8.6.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.6.0.tgz",
@@ -2833,6 +2841,15 @@
"node": ">=6.0.0"
}
},
+ "node_modules/dompurify": {
+ "version": "3.2.5",
+ "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.2.5.tgz",
+ "integrity": "sha512-mLPd29uoRe9HpvwP2TxClGQBzGXeEC/we/q+bFlmPPmj2p2Ugl3r6ATu/UU1v77DXNcehiBg9zsr1dREyA/dJQ==",
+ "license": "(MPL-2.0 OR Apache-2.0)",
+ "optionalDependencies": {
+ "@types/trusted-types": "^2.0.7"
+ }
+ },
"node_modules/eastasianwidth": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz",
diff --git a/package.json b/package.json
index 79f8b74..5878af7 100644
--- a/package.json
+++ b/package.json
@@ -21,6 +21,7 @@
"axios": "^1.7.9",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
+ "dompurify": "^3.2.5",
"embla-carousel-autoplay": "^8.3.0",
"embla-carousel-react": "^8.3.0",
"framer-motion": "^12.0.6",