add new routing
This commit is contained in:
@@ -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>
|
||||
|
||||
|
||||
30
src/pages/news/[...slug].astro
Normal file
30
src/pages/news/[...slug].astro
Normal 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>
|
||||
|
||||
Reference in New Issue
Block a user