From c9ed7c8fcca342fd9c9767fb860164cf1321ff9f Mon Sep 17 00:00:00 2001 From: Profile Profile Date: Sun, 8 Mar 2026 19:09:23 +0300 Subject: [PATCH] add correct news templates --- src/components/CategoryBadge.astro | 110 ++++++++++++++++++++++++-- src/components/ContentGrid.astro | 23 +++--- src/components/Header/Header.astro | 104 +++++++++++++++--------- src/layouts/MainLayout.astro | 5 +- src/pages/index.astro | 1 - src/pages/news/[...slug].astro | 15 +++- src/pages/news/index.astro | 12 +++ src/styles/components/ContentGrid.css | 30 +++---- 8 files changed, 218 insertions(+), 82 deletions(-) create mode 100644 src/pages/news/index.astro diff --git a/src/components/CategoryBadge.astro b/src/components/CategoryBadge.astro index 9afc10b..f52d036 100644 --- a/src/components/CategoryBadge.astro +++ b/src/components/CategoryBadge.astro @@ -2,10 +2,18 @@ export interface Props { name?: string; color?: string; + href?: string; + isNews?: boolean; class?: string; } -const { name, color = '', class: className = '' } = Astro.props; +const { + name, + color = '', + href, + isNews = false, + class: className = '' +} = Astro.props; function extractColorClass(colorString: string): string { if (!colorString) return 'bg-blue'; @@ -32,10 +40,100 @@ function extractColorClass(colorString: string): string { } const bgClass = extractColorClass(color); +const Tag = href ? 'a' : 'span'; --- -{name && ( -
- {name} -
-)} + + {/* Плашка новости, если isNews = true */} + {isNews && ( + + новости + + )} + + {/* Плашка рубрики */} + {name && ( + e.stopPropagation()} + > + {name} + + )} + + + \ No newline at end of file diff --git a/src/components/ContentGrid.astro b/src/components/ContentGrid.astro index 162a158..b453d25 100644 --- a/src/components/ContentGrid.astro +++ b/src/components/ContentGrid.astro @@ -84,19 +84,16 @@ function shouldBeLarge(index: number): boolean { ) : (
)} - - {item.categories?.nodes?.[0] && ( - e.stopPropagation()} - > - - - )} + + + {item.categories?.nodes?.[0] && ( + + )}
-
+
diff --git a/src/pages/index.astro b/src/pages/index.astro index 005a3e1..ae8924c 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -19,7 +19,6 @@ import MainLine from '@components/MainLine.astro'; import HomeNews from "@components/HomeNews.astro"; - //ISR export const prerender = false; --- diff --git a/src/pages/news/[...slug].astro b/src/pages/news/[...slug].astro index d6cf4d5..b902aa1 100644 --- a/src/pages/news/[...slug].astro +++ b/src/pages/news/[...slug].astro @@ -3,6 +3,7 @@ import MainLayout from '@layouts/MainLayout.astro'; import NewsSingle from '@components/NewsSingle.astro'; import { detectPageType } from '@lib/detect-page-type'; +import { wpInfo } from '@lib/wpInfo'; import { getAnewById } from '@lib/api/posts'; export const prerender = false; @@ -10,6 +11,14 @@ export const prerender = false; const pathname = Astro.url.pathname; const pageInfo = detectPageType(pathname); + +// Определяем категорию +if (!wpInfo.isLoaded()) { + await wpInfo.fetchAllCategories(); +} + +const category = wpInfo.getCategoryBySlug(pageInfo.categorySlug); + const fullUrl = Astro.url.href; const fullPath = Astro.url.origin + Astro.url.pathname; @@ -39,7 +48,11 @@ if (import.meta.env.DEV) { } --- - + {pageInfo.type === 'single' && post ? ( diff --git a/src/pages/news/index.astro b/src/pages/news/index.astro new file mode 100644 index 0000000..e021b7a --- /dev/null +++ b/src/pages/news/index.astro @@ -0,0 +1,12 @@ +--- + +import MainLayout from '@layouts/MainLayout.astro'; + +--- + + +

Все новости

+
\ No newline at end of file diff --git a/src/styles/components/ContentGrid.css b/src/styles/components/ContentGrid.css index ca49317..83bced4 100644 --- a/src/styles/components/ContentGrid.css +++ b/src/styles/components/ContentGrid.css @@ -97,26 +97,7 @@ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); } -/* Бейдж категории */ -.post-category-badge { - position: absolute; - top: 15px; - right: 15px; - background: #2563eb; - color: white; - padding: 5px 10px; - border-radius: 4px; - font-size: 11px; - font-weight: 600; - text-transform: uppercase; - letter-spacing: 0.5px; - z-index: 2; - box-shadow: 0 2px 5px rgba(0,0,0,0.2); - max-width: 80%; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; -} + /* Оверлей с контентом */ .post-content-overlay { @@ -137,6 +118,10 @@ gap: 8px; } + + + + .post-meta-overlay { margin-bottom: 3px; } @@ -160,6 +145,11 @@ text-overflow: ellipsis; } +.category-badge-white{ + background-color: white; + color: black; +} + .author-name { font-size: 12px; color: rgba(255, 255, 255, 0.85);