add emmed
This commit is contained in:
@@ -345,7 +345,7 @@ export async function getPostsByTag(slug, first = 14, after = null) {
|
||||
}
|
||||
`;
|
||||
|
||||
console.log('Fetching with:', { first, after, slug }); // Добавим лог параметров
|
||||
//console.log('Fetching with:', { first, after, slug }); // Добавим лог параметров
|
||||
|
||||
const data = await fetchGraphQL(query, { first, after, slug });
|
||||
|
||||
@@ -616,6 +616,65 @@ export async function getTagBySlug(slug) {
|
||||
|
||||
|
||||
|
||||
// lib/graphql.js или src/lib/graphql.js
|
||||
|
||||
/** подключаем пост по slug */
|
||||
export async function getPostBySlug(slug) {
|
||||
const cacheKey = `post:${slug}`;
|
||||
|
||||
return await cache.wrap(
|
||||
cacheKey,
|
||||
async () => {
|
||||
const query = `
|
||||
query GetPostBySlug($slug: String!) {
|
||||
profileArticleBy(slug: $slug) {
|
||||
title
|
||||
link
|
||||
featuredImage {
|
||||
node {
|
||||
sourceUrl(size: LARGE)
|
||||
altText
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
aNewBy(slug: $slug) {
|
||||
title
|
||||
link
|
||||
featuredImage {
|
||||
node {
|
||||
sourceUrl(size: LARGE)
|
||||
altText
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const data = await fetchGraphQL(query, { slug });
|
||||
console.log('Raw GraphQL response:', JSON.stringify(data, null, 2));
|
||||
|
||||
// Находим первый существующий пост
|
||||
const post = data.profileArticleBy || data.aNewBy;
|
||||
|
||||
if (!post) {
|
||||
console.log('No post found for slug:', slug);
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
title: post.title,
|
||||
url: post.link,
|
||||
image: post.featuredImage?.node?.sourceUrl || null,
|
||||
imageAlt: post.featuredImage?.node?.altText || post.title || '',
|
||||
type: data.profileArticleBy ? 'profile_article' : 'anew'
|
||||
};
|
||||
},
|
||||
{ ttl: CACHE_TTL.POST_DETAIL }
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Получить тег с постами по slug с пагинацией
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user