mirror of
https://github.com/KazooTTT/kazoottt-blog-v2.git
synced 2025-06-17 07:51:21 +08:00
Revert "refactor: Update routing and remove legacy blog/tag/category pages"
This reverts commit e60539598e
.
This commit is contained in:
31
src/pages/blog/[...page].astro
Normal file
31
src/pages/blog/[...page].astro
Normal file
@ -0,0 +1,31 @@
|
||||
---
|
||||
import type { CollectionEntry } from "astro:content";
|
||||
import { getAllPosts, getUniqueCategories, getUniqueTags } from "@/data/post";
|
||||
import { collectionDateSort } from "@/utils/date";
|
||||
import type { GetStaticPaths, Page } from "astro";
|
||||
|
||||
export const getStaticPaths = (async ({ paginate }) => {
|
||||
const MAX_POSTS_PER_PAGE = 20;
|
||||
const MAX_TAGS = 7;
|
||||
const MAX_CATEGORIES = 7;
|
||||
const allPosts = await getAllPosts();
|
||||
const uniqueTags = getUniqueTags(allPosts).slice(0, MAX_TAGS);
|
||||
const uniqueCategories = getUniqueCategories(allPosts).slice(0, MAX_CATEGORIES);
|
||||
const postsCount = allPosts.length;
|
||||
return paginate(allPosts.sort(collectionDateSort), {
|
||||
pageSize: MAX_POSTS_PER_PAGE,
|
||||
props: { uniqueTags, uniqueCategories, postsCount },
|
||||
});
|
||||
}) satisfies GetStaticPaths;
|
||||
|
||||
interface Props {
|
||||
page: Page<CollectionEntry<"post">>;
|
||||
uniqueTags: string[];
|
||||
uniqueCategories: string[];
|
||||
postsCount: number;
|
||||
}
|
||||
|
||||
const currentPath = Astro.url.pathname;
|
||||
const newPath = currentPath.replace("/blog/", "/posts/");
|
||||
return Astro.redirect(newPath);
|
||||
---
|
@ -1,4 +1,16 @@
|
||||
---
|
||||
import { getAllPosts } from "@/data/post";
|
||||
import type { GetStaticPaths } from "astro";
|
||||
|
||||
// if you're using an adaptor in SSR mode, getStaticPaths wont work -> https://docs.astro.build/en/guides/routing/#modifying-the-slug-example-for-ssr
|
||||
export const getStaticPaths = (async () => {
|
||||
const blogEntries = await getAllPosts();
|
||||
return blogEntries.map((post) => ({
|
||||
params: { slug: post.id },
|
||||
props: { post },
|
||||
}));
|
||||
}) satisfies GetStaticPaths;
|
||||
|
||||
const currentPath = Astro.url.pathname;
|
||||
const newPath = currentPath.replace("/blog/", "/posts/");
|
||||
return Astro.redirect(newPath);
|
||||
|
23
src/pages/category/[category]/[...page].astro
Normal file
23
src/pages/category/[category]/[...page].astro
Normal file
@ -0,0 +1,23 @@
|
||||
---
|
||||
import { getAllPosts, getUniqueCategories } from "@/data/post";
|
||||
import { collectionDateSort } from "@/utils/date";
|
||||
import type { GetStaticPaths } from "astro";
|
||||
|
||||
export const getStaticPaths: GetStaticPaths = async ({ paginate }) => {
|
||||
const allPosts = await getAllPosts();
|
||||
const sortedPosts = allPosts.sort(collectionDateSort);
|
||||
const uniqueCategories = getUniqueCategories(sortedPosts);
|
||||
|
||||
return uniqueCategories.flatMap((category) => {
|
||||
const filterPosts = sortedPosts.filter((post) => post.data.category === category);
|
||||
return paginate(filterPosts, {
|
||||
pageSize: 20,
|
||||
params: { category },
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const currentPath = Astro.url.pathname;
|
||||
const newPath = currentPath.replace("/category/", "/categories/");
|
||||
return Astro.redirect(newPath);
|
||||
---
|
3
src/pages/category/index.astro
Normal file
3
src/pages/category/index.astro
Normal file
@ -0,0 +1,3 @@
|
||||
---
|
||||
return Astro.redirect("/categories");
|
||||
---
|
25
src/pages/diary/[...page].astro
Normal file
25
src/pages/diary/[...page].astro
Normal file
@ -0,0 +1,25 @@
|
||||
---
|
||||
import { type CollectionEntry, getCollection } from "astro:content";
|
||||
import { collectionModifiedDateSort } from "@/utils/date";
|
||||
import type { GetStaticPaths, Page } from "astro";
|
||||
|
||||
export const getStaticPaths = (async ({ paginate }) => {
|
||||
const MAX_NOTES_PER_PAGE = 10;
|
||||
const allNotes = await getCollection("note");
|
||||
const notesCount = allNotes.length;
|
||||
return paginate(allNotes.sort(collectionModifiedDateSort), {
|
||||
pageSize: MAX_NOTES_PER_PAGE,
|
||||
props: { notesCount },
|
||||
});
|
||||
}) satisfies GetStaticPaths;
|
||||
|
||||
interface Props {
|
||||
page: Page<CollectionEntry<"note">>;
|
||||
uniqueTags: string[];
|
||||
notesCount: number;
|
||||
}
|
||||
|
||||
const currentPath = Astro.url.pathname;
|
||||
const newPath = currentPath.replace("/diary/", "/notes/");
|
||||
return Astro.redirect(newPath);
|
||||
---
|
@ -1,4 +1,17 @@
|
||||
---
|
||||
import { getCollection } from "astro:content";
|
||||
|
||||
import type { GetStaticPaths } from "astro";
|
||||
|
||||
// if you're using an adaptor in SSR mode, getStaticPaths wont work -> https://docs.astro.build/en/guides/routing/#modifying-the-slug-example-for-ssr
|
||||
export const getStaticPaths = (async () => {
|
||||
const allNotes = await getCollection("note");
|
||||
return allNotes.map((note) => ({
|
||||
params: { slug: note.id },
|
||||
props: { note },
|
||||
}));
|
||||
}) satisfies GetStaticPaths;
|
||||
|
||||
const currentPath = Astro.url.pathname;
|
||||
const newPath = currentPath.replace("/diary/", "/notes/");
|
||||
return Astro.redirect(newPath);
|
||||
|
@ -1,5 +0,0 @@
|
||||
---
|
||||
const currentPath = Astro.url.pathname;
|
||||
const newPath = currentPath.replace("/tag/", "/tags/");
|
||||
return Astro.redirect(newPath);
|
||||
---
|
23
src/pages/tag/[tag]/[...page].astro
Normal file
23
src/pages/tag/[tag]/[...page].astro
Normal file
@ -0,0 +1,23 @@
|
||||
---
|
||||
import { getAllPosts, getUniqueTags } from "@/data/post";
|
||||
import { collectionDateSort } from "@/utils/date";
|
||||
import type { GetStaticPaths } from "astro";
|
||||
|
||||
export const getStaticPaths: GetStaticPaths = async ({ paginate }) => {
|
||||
const allPosts = await getAllPosts();
|
||||
const sortedPosts = allPosts.sort(collectionDateSort);
|
||||
const uniqueTags = getUniqueTags(sortedPosts);
|
||||
|
||||
return uniqueTags.flatMap((tag) => {
|
||||
const filterPosts = sortedPosts.filter((post) => post.data.tags.includes(tag));
|
||||
return paginate(filterPosts, {
|
||||
pageSize: 20,
|
||||
params: { tag },
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const currentPath = Astro.url.pathname;
|
||||
const newPath = currentPath.replace("/tag/", "/tags/");
|
||||
return Astro.redirect(newPath);
|
||||
---
|
3
src/pages/tag/index.astro
Normal file
3
src/pages/tag/index.astro
Normal file
@ -0,0 +1,3 @@
|
||||
---
|
||||
return Astro.redirect("/tags");
|
||||
---
|
Reference in New Issue
Block a user