add load-more-posts
This commit is contained in:
@@ -103,6 +103,98 @@ export async function getLatestPosts(first = 14, after = null) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export async function getPostsByCategory(slug, first = 14, after = null) {
|
||||
// Создаем уникальный ключ для кэша
|
||||
const cacheKey = `category-posts:${slug}:${first}:${after || 'first-page'}`;
|
||||
|
||||
return await cache.wrap(
|
||||
cacheKey,
|
||||
async () => {
|
||||
const query = `
|
||||
query GetPostsByCategory($first: Int!, $after: String, $slug: String!) {
|
||||
profileArticles(
|
||||
first: $first
|
||||
after: $after
|
||||
where: {
|
||||
orderby: { field: DATE, order: DESC }
|
||||
categoryName: $slug
|
||||
}
|
||||
) {
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
endCursor
|
||||
}
|
||||
edges {
|
||||
cursor
|
||||
node {
|
||||
id
|
||||
databaseId
|
||||
title
|
||||
uri
|
||||
date
|
||||
featuredImage {
|
||||
node {
|
||||
sourceUrl(size: LARGE)
|
||||
altText
|
||||
}
|
||||
}
|
||||
author {
|
||||
node {
|
||||
id
|
||||
name
|
||||
firstName
|
||||
lastName
|
||||
avatar {
|
||||
url
|
||||
}
|
||||
uri
|
||||
}
|
||||
}
|
||||
# Соавторы как массив
|
||||
coauthors {
|
||||
id
|
||||
name
|
||||
firstName
|
||||
lastName
|
||||
url
|
||||
description
|
||||
}
|
||||
categories {
|
||||
nodes {
|
||||
id
|
||||
name
|
||||
color
|
||||
slug
|
||||
uri
|
||||
databaseId
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const data = await fetchGraphQL(query, { first, after, slug });
|
||||
|
||||
const posts = data.profileArticles?.edges?.map(edge => edge.node) || [];
|
||||
|
||||
return {
|
||||
posts,
|
||||
pageInfo: data.profileArticles?.pageInfo || { hasNextPage: false, endCursor: null }
|
||||
};
|
||||
},
|
||||
{ ttl: CACHE_TTL.POSTS }
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//последние новости (кэшированная версия)
|
||||
export async function getLatestAnews(count = 12): Promise<AnewsPost[]> {
|
||||
const cacheKey = `latest-anews:${count}`;
|
||||
|
||||
Reference in New Issue
Block a user