diff options
| author | Dawid Rycerz <dawid@rycerz.xyz> | 2025-07-03 13:59:59 +0300 |
|---|---|---|
| committer | Dawid Rycerz <dawid@rycerz.xyz> | 2025-07-03 13:59:59 +0300 |
| commit | 4b9018b6d92ef8f1854d9dc44625295c2acd3fb3 (patch) | |
| tree | 10e01ec849c7439befd0a21f04021213e98d0f94 /src | |
| parent | f100d259d2ffebe61fef56ea3964f6d534d598c8 (diff) | |
Cleanup old notes feature
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/note/Note.astro | 2 | ||||
| -rw-r--r-- | src/content.config.ts | 13 | ||||
| -rw-r--r-- | src/content/note/welcome.md | 9 | ||||
| -rw-r--r-- | src/pages/index.astro | 2 | ||||
| -rw-r--r-- | src/pages/micro/[...page].astro | 14 | ||||
| -rw-r--r-- | src/pages/micro/[...slug].astro | 11 | ||||
| -rw-r--r-- | src/pages/micro/rss.xml.ts | 11 | ||||
| -rw-r--r-- | src/utils/date.ts | 4 | ||||
| -rw-r--r-- | src/utils/micro.ts | 16 |
9 files changed, 22 insertions, 60 deletions
diff --git a/src/components/note/Note.astro b/src/components/note/Note.astro index b6a11c8..54d1fc0 100644 --- a/src/components/note/Note.astro +++ b/src/components/note/Note.astro @@ -4,7 +4,7 @@ import type { HTMLTag, Polymorphic } from "astro/types"; import FormattedDate from "@/components/FormattedDate.astro"; type Props<Tag extends HTMLTag> = Polymorphic<{ as: Tag }> & { - note: CollectionEntry<"note">; + note: CollectionEntry<"micro">; isPreview?: boolean | undefined; }; diff --git a/src/content.config.ts b/src/content.config.ts index 5930884..c85d88e 100644 --- a/src/content.config.ts +++ b/src/content.config.ts @@ -37,17 +37,6 @@ const post = defineCollection({ }), }); -const note = defineCollection({ - loader: glob({ base: "./src/content/note", pattern: "**/*.{md,mdx}" }), - schema: baseSchema.extend({ - description: z.string().optional(), - publishDate: z - .string() - .datetime({ offset: true }) // Ensures ISO 8601 format with offsets allowed (e.g. "2024-01-01T00:00:00Z" and "2024-01-01T00:00:00+02:00") - .transform((val) => new Date(val)), - }), -}); - const micro = defineCollection({ loader: pleromaLoader({ instanceUrl: "https://social.craftknight.com", @@ -69,4 +58,4 @@ const tag = defineCollection({ }), }); -export const collections = { post, note, tag, micro }; +export const collections = { post, tag, micro }; diff --git a/src/content/note/welcome.md b/src/content/note/welcome.md deleted file mode 100644 index 204d804..0000000 --- a/src/content/note/welcome.md +++ /dev/null @@ -1,9 +0,0 @@ ---- -title: Hello, Welcome -description: An introduction to using the note feature in Astro Cactus -publishDate: "2024-10-14T11:23:00Z" ---- - -Hi, Hello. This is an example note feature included with Astro Cactus. - -They're for shorter, concise "post's" that you'd like to share, they generally don't include headings, but hey, that's entirely up to you. diff --git a/src/pages/index.astro b/src/pages/index.astro index f3aac47..df7a66a 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -16,7 +16,7 @@ const allPostsByDate = allPosts // Micro const MAX_MICRO = 5; -const allMicro = await getCollection("note"); +const allMicro = await getCollection("micro").catch(() => []); // Fallback to empty array if micro collection fails const latestMicro = allMicro.sort(collectionDateSort).slice(0, MAX_MICRO); --- diff --git a/src/pages/micro/[...page].astro b/src/pages/micro/[...page].astro index b4e3e07..edfecab 100644 --- a/src/pages/micro/[...page].astro +++ b/src/pages/micro/[...page].astro @@ -5,19 +5,15 @@ import { Icon } from "astro-icon/components"; import Note from "@/components/note/Note.astro"; import Pagination from "@/components/Paginator.astro"; import PageLayout from "@/layouts/Base.astro"; -import { collectionDateSort } from "@/utils/date"; export const getStaticPaths = (async ({ paginate }) => { const MAX_MICRO_PER_PAGE = 10; - // Get both local notes and Pleroma posts - const [allNotes, allMicro] = await Promise.all([ - getCollection("note"), - getCollection("micro").catch(() => []), // Fallback to empty array if micro collection fails - ]); + // Get only Pleroma posts + const allMicro = await getCollection("micro").catch(() => []); // Fallback to empty array if micro collection fails - // Combine and sort all micro posts - const allMicroPosts = [...allNotes, ...allMicro].sort( + // Sort all micro posts + const allMicroPosts = allMicro.sort( (a, b) => b.data.publishDate.getTime() - a.data.publishDate.getTime(), ); @@ -25,7 +21,7 @@ export const getStaticPaths = (async ({ paginate }) => { }) satisfies GetStaticPaths; interface Props { - page: Page<CollectionEntry<"note"> | CollectionEntry<"micro">>; + page: Page<CollectionEntry<"micro">>; uniqueTags: string[]; } diff --git a/src/pages/micro/[...slug].astro b/src/pages/micro/[...slug].astro index 54f6234..4cfae32 100644 --- a/src/pages/micro/[...slug].astro +++ b/src/pages/micro/[...slug].astro @@ -6,15 +6,10 @@ import PageLayout from "@/layouts/Base.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 () => { - // Get both local notes and Pleroma posts - const [allNotes, allMicro] = await Promise.all([ - getCollection("note"), - getCollection("micro").catch(() => []), // Fallback to empty array if micro collection fails - ]); + // Get only Pleroma posts + const allMicro = await getCollection("micro").catch(() => []); // Fallback to empty array if micro collection fails - const allPosts = [...allNotes, ...allMicro]; - - return allPosts.map((post) => ({ + return allMicro.map((post) => ({ params: { slug: post.id }, props: { note: post }, // Keep 'note' name for compatibility with existing component })); diff --git a/src/pages/micro/rss.xml.ts b/src/pages/micro/rss.xml.ts index 0827ccb..ce25129 100644 --- a/src/pages/micro/rss.xml.ts +++ b/src/pages/micro/rss.xml.ts @@ -3,14 +3,11 @@ import rss from "@astrojs/rss"; import { siteConfig } from "@/site.config"; export const GET = async () => { - // Get both local notes and Pleroma posts - const [allNotes, allMicro] = await Promise.all([ - getCollection("note"), - getCollection("micro").catch(() => []), // Fallback to empty array if micro collection fails - ]); + // Get only Pleroma posts + const allMicro = await getCollection("micro").catch(() => []); // Fallback to empty array if micro collection fails - // Combine and sort all micro posts - const allMicroPosts = [...allNotes, ...allMicro].sort( + // Sort all micro posts + const allMicroPosts = allMicro.sort( (a, b) => b.data.publishDate.getTime() - a.data.publishDate.getTime(), ); diff --git a/src/utils/date.ts b/src/utils/date.ts index b919810..b8c0376 100644 --- a/src/utils/date.ts +++ b/src/utils/date.ts @@ -16,8 +16,8 @@ export function getFormattedDate( } export function collectionDateSort( - a: CollectionEntry<"post" | "note" | "micro">, - b: CollectionEntry<"post" | "note" | "micro">, + a: CollectionEntry<"post" | "micro">, + b: CollectionEntry<"post" | "micro">, ) { return b.data.publishDate.getTime() - a.data.publishDate.getTime(); } diff --git a/src/utils/micro.ts b/src/utils/micro.ts index 7344850..51d336b 100644 --- a/src/utils/micro.ts +++ b/src/utils/micro.ts @@ -1,6 +1,6 @@ import type { CollectionEntry } from "astro:content"; -export type MicroEntry = CollectionEntry<"note">; +export type MicroEntry = CollectionEntry<"micro">; export function sortMicroEntries(entries: MicroEntry[]): MicroEntry[] { return entries.sort((a, b) => b.data.publishDate.getTime() - a.data.publishDate.getTime()); @@ -9,18 +9,12 @@ export function sortMicroEntries(entries: MicroEntry[]): MicroEntry[] { export async function getAllMicroPosts(): Promise<MicroEntry[]> { const { getCollection } = await import("astro:content"); - const notes = await getCollection("note"); - - // Try to get micro posts if available, otherwise just use notes + // Get only Pleroma micro posts try { const microPosts = await getCollection("micro"); - const allMicroPosts: (CollectionEntry<"note"> | CollectionEntry<"micro">)[] = [ - ...notes, - ...microPosts, - ]; - return sortMicroEntries(allMicroPosts as MicroEntry[]); + return sortMicroEntries(microPosts); } catch (error) { - console.warn("Micro collection not available, using notes only:", error); - return sortMicroEntries(notes); + console.warn("Micro collection not available:", error); + return []; } } |
