add endpoint authors

This commit is contained in:
Profile Profile
2026-03-02 23:10:31 +03:00
parent 7739647549
commit e5af3fcfd6
7 changed files with 525 additions and 103 deletions

View File

@@ -23,19 +23,24 @@ const {
perLoad = 11
} = Astro.props;
// Используем perLoad везде
const loadMoreConfig = {
type,
slug,
perLoad // Теперь используем perLoad вместо first
perLoad
};
function getCoauthorsNames(coauthors: any[]): string {
if (!coauthors || coauthors.length === 0) return '';
return coauthors
.map((coauthor: any) => coauthor?.node?.name || coauthor?.name)
.map((coauthor: any) => {
const name = coauthor?.node?.name || coauthor?.name;
const nickname = coauthor?.node?.nickname || coauthor?.nickname;
return name; // Возвращаем только имя, ссылки будут в шаблоне
})
.filter(Boolean)
.join(' ');
.join(', ');
}
function shouldBeLarge(index: number): boolean {
@@ -55,7 +60,6 @@ function shouldBeLarge(index: number): boolean {
{items.map((item, index) => {
const postUrl = item.uri || `/blog/${item.databaseId}`;
const postDate = new Date(item.date);
const coauthorsNames = getCoauthorsNames(item.coauthors || []);
const isLarge = shouldBeLarge(index);
return (
@@ -66,54 +70,83 @@ function shouldBeLarge(index: number): boolean {
itemscope
itemtype="https://schema.org/BlogPosting"
>
<a href={postUrl} class="post-card-link">
<div class="post-image-container">
{item.featuredImage?.node?.sourceUrl ? (
<img
src={item.featuredImage.node.sourceUrl}
alt={item.featuredImage.node.altText || item.title}
width="400"
height="400"
loading="lazy"
class="post-image"
itemprop="image"
/>
) : (
<div class="post-image-placeholder"></div>
)}
<CategoryBadge
name={item.categories?.nodes?.[0]?.name}
color={item.categories?.nodes?.[0]?.color}
<div class="post-image-container">
{item.featuredImage?.node?.sourceUrl ? (
<img
src={item.featuredImage.node.sourceUrl}
alt={item.featuredImage.node.altText || item.title}
width="400"
height="400"
loading="lazy"
class="post-image"
itemprop="image"
/>
) : (
<div class="post-image-placeholder"></div>
)}
{item.categories?.nodes?.[0] && (
<a
href={`/${item.categories.nodes[0].slug}`}
class="category-badge-link"
onClick={(e) => e.stopPropagation()}
>
<CategoryBadge
name={item.categories.nodes[0].name}
color={item.categories.nodes[0].color}
/>
</a>
)}
<div class="post-content-overlay">
<div class="post-meta-overlay">
<time
datetime={item.date}
class="post-date-overlay"
itemprop="datePublished"
>
{postDate.toLocaleDateString('ru-RU', {
day: 'numeric',
month: 'short',
year: 'numeric'
}).replace(' г.', '')}
</time>
</div>
<div class="post-content-overlay">
<div class="post-meta-overlay">
<time
datetime={item.date}
class="post-date-overlay"
itemprop="datePublished"
>
{postDate.toLocaleDateString('ru-RU', {
day: 'numeric',
month: 'short',
year: 'numeric'
}).replace(' г.', '')}
</time>
</div>
<a href={postUrl} class="post-title-link" itemprop="url">
<h3 class="post-title-overlay" itemprop="headline">
{item.title}
</h3>
</a>
{coauthorsNames && (
<div class="author-name" itemprop="author">
{coauthorsNames}
</div>
)}
</div>
{item.coauthors && item.coauthors.length > 0 && (
<div class="coauthors-wrapper" itemprop="author">
{item.coauthors.map((coauthor: any, i: number) => {
const name = coauthor?.node?.name || coauthor?.name;
const nickname = coauthor?.node?.nickname || coauthor?.nickname;
console.log(nickname);
return (
<span key={nickname || name}>
{i > 0 && ', '}
{nickname ? (
<a
href={`/author/${nickname}`}
class="author-link"
onClick={(e) => e.stopPropagation()}
>
{name}
</a>
) : (
<span class="author-name">{name}</span>
)}
</span>
);
})}
</div>
)}
</div>
</a>
</div>
<div class="sr-only">
<h3 itemprop="headline">