3 Commits

5 changed files with 46 additions and 15 deletions

View File

@ -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);

View File

@ -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);

View 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);
---

View 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);
---

View File

@ -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);