add files

This commit is contained in:
Andrey Kuvshinov
2025-12-11 01:12:45 +03:00
commit 22358272c6
31 changed files with 7392 additions and 0 deletions

99
src/lib/api/posts.ts Normal file
View File

@@ -0,0 +1,99 @@
import { fetchGraphQL } from './graphql-client.js';
import type { ProfileArticle } from '../types/graphql.js';
// lib/api/posts.js
export async function getLatestPosts(first = 12, after = null) {
const query = `
query GetLatestProfileArticles($first: Int!, $after: String) {
profileArticles(
first: $first,
after: $after,
where: {orderby: { field: DATE, order: DESC }}
) {
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
}
}
categories {
nodes {
id
name
slug
uri
databaseId
}
}
tags {
nodes {
id
name
slug
uri
}
}
}
}
}
}
`;
const data = await fetchGraphQL(query, { first, after });
// Преобразуем edges в nodes
const posts = data.profileArticles?.edges?.map(edge => edge.node) || [];
return {
posts,
pageInfo: data.profileArticles?.pageInfo || { hasNextPage: false, endCursor: null }
};
}
export interface AnewsPost {
title: string;
uri: string;
date: string;
}
export async function getLatestAnews(count = 12): Promise<AnewsPost[]> {
const query = `
query GetAnews($count: Int!) {
aNews(first: $count, where: {orderby: {field: DATE, order: DESC}}) {
nodes {
title
uri
date
}
}
}
`;
const data = await fetchGraphQL(query, { count });
return data.aNews?.nodes || []; // Исправлено: aNews вместо anews
}