From cad0806f8c18b111d92b8fe489e7781751bccf8b Mon Sep 17 00:00:00 2001 From: StepanovPlaton Date: Tue, 3 Feb 2026 17:29:11 +0400 Subject: [PATCH] New root page --- src/pages/index.astro | 113 +++++++++++++++++++++++++++ src/pages/{ => news}/[...page].astro | 6 +- src/pages/news/index.astro | 35 +++++++++ 3 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 src/pages/index.astro rename src/pages/{ => news}/[...page].astro (90%) create mode 100644 src/pages/news/index.astro diff --git a/src/pages/index.astro b/src/pages/index.astro new file mode 100644 index 0000000..6749b11 --- /dev/null +++ b/src/pages/index.astro @@ -0,0 +1,113 @@ +--- +import { Icon } from "astro-icon/components"; + +import { type NavbarLink } from "@/types/config"; +import { navbarConfig } from "@/config"; +import { LinkPresets } from "@constants/link-presets"; +import { url } from "@utils/url"; +import GridLayout from "@layouts/grid.astro"; +import { siteConfig } from "@/config"; + + +// Получаем все ссылки из navbar, включая основные и с подразделами +const allLinks: NavbarLink[] = []; + +navbarConfig.links.forEach(link => { + if (typeof link === "number") { + // Это LinkPreset + const preset = LinkPresets[link]; + if (preset) { + allLinks.push(preset); + } + } else { + // Это NavbarLink + allLinks.push(link); + } +}); + +// Добавляем ссылку на новости/ленту постов +const newsLink: NavbarLink = { + name: "Новости", + url: "/news/", + icon: "material-symbols:article", + description: "Лента постов и статей", +}; + +// Вставляем ссылку на новости в начало списка +allLinks.unshift(newsLink); + +const pageTitle = siteConfig.title; +const pageDescription = siteConfig.subtitle || ""; +--- + + +
+
+ +
+

+ {pageTitle} +

+ {pageDescription && ( +

+ {pageDescription} +

+ )} +
+ +
+ {allLinks.map(link => { + // Для ссылок с подразделами показываем саму ссылку + const hasChildren = link.children && link.children.length > 0; + const linkUrl = hasChildren ? link.url : (link.external ? link.url : url(link.url)); + + return ( + +
+ {link.icon && } +
+

+ {link.name} +

+ {link.description && ( +

+ {link.description} +

+ )} +
+ ); + })} +
+
+
+
+ + diff --git a/src/pages/[...page].astro b/src/pages/news/[...page].astro similarity index 90% rename from src/pages/[...page].astro rename to src/pages/news/[...page].astro index 19520b4..6cb09f7 100644 --- a/src/pages/[...page].astro +++ b/src/pages/news/[...page].astro @@ -13,7 +13,9 @@ import GridLayout from "@layouts/grid.astro"; export const getStaticPaths = (async ({ paginate }) => { const allBlogPosts = await getSortedPosts(); - return paginate(allBlogPosts, { pageSize: PAGE_SIZE }); + return paginate(allBlogPosts, { + pageSize: PAGE_SIZE + }); }) satisfies GetStaticPaths; // https://github.com/withastro/astro/issues/6507#issuecomment-1489916992 @@ -26,4 +28,4 @@ const len = page.data.length; - \ No newline at end of file + diff --git a/src/pages/news/index.astro b/src/pages/news/index.astro new file mode 100644 index 0000000..d949ecd --- /dev/null +++ b/src/pages/news/index.astro @@ -0,0 +1,35 @@ +--- +export const prerender = true; + + +import { PAGE_SIZE } from "@constants/constants"; +import { getSortedPosts } from "@utils/content"; +import Pagination from "@components/pagination.astro"; +import PostPage from "@components/postPage.astro"; +import GridLayout from "@layouts/grid.astro"; + + +const allBlogPosts = await getSortedPosts(); +const firstPagePosts = allBlogPosts.slice(0, PAGE_SIZE); +const totalPages = Math.ceil(allBlogPosts.length / PAGE_SIZE); + +const page = { + currentPage: 1, + lastPage: totalPages, + size: PAGE_SIZE, + total: allBlogPosts.length, + data: firstPagePosts.map((post, index) => ({ + ...post, + index: index + 1, + })), +}; + +const len = page.data.length; +--- + + + + {totalPages > 1 && ( + + )} +