diff --git a/src/css/ChanakyaNews.css b/src/css/ChanakyaNews.css
new file mode 100644
index 0000000..d8d23f5
--- /dev/null
+++ b/src/css/ChanakyaNews.css
@@ -0,0 +1,72 @@
+/* Individual newsletter card */
+.nItem {
+ background-color: rgba(223, 223, 176, 0.4);
+ border-radius: 8px;
+ padding: 10px;
+ margin: 10px;
+ text-align: center;
+ box-shadow: 0 4px 8px #383636;
+ transition: transform 0.2s;
+ display: flex;
+ flex-direction: column;
+ justify-content: space-between;
+ height: 250px;
+ box-sizing: border-box;
+ width: calc(100% - 20px);
+}
+
+.nItem:hover {
+ border: 0.5px solid rgb(254, 251, 251);
+ transform: scale(1.05);
+}
+
+.card-des {
+ font-size: 1rem;
+ color: #383636;
+ margin-bottom: 10px;
+ text-overflow: ellipsis;
+ overflow: hidden;
+}
+
+.itemdate {
+ font-size: 0.9rem;
+ color: #502828;
+ margin-bottom: 5px;
+}
+.badge {
+ display: inline-block;
+ margin-bottom: 5px;
+ text-align: left; /* Align badge to the left */
+}
+
+.badge,
+.itemdate {
+ font-size: 0.9rem;
+ color: #502828;
+ text-align: left;
+ width: auto;
+ margin-bottom: 5px;
+}
+
+
+.nItem div {
+ display: flex;
+ flex-direction: column;
+ align-items: flex-start;
+}
+.btn {
+ align-self: center;
+ margin-top: auto;
+}
+
+@media only screen and (max-width: 600px) {
+ .individualitem {
+ display: flex;
+ justify-content: center;
+ width: 100%;
+ }
+
+ .nItem {
+ width: 90%;
+ }
+}
diff --git a/src/pages/resources/ChanakyaBook.jsx b/src/pages/resources/ChanakyaBook.jsx
index 00e1128..63ad0b6 100644
--- a/src/pages/resources/ChanakyaBook.jsx
+++ b/src/pages/resources/ChanakyaBook.jsx
@@ -1,9 +1,92 @@
-import React from 'react'
+import React, { useEffect, useState } from "react";
+import axios from "axios";
const ChanakyaBook = () => {
+ const [books, setBooks] = useState([]);
+ const [loading, setLoading] = useState(true);
+ const [error, setError] = useState(null);
+
+ useEffect(() => {
+ fetchBooks();
+ }, []);
+
+ const fetchBooks = async () => {
+ try {
+ setLoading(true);
+ const response = await axios.get(
+ "https://www.googleapis.com/books/v1/volumes?q=chanakya+OR+arthashastra+OR+kautilya"
+ );
+
+ const fetchedBooks = response.data.items.map((book) => ({
+ title: book.volumeInfo.title,
+ authors: book.volumeInfo.authors,
+ description: book.volumeInfo.description,
+ thumbnail: book.volumeInfo.imageLinks?.thumbnail,
+ link: book.volumeInfo.previewLink,
+ }));
+
+ setBooks(fetchedBooks);
+ setLoading(false);
+ } catch (err) {
+ console.error("Error fetching books:", err);
+ setError("Failed to fetch books. Please try again later.");
+ setLoading(false);
+ }
+ };
+
+ const cardStyle = window.matchMedia("(max-width: 992px)").matches
+ ? { width: "90%" }
+ : { width: "20rem" };
+ if (loading) return
Loading...
;
+ if (error) return {error}
;
+
return (
- ChanakyaBook
- )
-}
+
+
Books on Chanakya & Arthashastra
+
+ {books.map((book, index) => (
+
+
+ {book.thumbnail && (
+
+ )}
+
+
+ {book.title}
+
+ {book.authors && (
+
+ By: {book.authors.join(", ")}
+
+ )}
+ {book.description && (
+
+ {book.description.substring(0, 80)}...
+
+ )}
+
+
+
+
+ ))}
+
+
+ );
+};
export default ChanakyaBook;
diff --git a/src/pages/resources/ChanakyaNews.jsx b/src/pages/resources/ChanakyaNews.jsx
index df4c681..a8a11ef 100644
--- a/src/pages/resources/ChanakyaNews.jsx
+++ b/src/pages/resources/ChanakyaNews.jsx
@@ -1,6 +1,9 @@
-import React, { useState, useEffect } from 'react';
-import axios from 'axios';
-
+import React, { useState, useEffect } from "react";
+import axios from "axios";
+import Slider from "react-slick";
+import "slick-carousel/slick/slick.css";
+import "slick-carousel/slick/slick-theme.css";
+import "../../css/ChanakyaNews.css";
const ChanakyaNews = () => {
const [news, setNews] = useState([]);
const [loading, setLoading] = useState(true);
@@ -13,74 +16,127 @@ const ChanakyaNews = () => {
const fetchNews = async () => {
try {
setLoading(true);
- const rss2jsonEndpoint = 'https://api.rss2json.com/v1/api.json';
- const googleNewsRSS = 'https://news.google.com/rss/search?q=archaryachanakya+OR+Arthashastra+OR+kautilya&hl=en-IN&gl=IN&ceid=IN:en';
+ const rss2jsonEndpoint = "https://api.rss2json.com/v1/api.json";
+ const googleNewsRSS =
+ "https://news.google.com/rss/search?q=archaryachanakya+OR+Arthashastra+OR+kautilya&hl=en-IN&gl=IN&ceid=IN:en";
const response = await axios.get(rss2jsonEndpoint, {
params: {
rss_url: googleNewsRSS,
api_key: import.meta.env.VITE_NEWS_API_KEY,
count: 60,
- }
+ },
});
- const newsItems = response.data.items.map(item => ({
+ const newsItems = response.data.items.map((item) => ({
title: item.title,
link: item.link,
pubDate: item.pubDate,
- description: item.description
+ description: item.description,
}));
const categorizedNews = categorizeNews(newsItems);
setNews(categorizedNews);
setLoading(false);
} catch (err) {
- setError('Failed to fetch news. Please try again later.');
+ setError("Failed to fetch news. Please try again later.");
setLoading(false);
}
};
const categorizeNews = (newsItems) => {
const categoryKeywords = {
- economics: ['economy', 'finance', 'wealth', 'arthashastra', 'economic'],
- politics: ['governance', 'leadership', 'strategy', 'political'],
- history: ['history', 'ancient', 'mauryan', 'empire', 'historical'],
- teachings: ['wisdom', 'teachings', 'philosophy', 'quotes'],
+ economics: ["economy", "finance", "wealth", "arthashastra", "economic"],
+ politics: ["governance", "leadership", "strategy", "political"],
+ history: ["history", "ancient", "mauryan", "empire", "historical"],
+ teachings: ["wisdom", "teachings", "philosophy", "quotes"],
};
- return newsItems.map(item => {
- const content = (item.title + ' ' + item.description).toLowerCase();
- for (const [category, keywords] of Object.entries(categoryKeywords)) {
- if (keywords.some(keyword => content.includes(keyword))) {
- return { ...item, category };
+ return newsItems
+ .map((item) => {
+ const content = (item.title + " " + item.description).toLowerCase();
+ for (const [category, keywords] of Object.entries(categoryKeywords)) {
+ if (keywords.some((keyword) => content.includes(keyword))) {
+ return { ...item, category };
+ }
}
- }
- return null; // Exclude items that don't match any category
- }).filter(item => item !== null);
+ return null; // Exclude items that don't match any category
+ })
+ .filter((item) => item !== null);
};
if (loading) return Loading...
;
if (error) return {error}
;
+ const responsive = [
+ {
+ breakpoint: 1024,
+ settings: {
+ slidesToShow: 5,
+ },
+ },
+ {
+ breakpoint: 900,
+ settings: {
+ slidesToShow: 3,
+ },
+ },
+ {
+ breakpoint: 600,
+ settings: {
+ slidesToShow: 2,
+ },
+ },
+ {
+ breakpoint: 480,
+ settings: {
+ slidesToShow: 1,
+ },
+ },
+ ];
+ // Slider settings for the multi-item carousel
+ const settings = {
+ dots: false,
+ infinite: true,
+ speed: 500,
+ slidesToShow: 4,
+ slidesToScroll: 1,
+ autoplay: true,
+ autoplaySpeed: 2000,
+ pauseOnHover: true,
+ arrows: false,
+ responsive,
+ };
return (
-
+ <>
Latest News on Aacharya Chanakya
-
+
{news.map((item, index) => (
-
-
-
-
{item.title}
-
{item.category}
-
Published: {new Date(item.pubDate).toLocaleDateString()}
-
Read more
+
+
+
{item.title}
+
+
+ {item.category}
+
+
+ Published: {new Date(item.pubDate).toLocaleDateString()}
+
+
+ Read more
+
))}
-
-
+
+ >
);
};
-export default ChanakyaNews;
\ No newline at end of file
+export default ChanakyaNews;