Skip to content

Commit

Permalink
Merge pull request keploy#58 from keploy/author-map
Browse files Browse the repository at this point in the history
fix: author mapping and blogs visibility
  • Loading branch information
khareyash05 authored Oct 16, 2024
2 parents 331ec48 + 9f87a88 commit 4c75c7a
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 15 deletions.
7 changes: 3 additions & 4 deletions components/AuthorMapping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function AuthorMapping({
AuthorArray,
itemsPerPage = 8, // You can customize the number of items per page
}:{
AuthorArray: Pick<Post, "author" | "ppmaAuthorName">[],
AuthorArray: Pick<Post, "author" | "ppmaAuthorName" | "ppmaAuthorImage">[],
itemsPerPage?:number
}) {
const [currentPage, setCurrentPage] = useState(1);
Expand All @@ -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)) {
Expand Down Expand Up @@ -66,8 +66,7 @@ export default function AuthorMapping({
<Link href={`/authors/${author.slug}`} key={index}>
<div className="p-5 rounded-lg mt-5 mb-5 flex flex-col justify-between border border-transparent transform transition-colors hover:border-accent-2 hover:dark:bg-neutral-400/30 hover:scale-105 cursor-pointer">
<div className="flex items-center mb-3 sm:mb-0">
{author.publishingAuthor.split(" ")[0].toLowerCase().trim() ==
author.ppmaAuthorName.split(" ")[0].toLowerCase().trim() ? (
{author.avatarUrl != "imag1" && author.avatarUrl != "image" ? (
<Image
src={author.avatarUrl}
alt={`${author.ppmaAuthorName}'s Avatar`}
Expand Down
58 changes: 55 additions & 3 deletions lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,64 @@ 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
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: 1000, where: { orderby: { field: DATE, order: DESC } categoryName: "community" }) {
edges {
node {
title
excerpt
slug
date
postId
featuredImage {
node {
sourceUrl
Expand Down Expand Up @@ -321,6 +372,7 @@ export async function getAllAuthors() {
edges{
node{
ppmaAuthorName
ppmaAuthorImage
author {
node {
name
Expand Down Expand Up @@ -375,7 +427,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
Expand Down Expand Up @@ -408,7 +460,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
Expand Down
28 changes: 21 additions & 7 deletions pages/authors/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Header from "../../components/header";
import Container from "../../components/container";
import {
getAllAuthors,
getAllPostsForCommunity,
getAllPostsForTechnology,
getContent,
getPostsByAuthor,
} from "../../lib/api";
Expand Down Expand Up @@ -55,16 +57,28 @@ 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);

// 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
};
};
3 changes: 2 additions & 1 deletion pages/authors/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function Authors({
}: {
AllAuthors: {
edges: {
node: { author: Post["author"]; ppmaAuthorName: Post["ppmaAuthorName"] };
node: { author: Post["author"]; ppmaAuthorName: Post["ppmaAuthorName"],ppmaAuthorImage: Post["ppmaAuthorImage"] };
}[];
};
preview;
Expand Down Expand Up @@ -42,6 +42,7 @@ export default function Authors({

export const getStaticProps: GetStaticProps = async ({ preview = false }) => {
const AllAuthors = await getAllAuthors();
console.log(AllAuthors.edges);
return {
props: { AllAuthors, preview },
revalidate: 10,
Expand Down
2 changes: 2 additions & 0 deletions types/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface Post {
excerpt: string;
slug: string;
date: string;
postId: Number;
featuredImage: {
node: {
sourceUrl: string;
Expand All @@ -15,6 +16,7 @@ export interface Post {
node: Author;
};
ppmaAuthorName: string;
ppmaAuthorImage: string;
categories: {
edges: {
node: {
Expand Down

0 comments on commit 4c75c7a

Please sign in to comment.