Better getStaticPaths structure for blog endpoints
This commit is contained in:
@ -7,7 +7,9 @@ import Pagination from '~/components/blog/Pagination.astro';
|
||||
|
||||
import { blogListRobots, getStaticPathsBlogList } from '~/utils/blog';
|
||||
|
||||
export const getStaticPaths = getStaticPathsBlogList();
|
||||
export async function getStaticPaths ({ paginate }) {
|
||||
return await getStaticPathsBlogList({ paginate });
|
||||
}
|
||||
|
||||
const { page } = Astro.props;
|
||||
const currentPage = page.currentPage ?? 1;
|
||||
|
@ -6,7 +6,9 @@ import BlogList from '~/components/blog/List.astro';
|
||||
import Headline from '~/components/blog/Headline.astro';
|
||||
import Pagination from '~/components/blog/Pagination.astro';
|
||||
|
||||
export const getStaticPaths = getStaticPathsBlogCategory();
|
||||
export async function getStaticPaths ({ paginate }) {
|
||||
return await getStaticPathsBlogCategory({ paginate });
|
||||
}
|
||||
|
||||
const { page, category } = Astro.props;
|
||||
|
||||
|
@ -6,7 +6,9 @@ import BlogList from '~/components/blog/List.astro';
|
||||
import Headline from '~/components/blog/Headline.astro';
|
||||
import Pagination from '~/components/blog/Pagination.astro';
|
||||
|
||||
export const getStaticPaths = getStaticPathsBlogTag();
|
||||
export async function getStaticPaths ({ paginate }) {
|
||||
return await getStaticPathsBlogTag({ paginate });
|
||||
}
|
||||
|
||||
const { page, tag } = Astro.props;
|
||||
|
||||
|
@ -9,7 +9,9 @@ import { getCanonical, getPermalink } from '~/utils/permalinks';
|
||||
import { getStaticPathsBlogPost, blogPostRobots } from '~/utils/blog';
|
||||
import { findImage } from '~/utils/images';
|
||||
|
||||
export const getStaticPaths = getStaticPathsBlogPost();
|
||||
export async function getStaticPaths () {
|
||||
return await getStaticPathsBlogPost();
|
||||
}
|
||||
|
||||
const { post } = Astro.props;
|
||||
|
||||
|
@ -162,18 +162,16 @@ export const findLatestPosts = async ({ count }: { count?: number }): Promise<Ar
|
||||
};
|
||||
|
||||
/** */
|
||||
export const getStaticPathsBlogList =
|
||||
() =>
|
||||
async ({ paginate }) => {
|
||||
export const getStaticPathsBlogList = async ({ paginate }) => {
|
||||
if (!isBlogEnabled || !isBlogListRouteEnabled) return [];
|
||||
return paginate(await fetchPosts(), {
|
||||
params: { blog: BLOG_BASE || undefined },
|
||||
pageSize: blogPostsPerPage,
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
/** */
|
||||
export const getStaticPathsBlogPost = () => async () => {
|
||||
export const getStaticPathsBlogPost = async () => {
|
||||
if (!isBlogEnabled || !isBlogPostRouteEnabled) return [];
|
||||
return (await fetchPosts()).map((post) => ({
|
||||
params: {
|
||||
@ -184,9 +182,7 @@ export const getStaticPathsBlogPost = () => async () => {
|
||||
};
|
||||
|
||||
/** */
|
||||
export const getStaticPathsBlogCategory =
|
||||
() =>
|
||||
async ({ paginate }) => {
|
||||
export const getStaticPathsBlogCategory = async ({ paginate }) => {
|
||||
if (!isBlogEnabled || !isBlogCategoryRouteEnabled) return [];
|
||||
|
||||
const posts = await fetchPosts();
|
||||
@ -205,12 +201,10 @@ export const getStaticPathsBlogCategory =
|
||||
}
|
||||
)
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
/** */
|
||||
export const getStaticPathsBlogTag =
|
||||
() =>
|
||||
async ({ paginate }) => {
|
||||
export const getStaticPathsBlogTag = async ({ paginate }) => {
|
||||
if (!isBlogEnabled || !isBlogTagRouteEnabled) return [];
|
||||
|
||||
const posts = await fetchPosts();
|
||||
@ -229,4 +223,4 @@ export const getStaticPathsBlogTag =
|
||||
}
|
||||
)
|
||||
);
|
||||
};
|
||||
};
|
||||
|
Reference in New Issue
Block a user