mirror of
https://github.com/KazooTTT/kazoottt-blog-v2.git
synced 2025-06-24 11:11:29 +08:00
Compare commits
3 Commits
0888432c86
...
ca74c1c589
Author | SHA1 | Date | |
---|---|---|---|
ca74c1c589 | |||
94e6babb46 | |||
e60539598e |
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
import { getAllPosts } from "@/data/post";
|
import { getAllPosts } from "@/data/post";
|
||||||
import type { GetStaticPaths, InferGetStaticPropsType } from "astro";
|
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
|
// 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 () => {
|
export const getStaticPaths = (async () => {
|
||||||
@ -11,8 +11,6 @@ export const getStaticPaths = (async () => {
|
|||||||
}));
|
}));
|
||||||
}) satisfies GetStaticPaths;
|
}) satisfies GetStaticPaths;
|
||||||
|
|
||||||
type Props = InferGetStaticPropsType<typeof getStaticPaths>;
|
|
||||||
|
|
||||||
const currentPath = Astro.url.pathname;
|
const currentPath = Astro.url.pathname;
|
||||||
const newPath = currentPath.replace("/blog/", "/posts/");
|
const newPath = currentPath.replace("/blog/", "/posts/");
|
||||||
return Astro.redirect(newPath);
|
return Astro.redirect(newPath);
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
---
|
---
|
||||||
import type { CollectionEntry } from "astro:content";
|
|
||||||
import { getAllPosts, getUniqueCategories } from "@/data/post";
|
import { getAllPosts, getUniqueCategories } from "@/data/post";
|
||||||
import { collectionDateSort } from "@/utils/date";
|
import { collectionDateSort } from "@/utils/date";
|
||||||
import type { GetStaticPaths, Page } from "astro";
|
import type { GetStaticPaths } from "astro";
|
||||||
|
|
||||||
export const getStaticPaths: GetStaticPaths = async ({ paginate }) => {
|
export const getStaticPaths: GetStaticPaths = async ({ paginate }) => {
|
||||||
const allPosts = await getAllPosts();
|
const allPosts = await getAllPosts();
|
||||||
@ -18,10 +17,6 @@ export const getStaticPaths: GetStaticPaths = async ({ paginate }) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
interface Props {
|
|
||||||
page: Page<CollectionEntry<"post">>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentPath = Astro.url.pathname;
|
const currentPath = Astro.url.pathname;
|
||||||
const newPath = currentPath.replace("/category/", "/categories/");
|
const newPath = currentPath.replace("/category/", "/categories/");
|
||||||
return Astro.redirect(newPath);
|
return Astro.redirect(newPath);
|
||||||
|
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);
|
||||||
|
---
|
18
src/pages/diary/[...slug].astro
Normal file
18
src/pages/diary/[...slug].astro
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
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,8 +1,7 @@
|
|||||||
---
|
---
|
||||||
import type { CollectionEntry } from "astro:content";
|
|
||||||
import { getAllPosts, getUniqueTags } from "@/data/post";
|
import { getAllPosts, getUniqueTags } from "@/data/post";
|
||||||
import { collectionDateSort } from "@/utils/date";
|
import { collectionDateSort } from "@/utils/date";
|
||||||
import type { GetStaticPaths, Page } from "astro";
|
import type { GetStaticPaths } from "astro";
|
||||||
|
|
||||||
export const getStaticPaths: GetStaticPaths = async ({ paginate }) => {
|
export const getStaticPaths: GetStaticPaths = async ({ paginate }) => {
|
||||||
const allPosts = await getAllPosts();
|
const allPosts = await getAllPosts();
|
||||||
@ -18,10 +17,6 @@ export const getStaticPaths: GetStaticPaths = async ({ paginate }) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
interface Props {
|
|
||||||
page: Page<CollectionEntry<"post">>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentPath = Astro.url.pathname;
|
const currentPath = Astro.url.pathname;
|
||||||
const newPath = currentPath.replace("/tag/", "/tags/");
|
const newPath = currentPath.replace("/tag/", "/tags/");
|
||||||
return Astro.redirect(newPath);
|
return Astro.redirect(newPath);
|
||||||
|
Reference in New Issue
Block a user