Создание страницы блога

This commit is contained in:
Web-serfer 2026-04-06 21:28:31 +05:00
parent f84c24e91f
commit ed93c5646a
10 changed files with 1058 additions and 34 deletions

View file

@ -0,0 +1,225 @@
---
export interface Props {
title: string;
description: string;
category: string;
categoryColor?: string;
date: string;
readTime: string;
imageUrl?: string;
slug?: string;
}
const {
title,
description,
category,
categoryColor = 'bg-gold',
date,
readTime,
imageUrl = '/images/blog/default.avif',
slug = '#'
} = Astro.props;
// Форматируем дату
const formatDate = (dateStr: string) => {
const d = new Date(dateStr);
return d.toLocaleDateString('ru-RU', {
day: 'numeric',
month: 'long',
year: 'numeric'
});
};
---
<article class="blog-card animate-on-scroll" data-animation="fade-up">
<a href={slug} class="card-link">
<!-- Изображение -->
<div class="card-image">
<img src={imageUrl} alt={title} loading="lazy" />
<span class={`category-badge ${categoryColor}`}>{category}</span>
</div>
<!-- Контент -->
<div class="card-content">
<h3 class="card-title">{title}</h3>
<p class="card-description">{description}</p>
<div class="card-meta">
<span class="meta-item">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="meta-icon">
<rect width="18" height="18" x="3" y="4" rx="2" ry="2"></rect>
<line x1="16" x2="16" y1="2" y2="6"></line>
<line x1="8" x2="8" y1="2" y2="6"></line>
<line x1="3" x2="21" y1="10" y2="10"></line>
</svg>
{formatDate(date)}
</span>
<span class="meta-item">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="meta-icon">
<circle cx="12" cy="12" r="10"></circle>
<polyline points="12 6 12 12 16 14"></polyline>
</svg>
{readTime}
</span>
</div>
</div>
</a>
</article>
<style>
.blog-card {
background: #ffffff;
border-radius: 1rem;
overflow: hidden;
border: 2px solid transparent;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
height: 100%;
display: flex;
flex-direction: column;
}
.blog-card:hover {
border-color: #d4af37;
box-shadow: 0 12px 30px rgba(212, 175, 55, 0.12);
transform: translateY(-6px);
}
.card-link {
text-decoration: none;
color: inherit;
display: flex;
flex-direction: column;
height: 100%;
}
/* Изображение */
.card-image {
position: relative;
height: 200px;
overflow: hidden;
}
.card-image img {
width: 100%;
height: 100%;
object-fit: cover;
transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.blog-card:hover .card-image img {
transform: scale(1.05);
}
.category-badge {
position: absolute;
top: 1rem;
left: 1rem;
padding: 0.35rem 0.75rem;
border-radius: 0.5rem;
font-size: 0.75rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.category-badge.bg-gold {
background: linear-gradient(135deg, #d4af37 0%, #eac26e 100%);
color: #1e293b;
}
.category-badge.bg-blue {
background: linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%);
color: #ffffff;
}
.category-badge.bg-red {
background: linear-gradient(135deg, #ef4444 0%, #f87171 100%);
color: #ffffff;
}
.category-badge.bg-green {
background: linear-gradient(135deg, #22c55e 0%, #4ade80 100%);
color: #ffffff;
}
/* Контент */
.card-content {
padding: 1.5rem;
display: flex;
flex-direction: column;
gap: 0.75rem;
flex: 1;
}
.card-title {
color: #1e293b;
font-size: 1.15rem;
font-weight: 700;
margin: 0;
line-height: 1.4;
letter-spacing: -0.01em;
transition: color 0.2s ease;
}
.blog-card:hover .card-title {
color: #d4af37;
}
.card-description {
color: #64748b;
font-size: 0.9rem;
line-height: 1.6;
margin: 0;
flex: 1;
}
.card-meta {
display: flex;
align-items: center;
gap: 1.25rem;
padding-top: 1rem;
border-top: 1px solid #f1f5f9;
margin-top: auto;
}
.meta-item {
display: flex;
align-items: center;
gap: 0.4rem;
color: #94a3b8;
font-size: 0.8rem;
font-weight: 500;
}
.meta-icon {
width: 0.9rem;
height: 0.9rem;
}
/* Анимации */
.animate-on-scroll {
opacity: 0;
will-change: opacity, transform;
}
[data-animation="fade-up"] {
transform: translateY(30px);
transition: opacity 0.7s cubic-bezier(0.4, 0, 0.2, 1),
transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}
.animate-on-scroll.is-visible {
opacity: 1;
transform: translateY(0);
}
@media (prefers-reduced-motion: reduce) {
.animate-on-scroll {
opacity: 1;
transform: none;
transition: none;
}
}
</style>

View file

@ -0,0 +1,127 @@
---
export interface Props {
categories: string[];
activeCategory?: string;
}
const { categories, activeCategory = 'Все' } = Astro.props;
---
<div class="blog-categories animate-on-scroll" data-animation="fade-up">
<div class="categories-wrapper">
{categories.map((cat) => (
<button
class={`category-btn ${cat === activeCategory ? 'active' : ''}`}
data-category={cat}
>
{cat}
</button>
))}
</div>
</div>
<style>
.blog-categories {
padding: 2rem 0 0;
background: #f8fafc;
}
.categories-wrapper {
display: flex;
flex-wrap: wrap;
gap: 0.75rem;
justify-content: center;
max-width: 900px;
margin: 0 auto;
}
.category-btn {
padding: 0.6rem 1.25rem;
border: 2px solid #e2e8f0;
border-radius: 2rem;
background: #ffffff;
color: #64748b;
font-size: 0.875rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
white-space: nowrap;
}
.category-btn:hover {
border-color: #d4af37;
color: #d4af37;
transform: translateY(-2px);
}
.category-btn.active {
background: linear-gradient(135deg, #d4af37 0%, #eac26e 100%);
border-color: #d4af37;
color: #1e293b;
box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3);
}
/* Анимации */
.animate-on-scroll {
opacity: 0;
will-change: opacity, transform;
}
[data-animation="fade-up"] {
transform: translateY(30px);
transition: opacity 0.7s cubic-bezier(0.4, 0, 0.2, 1),
transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}
.animate-on-scroll.is-visible {
opacity: 1;
transform: translateY(0);
}
@media (prefers-reduced-motion: reduce) {
.animate-on-scroll {
opacity: 1;
transform: none;
transition: none;
}
}
@media (max-width: 640px) {
.categories-wrapper {
gap: 0.5rem;
}
.category-btn {
padding: 0.5rem 1rem;
font-size: 0.8rem;
}
}
</style>
<script>
// Клиентская логика фильтрации (пока заглушка)
document.addEventListener('DOMContentLoaded', () => {
const buttons = document.querySelectorAll('.category-btn');
buttons.forEach(btn => {
btn.addEventListener('click', () => {
buttons.forEach(b => b.classList.remove('active'));
btn.classList.add('active');
// TODO: Добавить логику фильтрации при интеграции с коллекцией
console.log('Выбрана категория:', btn.getAttribute('data-category'));
});
});
});
document.addEventListener('astro:page-load', () => {
const buttons = document.querySelectorAll('.category-btn');
buttons.forEach(btn => {
btn.addEventListener('click', () => {
buttons.forEach(b => b.classList.remove('active'));
btn.classList.add('active');
});
});
});
</script>

View file

@ -0,0 +1,178 @@
---
const badgeText = "БЛОГ И СТАТЬИ";
const titleWhite = "Полезные статьи";
const titleGold = "для автовладельцев";
const description = "Разбираем сложные юридические вопросы простым языком. Советы юриста по автоспорам, ДТП, ОСАГО и защите прав водителей.";
---
<section class="blog-hero">
<div class="hero-overlay"></div>
<div class="site-container hero-content">
<div class="badge animate-on-scroll" data-animation="fade-up">
<span class="status-dot"></span>
{badgeText}
</div>
<h1 class="hero-title">
<span class="text-white animate-on-scroll" data-animation="fade-up" data-delay="100">{titleWhite}</span>
<br />
<span class="text-gold animate-on-scroll" data-animation="fade-up" data-delay="200">{titleGold}</span>
</h1>
<p class="hero-description animate-on-scroll" data-animation="fade-up" data-delay="300">{description}</p>
</div>
</section>
<style>
.blog-hero {
position: relative;
width: 100%;
padding: 8rem 0 5rem;
background: linear-gradient(135deg, #0a2540 0%, #1e3a5f 100%);
overflow: hidden;
}
.blog-hero::before {
content: '';
position: absolute;
top: -30%;
right: -5%;
width: 500px;
height: 500px;
background: radial-gradient(circle, rgba(212, 175, 55, 0.08) 0%, transparent 70%);
border-radius: 50%;
}
.hero-overlay {
position: absolute;
top: 0; left: 0; width: 100%; height: 100%;
background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.02'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
z-index: 0;
}
.hero-content {
position: relative;
z-index: 1;
text-align: center;
max-width: 750px;
margin: 0 auto;
}
.badge {
display: inline-flex;
align-items: center;
gap: 0.6rem;
background-color: rgba(234, 194, 110, 0.15);
border: 1px solid rgba(234, 194, 110, 0.3);
color: #eac26e;
padding: 0.5rem 1rem;
border-radius: 6px;
font-size: 0.8rem;
font-weight: 700;
letter-spacing: 1.5px;
margin-bottom: 2rem;
}
.status-dot {
width: 10px;
height: 10px;
background: #22c55e;
border-radius: 50%;
animation: pulse 2s ease-in-out infinite;
box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
flex-shrink: 0;
}
@keyframes pulse {
0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); }
70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}
.hero-title {
font-size: clamp(2.5rem, 5vw, 4rem);
line-height: 1.15;
margin: 0 0 1.5rem 0;
font-weight: 800;
letter-spacing: -0.02em;
}
.hero-title .text-white,
.hero-title .text-gold {
display: inline-block;
}
.text-white { color: #ffffff; }
.text-gold { color: #eac26e; }
.hero-description {
color: rgba(255, 255, 255, 0.8);
font-size: 1.15rem;
line-height: 1.6;
margin: 0;
max-width: 600px;
margin-left: auto;
margin-right: auto;
}
/* Анимации */
.animate-on-scroll {
opacity: 0;
will-change: opacity, transform;
}
[data-animation="fade-up"] {
transform: translateY(30px);
transition: opacity 0.7s cubic-bezier(0.4, 0, 0.2, 1),
transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}
.animate-on-scroll.is-visible {
opacity: 1;
transform: translateY(0);
}
@media (prefers-reduced-motion: reduce) {
.animate-on-scroll {
opacity: 1;
transform: none;
transition: none;
}
}
@media (max-width: 768px) {
.blog-hero {
padding: 7rem 0 3.5rem;
}
.hero-title {
font-size: 2.2rem;
}
.hero-description {
font-size: 1rem;
}
}
</style>
<script>
const setupAnimations = () => {
const observerOptions = { threshold: 0.1 };
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const el = entry.target as HTMLElement;
const delay = parseInt(el.dataset.delay || '0');
setTimeout(() => el.classList.add('is-visible'), delay);
observer.unobserve(el);
}
});
}, observerOptions);
document.querySelectorAll('.animate-on-scroll').forEach((el) => observer.observe(el));
};
setupAnimations();
document.addEventListener('astro:after-swap', setupAnimations);
</script>

View file

@ -0,0 +1,187 @@
---
export interface Props {
currentPage: number;
totalPages: number;
}
const { currentPage, totalPages } = Astro.props;
const getPages = () => {
const pages: (number | string)[] = [];
for (let i = 1; i <= totalPages; i++) {
if (i === 1 || i === totalPages || (i >= currentPage - 1 && i <= currentPage + 1)) {
pages.push(i);
} else if (pages[pages.length - 1] !== '...') {
pages.push('...');
}
}
return pages;
};
---
<nav class="blog-pagination animate-on-scroll" data-animation="fade-up">
<div class="pagination-wrapper">
<!-- Кнопка Назад -->
<a
href={currentPage > 1 ? `/blog/page/${currentPage - 1}` : '#'}
class={`pagination-btn prev ${currentPage === 1 ? 'disabled' : ''}`}
aria-disabled={currentPage === 1}
>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="m15 18-6-6 6-6"/>
</svg>
</a>
<!-- Номера страниц -->
<div class="pagination-pages">
{getPages().map((page) => (
page === '...' ? (
<span class="pagination-ellipsis">…</span>
) : (
<a
href={page === 1 ? '/blog' : `/blog/page/${page}`}
class={`pagination-page ${page === currentPage ? 'active' : ''}`}
aria-current={page === currentPage ? 'page' : undefined}
>
{page}
</a>
)
))}
</div>
<!-- Кнопка Вперед -->
<a
href={currentPage < totalPages ? `/blog/page/${currentPage + 1}` : '#'}
class={`pagination-btn next ${currentPage === totalPages ? 'disabled' : ''}`}
aria-disabled={currentPage === totalPages}
>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="m9 18 6-6-6-6"/>
</svg>
</a>
</div>
</nav>
<style>
.blog-pagination {
padding: 3rem 0 4rem;
display: flex;
justify-content: center;
}
.pagination-wrapper {
display: flex;
align-items: center;
gap: 0.5rem;
}
.pagination-btn {
display: flex;
align-items: center;
justify-content: center;
width: 2.75rem;
height: 2.75rem;
border-radius: 0.75rem;
border: 2px solid #e2e8f0;
background: #ffffff;
color: #64748b;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
text-decoration: none;
}
.pagination-btn:not(.disabled):hover {
border-color: #d4af37;
color: #d4af37;
transform: translateY(-2px);
}
.pagination-btn.disabled {
opacity: 0.4;
cursor: not-allowed;
pointer-events: none;
}
.pagination-btn svg {
width: 1.25rem;
height: 1.25rem;
}
.pagination-pages {
display: flex;
align-items: center;
gap: 0.375rem;
}
.pagination-page {
display: flex;
align-items: center;
justify-content: center;
min-width: 2.75rem;
height: 2.75rem;
border-radius: 0.75rem;
border: 2px solid transparent;
background: #ffffff;
color: #64748b;
font-size: 0.9rem;
font-weight: 600;
text-decoration: none;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.pagination-page:hover {
border-color: #d4af37;
color: #d4af37;
}
.pagination-page.active {
background: linear-gradient(135deg, #d4af37 0%, #eac26e 100%);
border-color: #d4af37;
color: #1e293b;
box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3);
}
.pagination-ellipsis {
color: #94a3b8;
padding: 0 0.25rem;
font-size: 1.25rem;
user-select: none;
}
/* Анимации */
.animate-on-scroll {
opacity: 0;
will-change: opacity, transform;
}
[data-animation="fade-up"] {
transform: translateY(30px);
transition: opacity 0.7s cubic-bezier(0.4, 0, 0.2, 1),
transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}
.animate-on-scroll.is-visible {
opacity: 1;
transform: translateY(0);
}
@media (prefers-reduced-motion: reduce) {
.animate-on-scroll {
opacity: 1;
transform: none;
transition: none;
}
}
@media (max-width: 640px) {
.pagination-pages {
gap: 0.25rem;
}
.pagination-page,
.pagination-btn {
width: 2.25rem;
height: 2.25rem;
min-width: 2.25rem;
}
}
</style>