From dd3d27373ad7e2e0cf79e8230f5e0627cef18261 Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Wed, 16 Oct 2024 16:15:49 +0530 Subject: [PATCH 1/5] fix: author mapping and blogs visibility Signed-off-by: Yash Khare --- lib/api.ts | 55 ++++++++++++++++++++++++++++++++++++++-- pages/authors/[slug].tsx | 38 ++++++++++++++++++++++----- types/post.ts | 1 + 3 files changed, 85 insertions(+), 9 deletions(-) diff --git a/lib/api.ts b/lib/api.ts index 39c5d30..f5951fc 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -276,6 +276,57 @@ export async function getAllPostsForTechnology(preview) { excerpt slug date + postId + featuredImage { + node { + sourceUrl + } + } + author { + node { + name + firstName + lastName + avatar { + url + } + } + } + ppmaAuthorName + categories { + edges { + node { + name + } + } + } + } + } + } + } + `, + { + variables: { + preview, + }, + } + ); + + return data?.posts; +} + +export async function getAllPostsForCommunity(preview) { + const data = await fetchAPI( + ` + query AllPostsForCategory{ + posts(first: 100, where: { orderby: { field: DATE, order: DESC } categoryName: "community" }) { + edges { + node { + title + excerpt + slug + date + postId featuredImage { node { sourceUrl @@ -375,7 +426,7 @@ export async function getMoreStoriesForSlugs() { const data = await fetchAPI( ` query AllPostsForCategory { - techPosts: posts(first: 10, where: { orderby: { field: DATE, order: DESC }, categoryName: "technology" }) { + techPosts: posts(first: 100, where: { orderby: { field: DATE, order: DESC }, categoryName: "technology" }) { edges { node { title @@ -408,7 +459,7 @@ export async function getMoreStoriesForSlugs() { } } } - communityPosts: posts(first: 10, where: { orderby: { field: DATE, order: DESC }, categoryName: "community" }) { + communityPosts: posts(first: 100, where: { orderby: { field: DATE, order: DESC }, categoryName: "community" }) { edges { node { title diff --git a/pages/authors/[slug].tsx b/pages/authors/[slug].tsx index 9e90dfc..45d556c 100644 --- a/pages/authors/[slug].tsx +++ b/pages/authors/[slug].tsx @@ -3,12 +3,15 @@ import Header from "../../components/header"; import Container from "../../components/container"; import { getAllAuthors, + getAllPostsForCommunity, + getAllPostsForTechnology, getContent, getPostsByAuthor, } from "../../lib/api"; import { GetStaticPaths, GetStaticProps } from "next"; import PostByAuthorMapping from "../../components/postByAuthorMapping"; import { HOME_OG_IMAGE_URL } from "../../lib/constants"; +import fs from 'fs'; export default function AuthorPage({ preview, filteredPosts ,content }) { if (!filteredPosts || filteredPosts.length === 0) { @@ -51,20 +54,41 @@ export const getStaticPaths: GetStaticPaths = async ({}) => { }; }; +const logToFile = (message: string) => { + const logMessage = `${new Date().toISOString()} - ${message}\n`; + fs.appendFileSync('server-log.txt', logMessage, 'utf8'); +}; + export const getStaticProps: GetStaticProps = async ({ preview = false, params, }) => { - const { slug } = params; - const postsByAuthor = await getPostsByAuthor(); - const filteredPosts = postsByAuthor.edges.filter( + const { slug } = params as { slug: string }; + + // Fetch posts from both sources + const postsByTechnology = await getAllPostsForTechnology(preview); + const postsByCommunity = await getAllPostsForCommunity(preview); + + // Log fetched posts for debugging + const logMessage = `Technology Posts: ${JSON.stringify(postsByTechnology.edges, null, 2)}\nCommunity Posts: ${JSON.stringify(postsByCommunity.edges, null, 2)}`; + logToFile(logMessage); + + // Combine posts from both sources + const allPosts = [...postsByTechnology.edges, ...postsByCommunity.edges]; + + // Filter the combined posts by the given slug + const filteredPosts = allPosts.filter( (item) => item.node.ppmaAuthorName === slug ); - const postId = (filteredPosts[0].node.postId); - const content = await getContent(postId); + + // Extract postId from the first matching post (if any) + const postId = filteredPosts[0]?.node?.postId; + + // Fetch content using postId (if available) + const content = postId ? await getContent(postId) : null; return { - props: { preview, filteredPosts , content}, - revalidate: 10, + props: { preview, filteredPosts, content }, + revalidate: 10, // ISR with 10 seconds revalidation }; }; diff --git a/types/post.ts b/types/post.ts index df5d925..17395b1 100644 --- a/types/post.ts +++ b/types/post.ts @@ -6,6 +6,7 @@ export interface Post { excerpt: string; slug: string; date: string; + postId: Number; featuredImage: { node: { sourceUrl: string; From 5cd9a59eaf53d4315cca4d6dd76e1900f00514c0 Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Wed, 16 Oct 2024 16:26:00 +0530 Subject: [PATCH 2/5] fix file Signed-off-by: Yash Khare --- pages/authors/[slug].tsx | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pages/authors/[slug].tsx b/pages/authors/[slug].tsx index 45d556c..83978b4 100644 --- a/pages/authors/[slug].tsx +++ b/pages/authors/[slug].tsx @@ -11,7 +11,6 @@ import { import { GetStaticPaths, GetStaticProps } from "next"; import PostByAuthorMapping from "../../components/postByAuthorMapping"; import { HOME_OG_IMAGE_URL } from "../../lib/constants"; -import fs from 'fs'; export default function AuthorPage({ preview, filteredPosts ,content }) { if (!filteredPosts || filteredPosts.length === 0) { @@ -54,11 +53,6 @@ export const getStaticPaths: GetStaticPaths = async ({}) => { }; }; -const logToFile = (message: string) => { - const logMessage = `${new Date().toISOString()} - ${message}\n`; - fs.appendFileSync('server-log.txt', logMessage, 'utf8'); -}; - export const getStaticProps: GetStaticProps = async ({ preview = false, params, @@ -69,10 +63,6 @@ export const getStaticProps: GetStaticProps = async ({ const postsByTechnology = await getAllPostsForTechnology(preview); const postsByCommunity = await getAllPostsForCommunity(preview); - // Log fetched posts for debugging - const logMessage = `Technology Posts: ${JSON.stringify(postsByTechnology.edges, null, 2)}\nCommunity Posts: ${JSON.stringify(postsByCommunity.edges, null, 2)}`; - logToFile(logMessage); - // Combine posts from both sources const allPosts = [...postsByTechnology.edges, ...postsByCommunity.edges]; From 53b94c66888f3726ceeb27f6a51feae58e288355 Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Wed, 16 Oct 2024 16:39:45 +0530 Subject: [PATCH 3/5] increase limit Signed-off-by: Yash Khare --- lib/api.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/api.ts b/lib/api.ts index f5951fc..fb988d0 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -269,7 +269,7 @@ export async function getAllPostsForTechnology(preview) { const data = await fetchAPI( ` query AllPostsForCategory{ - posts(first: 100, where: { orderby: { field: DATE, order: DESC } categoryName: "technology" }) { + posts(first: 1000, where: { orderby: { field: DATE, order: DESC } categoryName: "technology" }) { edges { node { title @@ -319,7 +319,7 @@ export async function getAllPostsForCommunity(preview) { const data = await fetchAPI( ` query AllPostsForCategory{ - posts(first: 100, where: { orderby: { field: DATE, order: DESC } categoryName: "community" }) { + posts(first: 1000, where: { orderby: { field: DATE, order: DESC } categoryName: "community" }) { edges { node { title From b9e391cfe80c16c0742de09aac7e05b66f09bc9c Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Wed, 16 Oct 2024 17:26:11 +0530 Subject: [PATCH 4/5] fix author image Signed-off-by: Yash Khare --- components/AuthorMapping.tsx | 7 +++---- lib/api.ts | 1 + pages/authors/index.tsx | 3 ++- types/post.ts | 1 + 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/components/AuthorMapping.tsx b/components/AuthorMapping.tsx index 975e301..ecedf76 100644 --- a/components/AuthorMapping.tsx +++ b/components/AuthorMapping.tsx @@ -7,7 +7,7 @@ export default function AuthorMapping({ AuthorArray, itemsPerPage = 8, // You can customize the number of items per page }:{ - AuthorArray: Pick[], + AuthorArray: Pick[], itemsPerPage?:number }) { const [currentPage, setCurrentPage] = useState(1); @@ -17,7 +17,7 @@ export default function AuthorMapping({ AuthorArray.forEach((item) => { const ppmaAuthorName = formatAuthorName(item.ppmaAuthorName); - const avatarUrl = item.author.node.avatar.url; + const avatarUrl = item.ppmaAuthorImage; const slug = item.ppmaAuthorName; const publishingAuthor = formatAuthorName(item.author.node.name); if (Array.isArray(ppmaAuthorName)) { @@ -66,8 +66,7 @@ export default function AuthorMapping({
- {author.publishingAuthor.split(" ")[0].toLowerCase().trim() == - author.ppmaAuthorName.split(" ")[0].toLowerCase().trim() ? ( + {author.avatarUrl != "imag1" ? ( {`${author.ppmaAuthorName}'s { const AllAuthors = await getAllAuthors(); + console.log(AllAuthors.edges); return { props: { AllAuthors, preview }, revalidate: 10, diff --git a/types/post.ts b/types/post.ts index 17395b1..606e629 100644 --- a/types/post.ts +++ b/types/post.ts @@ -16,6 +16,7 @@ export interface Post { node: Author; }; ppmaAuthorName: string; + ppmaAuthorImage: string; categories: { edges: { node: { From 9f87a881dafcfbf46b9ea07cd017b890152ac127 Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Wed, 16 Oct 2024 17:35:27 +0530 Subject: [PATCH 5/5] Fix author avatar display in AuthorMapping component Signed-off-by: Yash Khare --- components/AuthorMapping.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/AuthorMapping.tsx b/components/AuthorMapping.tsx index ecedf76..0bff74c 100644 --- a/components/AuthorMapping.tsx +++ b/components/AuthorMapping.tsx @@ -66,7 +66,7 @@ export default function AuthorMapping({
- {author.avatarUrl != "imag1" ? ( + {author.avatarUrl != "imag1" && author.avatarUrl != "image" ? (