diff options
| author | Dawid Rycerz <dawid@rycerz.xyz> | 2025-07-03 13:46:07 +0300 |
|---|---|---|
| committer | Dawid Rycerz <dawid@rycerz.xyz> | 2025-07-03 13:46:07 +0300 |
| commit | f100d259d2ffebe61fef56ea3964f6d534d598c8 (patch) | |
| tree | 09d06511506da9c35585740d56598eb542fac079 /src/pages | |
| parent | 1e5f5a953588cefa75396454c9aed0a79552db14 (diff) | |
Initial pleroma pull support
Diffstat (limited to 'src/pages')
| -rw-r--r-- | src/pages/index.astro | 2 | ||||
| -rw-r--r-- | src/pages/micro/[...page].astro | 23 | ||||
| -rw-r--r-- | src/pages/micro/[...slug].astro | 18 | ||||
| -rw-r--r-- | src/pages/micro/rss.xml.ts | 22 | ||||
| -rw-r--r-- | src/pages/og-image/[...slug].png.ts | 8 | ||||
| -rw-r--r-- | src/pages/posts/[...page].astro | 6 | ||||
| -rw-r--r-- | src/pages/posts/[...slug].astro | 2 | ||||
| -rw-r--r-- | src/pages/rss.xml.ts | 2 | ||||
| -rw-r--r-- | src/pages/tags/[tag]/[...page].astro | 6 |
9 files changed, 58 insertions, 31 deletions
diff --git a/src/pages/index.astro b/src/pages/index.astro index 4b813da..f3aac47 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,8 +1,8 @@ --- import { type CollectionEntry, getCollection } from "astro:content"; -import SocialList from "@/components/SocialList.astro"; import PostPreview from "@/components/blog/PostPreview.astro"; import Note from "@/components/note/Note.astro"; +import SocialList from "@/components/SocialList.astro"; import { getAllPosts } from "@/data/post"; import PageLayout from "@/layouts/Base.astro"; import { collectionDateSort } from "@/utils/date"; diff --git a/src/pages/micro/[...page].astro b/src/pages/micro/[...page].astro index 08f5fd3..b4e3e07 100644 --- a/src/pages/micro/[...page].astro +++ b/src/pages/micro/[...page].astro @@ -1,20 +1,31 @@ --- import { type CollectionEntry, getCollection } from "astro:content"; -import Pagination from "@/components/Paginator.astro"; +import type { GetStaticPaths, Page } from "astro"; +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"; -import type { GetStaticPaths, Page } from "astro"; -import { Icon } from "astro-icon/components"; export const getStaticPaths = (async ({ paginate }) => { const MAX_MICRO_PER_PAGE = 10; - const allMicro = await getCollection("note"); - return paginate(allMicro.sort(collectionDateSort), { pageSize: MAX_MICRO_PER_PAGE }); + + // 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 + ]); + + // Combine and sort all micro posts + const allMicroPosts = [...allNotes, ...allMicro].sort( + (a, b) => b.data.publishDate.getTime() - a.data.publishDate.getTime(), + ); + + return paginate(allMicroPosts, { pageSize: MAX_MICRO_PER_PAGE }); }) satisfies GetStaticPaths; interface Props { - page: Page<CollectionEntry<"note">>; + page: Page<CollectionEntry<"note"> | CollectionEntry<"micro">>; uniqueTags: string[]; } diff --git a/src/pages/micro/[...slug].astro b/src/pages/micro/[...slug].astro index 2ce847d..54f6234 100644 --- a/src/pages/micro/[...slug].astro +++ b/src/pages/micro/[...slug].astro @@ -1,16 +1,22 @@ --- import { getCollection } from "astro:content"; - +import type { GetStaticPaths, InferGetStaticPropsType } from "astro"; import Note from "@/components/note/Note.astro"; import PageLayout from "@/layouts/Base.astro"; -import type { GetStaticPaths, InferGetStaticPropsType } 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 }, + // 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 + ]); + + const allPosts = [...allNotes, ...allMicro]; + + return allPosts.map((post) => ({ + params: { slug: post.id }, + props: { note: post }, // Keep 'note' name for compatibility with existing component })); }) satisfies GetStaticPaths; diff --git a/src/pages/micro/rss.xml.ts b/src/pages/micro/rss.xml.ts index 7311319..0827ccb 100644 --- a/src/pages/micro/rss.xml.ts +++ b/src/pages/micro/rss.xml.ts @@ -1,18 +1,28 @@ import { getCollection } from "astro:content"; -import { siteConfig } from "@/site.config"; import rss from "@astrojs/rss"; +import { siteConfig } from "@/site.config"; export const GET = async () => { - const micro = await getCollection("note"); + // 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 + ]); + + // Combine and sort all micro posts + const allMicroPosts = [...allNotes, ...allMicro].sort( + (a, b) => b.data.publishDate.getTime() - a.data.publishDate.getTime(), + ); return rss({ title: siteConfig.title, description: siteConfig.description, site: import.meta.env.SITE, - items: micro.map((note) => ({ - title: note.data.title, - pubDate: note.data.publishDate, - link: `micro/${note.id}/`, + items: allMicroPosts.map((post) => ({ + title: post.data.title, + pubDate: post.data.publishDate, + link: `micro/${post.id}/`, + description: post.data.description, })), }); }; diff --git a/src/pages/og-image/[...slug].png.ts b/src/pages/og-image/[...slug].png.ts index a4982d8..f58316c 100644 --- a/src/pages/og-image/[...slug].png.ts +++ b/src/pages/og-image/[...slug].png.ts @@ -1,12 +1,12 @@ +import { Resvg } from "@resvg/resvg-js"; +import type { APIContext, InferGetStaticPropsType } from "astro"; +import satori, { type SatoriOptions } from "satori"; +import { html } from "satori-html"; import RobotoMonoBold from "@/assets/roboto-mono-700.ttf"; import RobotoMono from "@/assets/roboto-mono-regular.ttf"; import { getAllPosts } from "@/data/post"; import { siteConfig } from "@/site.config"; import { getFormattedDate } from "@/utils/date"; -import { Resvg } from "@resvg/resvg-js"; -import type { APIContext, InferGetStaticPropsType } from "astro"; -import satori, { type SatoriOptions } from "satori"; -import { html } from "satori-html"; const ogOptions: SatoriOptions = { // debug: true, diff --git a/src/pages/posts/[...page].astro b/src/pages/posts/[...page].astro index 495fc7b..e07bc29 100644 --- a/src/pages/posts/[...page].astro +++ b/src/pages/posts/[...page].astro @@ -1,12 +1,12 @@ --- import type { CollectionEntry } from "astro:content"; -import Pagination from "@/components/Paginator.astro"; +import type { GetStaticPaths, Page } from "astro"; +import { Icon } from "astro-icon/components"; import PostPreview from "@/components/blog/PostPreview.astro"; +import Pagination from "@/components/Paginator.astro"; import { getAllPosts, getUniqueTags, groupPostsByYear } from "@/data/post"; import PageLayout from "@/layouts/Base.astro"; import { collectionDateSort } from "@/utils/date"; -import type { GetStaticPaths, Page } from "astro"; -import { Icon } from "astro-icon/components"; export const getStaticPaths = (async ({ paginate }) => { const MAX_POSTS_PER_PAGE = 10; diff --git a/src/pages/posts/[...slug].astro b/src/pages/posts/[...slug].astro index ca9c491..02047bd 100644 --- a/src/pages/posts/[...slug].astro +++ b/src/pages/posts/[...slug].astro @@ -1,8 +1,8 @@ --- import { render } from "astro:content"; +import type { GetStaticPaths, InferGetStaticPropsType } from "astro"; import { getAllPosts } from "@/data/post"; import PostLayout from "@/layouts/BlogPost.astro"; -import type { GetStaticPaths, InferGetStaticPropsType } 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 () => { diff --git a/src/pages/rss.xml.ts b/src/pages/rss.xml.ts index 1c305af..8a6525d 100644 --- a/src/pages/rss.xml.ts +++ b/src/pages/rss.xml.ts @@ -1,6 +1,6 @@ +import rss from "@astrojs/rss"; import { getAllPosts } from "@/data/post"; import { siteConfig } from "@/site.config"; -import rss from "@astrojs/rss"; export const GET = async () => { const posts = await getAllPosts(); diff --git a/src/pages/tags/[tag]/[...page].astro b/src/pages/tags/[tag]/[...page].astro index 56923fb..93ea3be 100644 --- a/src/pages/tags/[tag]/[...page].astro +++ b/src/pages/tags/[tag]/[...page].astro @@ -1,12 +1,12 @@ --- import { render } from "astro:content"; -import Pagination from "@/components/Paginator.astro"; +import type { GetStaticPaths, InferGetStaticPropsType } from "astro"; +import { Icon } from "astro-icon/components"; import PostPreview from "@/components/blog/PostPreview.astro"; +import Pagination from "@/components/Paginator.astro"; import { getAllPosts, getTagMeta, getUniqueTags } from "@/data/post"; import PageLayout from "@/layouts/Base.astro"; import { collectionDateSort } from "@/utils/date"; -import type { GetStaticPaths, InferGetStaticPropsType } from "astro"; -import { Icon } from "astro-icon/components"; export const getStaticPaths = (async ({ paginate }) => { const allPosts = await getAllPosts(); |
