add new routing

This commit is contained in:
Andrey Kuvshinov
2025-12-17 23:05:49 +03:00
parent a72d47f6d9
commit 033158e384
9 changed files with 572 additions and 73 deletions

View File

@@ -1,26 +1,29 @@
---
import { fetchCategory } from '@api/categories';
import MainLayout from '@layouts/MainLayout.astro';
import CategoryArchive from '@templates/CategoryArchive.astro';
import { getCategory } from '@api/categories';
import { getArchivePostsById } from '@api/archiveById';
import { getNodeByURI, getCategoryPosts } from '@lib/api/all';
export const prerender = false; // ISR
//export const revalidate = 60;
export const prerender = false;
const { slug } = Astro.params;
const pathArray = Array.isArray(slug) ? slug : [slug];
const uri = slug ? `/${slug}` : '/';
let response;
let node = null;
// Получаем категорию по цепочке slug
const category = await getCategory(pathArray);
if (!category) return Astro.redirect('/404');
const perPage = 20;
try {
response = await getNodeByURI(uri);
node = response?.nodeByUri;
} catch (error) {
console.error('Error fetching node:', error);
}
// ISR кэширование
//Astro.response.headers.set(
// 'Cache-Control',
// 'public, s-maxage=3600, stale-while-revalidate=86400'
//);
---
<MainLayout title={category.name}>
<h1>{category.name}</h1>
</MainLayout>
Article
<p>{uri}</p>

View File

@@ -0,0 +1,30 @@
---
import MainLayout from '@layouts/MainLayout.astro';
import { getNodeByURI, getCategoryPosts } from '@lib/api/all';
export const prerender = false;
const { slug } = Astro.params;
const uri = slug ? `/${slug}` : '/';
let response;
let node = null;
try {
response = await getNodeByURI(uri);
node = response?.nodeByUri;
} catch (error) {
console.error('Error fetching node:', error);
}
// ISR кэширование
//Astro.response.headers.set(
// 'Cache-Control',
// 'public, s-maxage=3600, stale-while-revalidate=86400'
//);
---
News
<p>{uri}</p>