add main and colomn items

This commit is contained in:
Profile Profile
2026-01-29 01:30:06 +03:00
parent 3ca3811a5f
commit 49a4638c75
4 changed files with 406 additions and 0 deletions

149
src/lib/api/colon-posts.ts Normal file
View File

@@ -0,0 +1,149 @@
// src/lib/api/colon-posts.ts
import { fetchGraphQL } from './graphql-client.js';
import { cache } from '@lib/cache/manager.js';
import { CACHE_TTL } from '@lib/cache/cache-ttl';
/**
* Интерфейс для поста колонки (ProfileArticle с colonItem = true)
*/
export interface ColonPost {
id: string;
databaseId: number;
title: string;
uri: string;
date: string;
colonItem: boolean;
excerpt?: string;
featuredImage?: {
node: {
sourceUrl: string;
altText: string;
};
};
author: {
node: {
id: string;
name: string;
firstName: string;
lastName: string;
avatar: {
url: string;
};
uri: string;
};
};
coauthors?: Array<{
id: string;
name: string;
firstName: string;
lastName: string;
url: string;
description: string;
}>;
categories: {
nodes: Array<{
id: string;
name: string;
color?: string;
slug: string;
uri: string;
databaseId: number;
}>;
};
tags: {
nodes: Array<{
id: string;
name: string;
slug: string;
uri: string;
}>;
};
}
/**
* GraphQL запрос для получения последнего поста колонки
*/
const LATEST_COLON_POST_QUERY = `
query GetLatestColonPost {
profileArticles(
where: {
status: PUBLISH
colonItemEquals: true
orderby: { field: DATE, order: DESC }
}
first: 1
) {
nodes {
id
databaseId
title
uri
date
colonItem
excerpt
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
}
}
tags {
nodes {
id
name
slug
uri
}
}
}
}
}
`;
/**
* Получает последний пост колонки
*
* @returns {Promise<ColonPost | null>} Последний пост колонки или null
*/
export async function getLatestColonPost(): Promise<ColonPost | null> {
const cacheKey = 'latest-colon-post';
return await cache.wrap(
cacheKey,
async () => {
const data = await fetchGraphQL(LATEST_COLON_POST_QUERY);
return data?.profileArticles?.nodes?.[0] || null;
},
CACHE_TTL.SHORT
);
}

149
src/lib/api/main-posts.ts Normal file
View File

@@ -0,0 +1,149 @@
// src/lib/api/main-posts.ts
import { fetchGraphQL } from './graphql-client.js';
import { cache } from '@lib/cache/manager.js';
import { CACHE_TTL } from '@lib/cache/cache-ttl';
/**
* Интерфейс для главного поста (ProfileArticle с mainItem = true)
*/
export interface MainPost {
id: string;
databaseId: number;
title: string;
uri: string;
date: string;
mainItem: boolean;
excerpt?: string;
featuredImage?: {
node: {
sourceUrl: string;
altText: string;
};
};
author: {
node: {
id: string;
name: string;
firstName: string;
lastName: string;
avatar: {
url: string;
};
uri: string;
};
};
coauthors?: Array<{
id: string;
name: string;
firstName: string;
lastName: string;
url: string;
description: string;
}>;
categories: {
nodes: Array<{
id: string;
name: string;
color?: string;
slug: string;
uri: string;
databaseId: number;
}>;
};
tags: {
nodes: Array<{
id: string;
name: string;
slug: string;
uri: string;
}>;
};
}
/**
* GraphQL запрос для получения последнего главного поста
*/
const LATEST_MAIN_POST_QUERY = `
query GetLatestMainPost {
profileArticles(
where: {
status: PUBLISH
mainItemEquals: true
orderby: { field: DATE, order: DESC }
}
first: 1
) {
nodes {
id
databaseId
title
uri
date
mainItem
excerpt
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
}
}
tags {
nodes {
id
name
slug
uri
}
}
}
}
}
`;
/**
* Получает последний главный пост
*
* @returns {Promise<MainPost | null>} Последний главный пост или null
*/
export async function getLatestMainPost(): Promise<MainPost | null> {
const cacheKey = 'latest-main-post';
return await cache.wrap(
cacheKey,
async () => {
const data = await fetchGraphQL(LATEST_MAIN_POST_QUERY);
return data?.profileArticles?.nodes?.[0] || null;
},
CACHE_TTL.SHORT
);
}