From 1e5f5a953588cefa75396454c9aed0a79552db14 Mon Sep 17 00:00:00 2001 From: Dawid Rycerz Date: Thu, 3 Jul 2025 13:09:53 +0300 Subject: Migrate notes to micro --- src/components/BaseHead.astro | 2 +- src/components/note/Note.astro | 2 +- src/pages/index.astro | 14 ++++----- src/pages/micro/[...page].astro | 63 +++++++++++++++++++++++++++++++++++++++++ src/pages/micro/[...slug].astro | 31 ++++++++++++++++++++ src/pages/micro/rss.xml.ts | 18 ++++++++++++ src/pages/notes/[...page].astro | 63 ----------------------------------------- src/pages/notes/[...slug].astro | 31 -------------------- src/pages/notes/rss.xml.ts | 18 ------------ src/site.config.ts | 4 +-- 10 files changed, 123 insertions(+), 123 deletions(-) create mode 100644 src/pages/micro/[...page].astro create mode 100644 src/pages/micro/[...slug].astro create mode 100644 src/pages/micro/rss.xml.ts delete mode 100644 src/pages/notes/[...page].astro delete mode 100644 src/pages/notes/[...slug].astro delete mode 100644 src/pages/notes/rss.xml.ts diff --git a/src/components/BaseHead.astro b/src/components/BaseHead.astro index 7ff861f..ceb55ea 100644 --- a/src/components/BaseHead.astro +++ b/src/components/BaseHead.astro @@ -71,7 +71,7 @@ const socialImageURL = new URL(ogImage ? ogImage : "/social-card.png", Astro.url {/* RSS auto-discovery */} - + {/* Webmentions */} { diff --git a/src/components/note/Note.astro b/src/components/note/Note.astro index cff3414..d96cb6d 100644 --- a/src/components/note/Note.astro +++ b/src/components/note/Note.astro @@ -21,7 +21,7 @@ const { Content } = await render(note); { isPreview ? ( - + {note.data.title} ) : ( diff --git a/src/pages/index.astro b/src/pages/index.astro index a539717..4b813da 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -14,10 +14,10 @@ const allPostsByDate = allPosts .sort(collectionDateSort) .slice(0, MAX_POSTS) as CollectionEntry<"post">[]; -// Notes -const MAX_NOTES = 5; -const allNotes = await getCollection("note"); -const latestNotes = allNotes.sort(collectionDateSort).slice(0, MAX_NOTES); +// Micro +const MAX_MICRO = 5; +const allMicro = await getCollection("note"); +const latestMicro = allMicro.sort(collectionDateSort).slice(0, MAX_MICRO); --- @@ -46,13 +46,13 @@ const latestNotes = allNotes.sort(collectionDateSort).slice(0, MAX_NOTES); { - latestNotes.length > 0 && ( + latestMicro.length > 0 && (

- Notes + Micro

    - {latestNotes.map((note) => ( + {latestMicro.map((note) => (
  • diff --git a/src/pages/micro/[...page].astro b/src/pages/micro/[...page].astro new file mode 100644 index 0000000..08f5fd3 --- /dev/null +++ b/src/pages/micro/[...page].astro @@ -0,0 +1,63 @@ +--- +import { type CollectionEntry, getCollection } from "astro:content"; +import Pagination from "@/components/Paginator.astro"; +import Note from "@/components/note/Note.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 }); +}) satisfies GetStaticPaths; + +interface Props { + page: Page>; + uniqueTags: string[]; +} + +const { page } = Astro.props; + +const meta = { + description: "Read my collection of micro posts", + title: "Micro", +}; + +const paginationProps = { + ...(page.url.prev && { + prevUrl: { + text: "← Previous Page", + url: page.url.prev, + }, + }), + ...(page.url.next && { + nextUrl: { + text: "Next Page →", + url: page.url.next, + }, + }), +}; +--- + + +
    +

    + Micro + RSS feed + +

    +
      + { + page.data.map((note) => ( +
    • + +
    • + )) + } +
    + +
    +
    diff --git a/src/pages/micro/[...slug].astro b/src/pages/micro/[...slug].astro new file mode 100644 index 0000000..2ce847d --- /dev/null +++ b/src/pages/micro/[...slug].astro @@ -0,0 +1,31 @@ +--- +import { getCollection } from "astro:content"; + +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 }, + })); +}) satisfies GetStaticPaths; + +export type Props = InferGetStaticPropsType; + +const { note } = Astro.props; + +const meta = { + description: + note.data.description || + `Read about my note posted on: ${note.data.publishDate.toLocaleDateString()}`, + title: note.data.title, +}; +--- + + + + diff --git a/src/pages/micro/rss.xml.ts b/src/pages/micro/rss.xml.ts new file mode 100644 index 0000000..7311319 --- /dev/null +++ b/src/pages/micro/rss.xml.ts @@ -0,0 +1,18 @@ +import { getCollection } from "astro:content"; +import { siteConfig } from "@/site.config"; +import rss from "@astrojs/rss"; + +export const GET = async () => { + const micro = await getCollection("note"); + + 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}/`, + })), + }); +}; diff --git a/src/pages/notes/[...page].astro b/src/pages/notes/[...page].astro deleted file mode 100644 index fdc5af9..0000000 --- a/src/pages/notes/[...page].astro +++ /dev/null @@ -1,63 +0,0 @@ ---- -import { type CollectionEntry, getCollection } from "astro:content"; -import Pagination from "@/components/Paginator.astro"; -import Note from "@/components/note/Note.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_NOTES_PER_PAGE = 10; - const allNotes = await getCollection("note"); - return paginate(allNotes.sort(collectionDateSort), { pageSize: MAX_NOTES_PER_PAGE }); -}) satisfies GetStaticPaths; - -interface Props { - page: Page>; - uniqueTags: string[]; -} - -const { page } = Astro.props; - -const meta = { - description: "Read my collection of notes", - title: "Notes", -}; - -const paginationProps = { - ...(page.url.prev && { - prevUrl: { - text: "← Previous Page", - url: page.url.prev, - }, - }), - ...(page.url.next && { - nextUrl: { - text: "Next Page →", - url: page.url.next, - }, - }), -}; ---- - - -
    -

    - Notes - RSS feed - -

    -
      - { - page.data.map((note) => ( -
    • - -
    • - )) - } -
    - -
    -
    diff --git a/src/pages/notes/[...slug].astro b/src/pages/notes/[...slug].astro deleted file mode 100644 index 2ce847d..0000000 --- a/src/pages/notes/[...slug].astro +++ /dev/null @@ -1,31 +0,0 @@ ---- -import { getCollection } from "astro:content"; - -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 }, - })); -}) satisfies GetStaticPaths; - -export type Props = InferGetStaticPropsType; - -const { note } = Astro.props; - -const meta = { - description: - note.data.description || - `Read about my note posted on: ${note.data.publishDate.toLocaleDateString()}`, - title: note.data.title, -}; ---- - - - - diff --git a/src/pages/notes/rss.xml.ts b/src/pages/notes/rss.xml.ts deleted file mode 100644 index 0f1f945..0000000 --- a/src/pages/notes/rss.xml.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { getCollection } from "astro:content"; -import { siteConfig } from "@/site.config"; -import rss from "@astrojs/rss"; - -export const GET = async () => { - const notes = await getCollection("note"); - - return rss({ - title: siteConfig.title, - description: siteConfig.description, - site: import.meta.env.SITE, - items: notes.map((note) => ({ - title: note.data.title, - pubDate: note.data.publishDate, - link: `notes/${note.id}/`, - })), - }); -}; diff --git a/src/site.config.ts b/src/site.config.ts index f4f7539..5abb1ae 100644 --- a/src/site.config.ts +++ b/src/site.config.ts @@ -45,8 +45,8 @@ export const menuLinks: { path: string; title: string }[] = [ title: "Blog", }, { - path: "/notes/", - title: "Notes", + path: "/micro/", + title: "Micro", }, ]; -- cgit v1.2.3