From d41eff9eccf66644c4c60f53cb516bf079937a28 Mon Sep 17 00:00:00 2001 From: aman333nolawz Date: Mon, 2 Mar 2026 21:49:13 +0530 Subject: Using astro-erudite for static site generation --- src/pages/blog/[...id].astro | 299 +++++++++++++++++++++++++++++++++++++++++ src/pages/blog/[...page].astro | 58 ++++++++ 2 files changed, 357 insertions(+) create mode 100644 src/pages/blog/[...id].astro create mode 100644 src/pages/blog/[...page].astro (limited to 'src/pages/blog') diff --git a/src/pages/blog/[...id].astro b/src/pages/blog/[...id].astro new file mode 100644 index 0000000..5cc9eab --- /dev/null +++ b/src/pages/blog/[...id].astro @@ -0,0 +1,299 @@ +--- +import Breadcrumbs from '@/components/Breadcrumbs.astro' +import Link from '@/components/Link.astro' +import PostHead from '@/components/PostHead.astro' +import PostNavigation from '@/components/PostNavigation.astro' +import SubpostsHeader from '@/components/SubpostsHeader.astro' +import SubpostsSidebar from '@/components/SubpostsSidebar.astro' +import TOCHeader from '@/components/TOCHeader.astro' +import TOCSidebar from '@/components/TOCSidebar.astro' +import { badgeVariants } from '@/components/ui/badge' +import { Button } from '@/components/ui/button' +import Layout from '@/layouts/Layout.astro' +import { + getAdjacentPosts, + getAllPostsAndSubposts, + getCombinedReadingTime, + getParentId, + getParentPost, + getPostReadingTime, + getSubpostCount, + getTOCSections, + hasSubposts, + isSubpost, + parseAuthors, +} from '@/lib/data-utils' +import { formatDate } from '@/lib/utils' +import { Icon } from 'astro-icon/components' +import { Image } from 'astro:assets' +import { render } from 'astro:content' + +export async function getStaticPaths() { + const posts = await getAllPostsAndSubposts() + return posts.map((post) => ({ + params: { id: post.id }, + props: post, + })) +} + +const post = Astro.props +const currentPostId = Astro.params.id +const { Content, headings } = await render(post) +const authors = await parseAuthors(post.data.authors ?? []) + +const isCurrentSubpost = isSubpost(currentPostId) +const navigation = await getAdjacentPosts(currentPostId) +const parentPost = isCurrentSubpost ? await getParentPost(currentPostId) : null + +const hasChildPosts = await hasSubposts(currentPostId) +const subpostCount = !isCurrentSubpost + ? await getSubpostCount(currentPostId) + : 0 +const postReadingTime = await getPostReadingTime(currentPostId) +const combinedReadingTime = + hasChildPosts && !isCurrentSubpost + ? await getCombinedReadingTime(currentPostId) + : null + +const tocSections = await getTOCSections(currentPostId) +--- + + + + { + (hasChildPosts || isCurrentSubpost) && ( + + ) + } + { + headings?.length > 0 && + !( + isCurrentSubpost && + headings.length === 1 && + headings[0].text === post.data.title + ) && + } + +
+
+ +
+ + { + post.data.image && ( + {post.data.title} + ) + } + +
+
+

+ {post.data.title} +

+ +
+ { + authors.length > 0 && ( +
+ {authors.map((author) => ( +
+ {author.name} + {author.isRegistered ? ( + + {author.name} + + ) : ( + {author.name} + )} +
+ ))} +
+ ) + } + +
+ {formatDate(post.data.date)} +
+ +
+ + {postReadingTime} + { + combinedReadingTime && + combinedReadingTime !== postReadingTime && ( + + {' '} + ({combinedReadingTime} total) + + ) + } + +
+ + { + subpostCount > 0 && ( +
+ + {subpostCount} subpost{subpostCount === 1 ? '' : 's'} +
+ ) + } +
+
+ { + post.data.tags && + post.data.tags.length > 0 && + post.data.tags.map((tag) => ( + + + {tag} + + )) + } +
+
+ + +
+ + { + tocSections.length > 0 && ( + + ) + } + +
+ +
+ + { + (hasChildPosts || isCurrentSubpost) && ( + + ) + } + + +
+ + + + +
+ + \ No newline at end of file diff --git a/src/pages/blog/[...page].astro b/src/pages/blog/[...page].astro new file mode 100644 index 0000000..eb196db --- /dev/null +++ b/src/pages/blog/[...page].astro @@ -0,0 +1,58 @@ +--- +import BlogCard from '@/components/BlogCard.astro' +import Breadcrumbs from '@/components/Breadcrumbs.astro' +import PageHead from '@/components/PageHead.astro' +import PaginationComponent from '@/components/ui/pagination' +import { SITE } from '@/consts' +import Layout from '@/layouts/Layout.astro' +import { getAllPosts, groupPostsByYear } from '@/lib/data-utils' +import type { PaginateFunction } from 'astro' + +export async function getStaticPaths({ + paginate, +}: { + paginate: PaginateFunction +}) { + const allPosts = await getAllPosts() + return paginate(allPosts, { pageSize: SITE.postsPerPage }) +} + +const { page } = Astro.props + +const postsByYear = groupPostsByYear(page.data) +const years = Object.keys(postsByYear).sort((a, b) => parseInt(b) - parseInt(a)) +--- + + + + + +
+ { + years.map((year) => ( +
+
{year}
+
    + {postsByYear[year].map((post) => ( +
  • + +
  • + ))} +
+
+ )) + } +
+ + +
-- cgit v1.2.3