Better getStaticPaths structure for blog endpoints

This commit is contained in:
prototypa
2023-08-12 02:22:19 -04:00
parent 8995bfbd5f
commit 9a350af269
5 changed files with 56 additions and 54 deletions

View File

@ -7,7 +7,9 @@ import Pagination from '~/components/blog/Pagination.astro';
import { blogListRobots, getStaticPathsBlogList } from '~/utils/blog'; import { blogListRobots, getStaticPathsBlogList } from '~/utils/blog';
export const getStaticPaths = getStaticPathsBlogList(); export async function getStaticPaths ({ paginate }) {
return await getStaticPathsBlogList({ paginate });
}
const { page } = Astro.props; const { page } = Astro.props;
const currentPage = page.currentPage ?? 1; const currentPage = page.currentPage ?? 1;

View File

@ -6,7 +6,9 @@ import BlogList from '~/components/blog/List.astro';
import Headline from '~/components/blog/Headline.astro'; import Headline from '~/components/blog/Headline.astro';
import Pagination from '~/components/blog/Pagination.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; const { page, category } = Astro.props;

View File

@ -6,7 +6,9 @@ import BlogList from '~/components/blog/List.astro';
import Headline from '~/components/blog/Headline.astro'; import Headline from '~/components/blog/Headline.astro';
import Pagination from '~/components/blog/Pagination.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; const { page, tag } = Astro.props;

View File

@ -9,7 +9,9 @@ import { getCanonical, getPermalink } from '~/utils/permalinks';
import { getStaticPathsBlogPost, blogPostRobots } from '~/utils/blog'; import { getStaticPathsBlogPost, blogPostRobots } from '~/utils/blog';
import { findImage } from '~/utils/images'; import { findImage } from '~/utils/images';
export const getStaticPaths = getStaticPathsBlogPost(); export async function getStaticPaths () {
return await getStaticPathsBlogPost();
}
const { post } = Astro.props; const { post } = Astro.props;

View File

@ -162,18 +162,16 @@ export const findLatestPosts = async ({ count }: { count?: number }): Promise<Ar
}; };
/** */ /** */
export const getStaticPathsBlogList = export const getStaticPathsBlogList = async ({ paginate }) => {
() =>
async ({ paginate }) => {
if (!isBlogEnabled || !isBlogListRouteEnabled) return []; if (!isBlogEnabled || !isBlogListRouteEnabled) return [];
return paginate(await fetchPosts(), { return paginate(await fetchPosts(), {
params: { blog: BLOG_BASE || undefined }, params: { blog: BLOG_BASE || undefined },
pageSize: blogPostsPerPage, pageSize: blogPostsPerPage,
}); });
}; };
/** */ /** */
export const getStaticPathsBlogPost = () => async () => { export const getStaticPathsBlogPost = async () => {
if (!isBlogEnabled || !isBlogPostRouteEnabled) return []; if (!isBlogEnabled || !isBlogPostRouteEnabled) return [];
return (await fetchPosts()).map((post) => ({ return (await fetchPosts()).map((post) => ({
params: { params: {
@ -184,9 +182,7 @@ export const getStaticPathsBlogPost = () => async () => {
}; };
/** */ /** */
export const getStaticPathsBlogCategory = export const getStaticPathsBlogCategory = async ({ paginate }) => {
() =>
async ({ paginate }) => {
if (!isBlogEnabled || !isBlogCategoryRouteEnabled) return []; if (!isBlogEnabled || !isBlogCategoryRouteEnabled) return [];
const posts = await fetchPosts(); const posts = await fetchPosts();
@ -205,12 +201,10 @@ export const getStaticPathsBlogCategory =
} }
) )
); );
}; };
/** */ /** */
export const getStaticPathsBlogTag = export const getStaticPathsBlogTag = async ({ paginate }) => {
() =>
async ({ paginate }) => {
if (!isBlogEnabled || !isBlogTagRouteEnabled) return []; if (!isBlogEnabled || !isBlogTagRouteEnabled) return [];
const posts = await fetchPosts(); const posts = await fetchPosts();
@ -229,4 +223,4 @@ export const getStaticPathsBlogTag =
} }
) )
); );
}; };