new logic routes
This commit is contained in:
@@ -1,21 +1,32 @@
|
||||
---
|
||||
import MainLayout from '@layouts/MainLayout.astro';
|
||||
import NewsSingle from '@components/NewsSingle.astro';
|
||||
|
||||
import { getNodeByURI, getCategoryPosts } from '@lib/api/all';
|
||||
import { getProfileArticleById } from '@lib/api/posts'; //логика
|
||||
|
||||
import { detectPageType } from '@lib/detect-page-type';
|
||||
|
||||
export const prerender = false;
|
||||
|
||||
const { slug } = Astro.params;
|
||||
const uri = slug ? `/${slug}` : '/';
|
||||
const pathname = Astro.url.pathname; // "/news/society/chto-sluchilos-nochju-27-oktyabrya-2025-goda-1772178/"
|
||||
const pageInfo = detectPageType(pathname); //определяем тип страницы
|
||||
|
||||
|
||||
let response;
|
||||
let node = null;
|
||||
let article = null;
|
||||
|
||||
if (pageInfo.type === 'single') { //одиночная статья
|
||||
|
||||
try {
|
||||
article = await getProfileArticleById(pageInfo.postId); //получвем данные поста
|
||||
} catch (error) {
|
||||
console.error('Error fetching node:', error);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
response = await getNodeByURI(uri);
|
||||
node = response?.nodeByUri;
|
||||
} catch (error) {
|
||||
console.error('Error fetching node:', error);
|
||||
}
|
||||
|
||||
// ISR кэширование
|
||||
//Astro.response.headers.set(
|
||||
@@ -24,6 +35,17 @@ try {
|
||||
//);
|
||||
---
|
||||
|
||||
Article
|
||||
<p>{uri}</p>
|
||||
<MainLayout
|
||||
title={article.title}
|
||||
description="Информационное агентство Деловой журнал Профиль"
|
||||
>
|
||||
|
||||
{pageInfo.type === 'single' && article ? (
|
||||
<NewsSingle post={article} pageInfo={pageInfo} />
|
||||
) : (
|
||||
// Можно добавить fallback контент
|
||||
<div>Загрузка или другой тип страницы...</div>
|
||||
)}
|
||||
|
||||
</MainLayout>
|
||||
|
||||
|
||||
@@ -1,16 +1,49 @@
|
||||
---
|
||||
import MainLayout from '@layouts/MainLayout.astro';
|
||||
import NewsSingle from '@components/NewsSingle.astro';
|
||||
|
||||
import { detectPageType } from '@lib/detect-page-type';
|
||||
|
||||
import { getAnewsById } from '@lib/api/posts'; //логика
|
||||
|
||||
|
||||
export const prerender = false;
|
||||
|
||||
const pathname = Astro.url.pathname; // "/news/society/chto-sluchilos-nochju-27-oktyabrya-2025-goda-1772178/"
|
||||
const pageInfo = detectPageType(pathname);
|
||||
|
||||
//console.log(pageInfo);
|
||||
|
||||
// Или для полного URL
|
||||
const fullUrl = Astro.url.href;
|
||||
// Или для origin + pathname
|
||||
const fullPath = Astro.url.origin + Astro.url.pathname;
|
||||
|
||||
|
||||
if (pageInfo.type === 'single' && pageInfo.contentType === 'news') {
|
||||
|
||||
if (pageInfo.postId && typeof pageInfo.postId === 'number') {
|
||||
|
||||
const response = await getAnewsById(pageInfo.postId);
|
||||
console.log(response);
|
||||
|
||||
//pageData = response?.post;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (import.meta.env.DEV) {
|
||||
|
||||
const currentFile = import.meta.url
|
||||
.replace('file://', '')
|
||||
.replace(process.cwd(), '')
|
||||
.replace(/^\//, '');
|
||||
|
||||
console.log('Файл:', currentFile);
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
<MainLayout>
|
||||
|
||||
Reference in New Issue
Block a user