From a889d57e13909efbf6987f92c96e74cf3ebe001e Mon Sep 17 00:00:00 2001 From: PranavU-Coder Date: Mon, 12 Oct 2026 03:05:07 +0530 Subject: [PATCH 1/3] feat: enhancing blogging-utility, following best SWE principles for writing code & removed redundant pages --- README.md | 3 +- WEBSITE_CONFIG.md | 29 +++++- app/authors/[id]/page.tsx | 63 +++++++++++ app/authors/page.tsx | 29 ++++++ app/blog/[uid]/page.tsx | 115 ++++++++++++++------- app/blog/page.tsx | 56 ++++++---- app/error.tsx | 2 +- app/events/page.tsx | 10 -- app/global-error.tsx | 8 +- app/layout.tsx | 24 ++--- app/not-found.tsx | 13 +-- app/page.tsx | 22 ++-- app/services/page.tsx | 21 ---- app/team/page.tsx | 10 +- components/BlogCard.tsx | 31 ------ components/CustomImage.tsx | 35 ------- components/Header.tsx | 111 -------------------- components/Links.tsx | 52 ---------- components/Logo.tsx | 20 ---- components/MarkdownRenderer.tsx | 10 -- components/ServerError.tsx | 19 ---- components/UnderDev.tsx | 18 ---- components/authors/AuthorAvatar.tsx | 37 +++++++ components/authors/AuthorCard.tsx | 73 +++++++++++++ components/authors/AuthorProfiles.tsx | 19 ++++ components/blog/BlogCard.tsx | 52 ++++++++++ components/blog/CoverImage.tsx | 33 ++++++ components/blog/HeadingList.tsx | 37 +++++++ components/blog/MarkdownRenderer.tsx | 13 +++ components/blog/PostHeader.tsx | 32 ++++++ components/blog/PostList.tsx | 16 +++ components/blog/PostMeta.tsx | 61 +++++++++++ components/blog/PostNavigation.tsx | 73 +++++++++++++ components/blog/TableOfContents.tsx | 48 +++++++++ components/blog/Tags.tsx | 19 ++++ components/common/Breadcrumbs.tsx | 45 ++++++++ components/common/Container.tsx | 9 ++ components/common/ServerError.tsx | 17 +++ components/common/StatusMessage.tsx | 18 ++++ components/common/ThemeScript.tsx | 8 ++ components/{ => common}/TransitionLink.tsx | 2 +- components/common/UnderDev.tsx | 13 +++ components/{ => layout}/Footer.tsx | 23 ++--- components/layout/Header.tsx | 29 ++++++ components/{ => layout}/Layout.tsx | 10 +- components/layout/Logo.tsx | 18 ++++ components/layout/MobileNav.tsx | 31 ++++++ components/layout/NavLinks.tsx | 38 +++++++ components/layout/SectionName.tsx | 12 +++ components/layout/ThemeToggle.tsx | 30 ++++++ components/layout/styles.ts | 2 + components/ui/button.tsx | 2 +- content/authors/karthik-prabhu.md | 3 + content/posts/advice-from-an-alumnus.md | 3 +- hooks/use-theme.ts | 48 +++++++++ hooks/use-visible-sections.ts | 47 +++++++++ lib/content/authors.ts | 78 ++++++++++++++ lib/content/collection.ts | 48 +++++++++ lib/content/markdown.ts | 46 +++++++++ lib/content/posts.ts | 74 +++++++++++++ lib/content/schema.ts | 30 ++++++ lib/format.ts | 9 ++ lib/posts.ts | 111 -------------------- lib/site.ts | 28 +++++ lib/theme-script.ts | 13 --- lib/theme.ts | 21 ++++ next.config.ts | 6 ++ package.json | 6 ++ pnpm-lock.yaml | 18 ++++ types/blog.ts | 29 ++++++ 70 files changed, 1554 insertions(+), 585 deletions(-) create mode 100644 app/authors/[id]/page.tsx create mode 100644 app/authors/page.tsx delete mode 100644 app/events/page.tsx delete mode 100644 app/services/page.tsx delete mode 100644 components/BlogCard.tsx delete mode 100644 components/CustomImage.tsx delete mode 100644 components/Header.tsx delete mode 100644 components/Links.tsx delete mode 100644 components/Logo.tsx delete mode 100644 components/MarkdownRenderer.tsx delete mode 100644 components/ServerError.tsx delete mode 100644 components/UnderDev.tsx create mode 100644 components/authors/AuthorAvatar.tsx create mode 100644 components/authors/AuthorCard.tsx create mode 100644 components/authors/AuthorProfiles.tsx create mode 100644 components/blog/BlogCard.tsx create mode 100644 components/blog/CoverImage.tsx create mode 100644 components/blog/HeadingList.tsx create mode 100644 components/blog/MarkdownRenderer.tsx create mode 100644 components/blog/PostHeader.tsx create mode 100644 components/blog/PostList.tsx create mode 100644 components/blog/PostMeta.tsx create mode 100644 components/blog/PostNavigation.tsx create mode 100644 components/blog/TableOfContents.tsx create mode 100644 components/blog/Tags.tsx create mode 100644 components/common/Breadcrumbs.tsx create mode 100644 components/common/Container.tsx create mode 100644 components/common/ServerError.tsx create mode 100644 components/common/StatusMessage.tsx create mode 100644 components/common/ThemeScript.tsx rename components/{ => common}/TransitionLink.tsx (100%) create mode 100644 components/common/UnderDev.tsx rename components/{ => layout}/Footer.tsx (87%) create mode 100644 components/layout/Header.tsx rename components/{ => layout}/Layout.tsx (90%) create mode 100644 components/layout/Logo.tsx create mode 100644 components/layout/MobileNav.tsx create mode 100644 components/layout/NavLinks.tsx create mode 100644 components/layout/SectionName.tsx create mode 100644 components/layout/ThemeToggle.tsx create mode 100644 components/layout/styles.ts create mode 100644 content/authors/karthik-prabhu.md create mode 100644 hooks/use-theme.ts create mode 100644 hooks/use-visible-sections.ts create mode 100644 lib/content/authors.ts create mode 100644 lib/content/collection.ts create mode 100644 lib/content/markdown.ts create mode 100644 lib/content/posts.ts create mode 100644 lib/content/schema.ts create mode 100644 lib/format.ts delete mode 100644 lib/posts.ts create mode 100644 lib/site.ts delete mode 100644 lib/theme-script.ts create mode 100644 lib/theme.ts diff --git a/README.md b/README.md index cf5a6da..350ba48 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,6 @@ pnpm format CI runs the production build with `pnpm build`. A deployed Node.js application starts with `pnpm start`. Configure hosting to use the repository root, with `pnpm install --frozen-lockfile` as the install command and `pnpm build` as the build command. -## Blog posts See [website configuration](./WEBSITE_CONFIG.md) for the Markdown format, images, and publishing instructions. The blog initially displays “No posts yet.” Add your own content to `content/posts/`; existing hosted content is not copied automatically. @@ -89,7 +88,7 @@ Use a deployment that supports the Next.js Node.js runtime when adding Route Han ## Page transitions -Internal site links use `components/TransitionLink` and `next-transition-router` to finish the current page's exit animation before navigating, then reset scroll and animate the new page in. The shared header and footer stay mounted. Browser Back/Forward uses native navigation and scroll restoration without page transitions. Use the transition-aware Link with `scroll={false}` when adding site navigation; external links and Markdown anchors retain normal browser behavior. +Internal site links use `components/common/TransitionLink` and `next-transition-router` to finish the current page's exit animation before navigating, then reset scroll and animate the new page in. The shared header and footer stay mounted. Browser Back/Forward uses native navigation and scroll restoration without page transitions. Use the transition-aware Link with `scroll={false}` when adding site navigation; external links and Markdown anchors retain normal browser behavior. ## Contributing diff --git a/WEBSITE_CONFIG.md b/WEBSITE_CONFIG.md index ca0f61c..f5ca17a 100644 --- a/WEBSITE_CONFIG.md +++ b/WEBSITE_CONFIG.md @@ -10,10 +10,13 @@ Create `content/posts/your-post.md`: --- id: your-post title: Your post title +description: One-sentence summary shown on the blog list and in link previews. authors: - - Your Name + - your-author-id publishDate: '2026-10-08' status: draft +tags: + - open-source coverImage: /images/your-post.jpg --- @@ -23,7 +26,9 @@ Write standard Markdown here, including **bold text**, links, fenced code blocks ``` - `id` determines the URL (`/blog/your-post`), independently of the filename. IDs must be unique across drafts and published posts and contain only letters, numbers, underscores, or hyphens. Numeric IDs are supported for preserving existing URLs. -- `title` is a non-empty string; `authors` is a non-empty array of names. +- `title` is a non-empty string; `authors` is a non-empty array. Each entry is either an author ID from `content/authors/` (shown with an avatar and a link to their profile) or a plain name for contributors without a profile. +- `description` and `tags` are optional. Tags are displayed as badges. +- Reading time is calculated from the body at roughly 200 words per minute; it is not set in frontmatter. - `publishDate` is a quoted, valid `YYYY-MM-DD` date. Published posts sort newest first. This date is display metadata, not a publishing schedule. - `status` must be `draft` or `published`. Only published posts appear in the list or have public detail pages. There is no draft preview. - `coverImage` is optional. Place the example image in `public/images/your-post.jpg`; omit this field to display the existing placeholder. Images must use local public paths beginning with a single `/`. @@ -31,6 +36,26 @@ Write standard Markdown here, including **bold text**, links, fenced code blocks The directory initially contains only `.gitkeep`, so the blog shows “No posts yet.” Invalid metadata and duplicate IDs produce errors identifying the offending post or ID. +## Add an author profile + +Create `content/authors/your-author-id.md`. The filename (without `.md`) is the author ID used in post `authors` lists and in the profile URL (`/authors/your-author-id`): + +```md +--- +name: Your Name +pronouns: they/them +avatar: /authors/your-author-id.png +bio: A short line about yourself. +website: https://example.com +github: https://github.com/your-username +linkedin: https://www.linkedin.com/in/your-username +twitter: https://x.com/your-username +mail: you@example.com +--- +``` + +Only `name` is required. `avatar` must be a local public path (place the image in `public/authors/`); without one, the author's initial is shown. Links must use `https://`. Each post page ends with the profiles of its registered authors, and `/authors` lists everyone. + ## Publish Change `status` to `published`, commit the Markdown and any images, and deploy. App Router Server Components and `generateStaticParams` generate blog pages during the production build; additions, edits, and removals require a rebuild and deployment. During development, the content loader reads files on each page request. Reload the page to see content changes; new published IDs work without restarting the dev server. diff --git a/app/authors/[id]/page.tsx b/app/authors/[id]/page.tsx new file mode 100644 index 0000000..795d31f --- /dev/null +++ b/app/authors/[id]/page.tsx @@ -0,0 +1,63 @@ +import type { Metadata } from 'next'; +import { notFound } from 'next/navigation'; +import AuthorCard from '@/components/authors/AuthorCard'; +import PostList from '@/components/blog/PostList'; +import Breadcrumbs from '@/components/common/Breadcrumbs'; +import Container from '@/components/common/Container'; +import { getAllAuthors, getAuthor } from '@/lib/content/authors'; +import { getPostsByAuthor } from '@/lib/content/posts'; + +// reference: https://pranavu.dev + +export const dynamicParams = false; + +export async function generateStaticParams() { + return (await getAllAuthors()).map((author) => ({ id: author.id })); +} + +type AuthorPageProps = { params: Promise<{ id: string }> }; + +async function loadAuthor(params: AuthorPageProps['params']) { + const { id } = await params; + const author = await getAuthor(id); + if (!author) notFound(); + return author; +} + +export async function generateMetadata({ + params, +}: AuthorPageProps): Promise { + const author = await loadAuthor(params); + return { + title: author.name, + description: author.bio ?? `Posts by ${author.name}.`, + }; +} + +export default async function AuthorPage({ params }: AuthorPageProps) { + const author = await loadAuthor(params); + const posts = await getPostsByAuthor(author.id); + + return ( + + + +

+ Posts by {author.name} +

+ {posts.length === 0 ? ( +

+ No posts available from this author. +

+ ) : ( + + )} +
+ ); +} diff --git a/app/authors/page.tsx b/app/authors/page.tsx new file mode 100644 index 0000000..0a06136 --- /dev/null +++ b/app/authors/page.tsx @@ -0,0 +1,29 @@ +import type { Metadata } from 'next'; +import AuthorCard from '@/components/authors/AuthorCard'; +import Breadcrumbs from '@/components/common/Breadcrumbs'; +import Container from '@/components/common/Container'; +import { getAllAuthors } from '@/lib/content/authors'; + +export const metadata: Metadata = { title: 'Authors' }; + +export default async function AuthorsPage() { + const authors = await getAllAuthors(); + return ( + + + {authors.length === 0 ? ( +

No authors yet.

+ ) : ( +
    + {authors.map((author) => ( +
  • + +
  • + ))} +
+ )} +
+ ); +} diff --git a/app/blog/[uid]/page.tsx b/app/blog/[uid]/page.tsx index 4dccfea..5d1f0f0 100644 --- a/app/blog/[uid]/page.tsx +++ b/app/blog/[uid]/page.tsx @@ -1,10 +1,22 @@ import type { Metadata } from 'next'; import { notFound } from 'next/navigation'; -import Link from '../../../components/TransitionLink'; -import { ArrowLeft } from 'lucide-react'; -import { getPost, getPublishedPosts } from '../../../lib/posts'; -import CustomImage from '../../../components/CustomImage'; -import MarkdownRenderer from '../../../components/MarkdownRenderer'; +import AuthorProfiles from '@/components/authors/AuthorProfiles'; +import CoverImage from '@/components/blog/CoverImage'; +import MarkdownRenderer from '@/components/blog/MarkdownRenderer'; +import PostHeader from '@/components/blog/PostHeader'; +import PostNavigation from '@/components/blog/PostNavigation'; +import { + TableOfContentsDropdown, + TableOfContentsSidebar, +} from '@/components/blog/TableOfContents'; +import Breadcrumbs from '@/components/common/Breadcrumbs'; +import Container from '@/components/common/Container'; +import { resolveAuthors } from '@/lib/content/authors'; +import { + getAdjacentPosts, + getPost, + getPublishedPosts, +} from '@/lib/content/posts'; export const dynamicParams = false; @@ -25,41 +37,66 @@ export async function generateMetadata({ params, }: PostPageProps): Promise { const post = await loadPost(params); - return { title: `${post.title} | Manipal OSF` }; + const authors = await resolveAuthors(post.authors); + const description = post.description ?? undefined; + return { + title: post.title, + description, + authors: authors.map((author) => ({ + name: author.name, + url: author.isRegistered ? `/authors/${author.id}` : undefined, + })), + openGraph: { + type: 'article', + title: post.title, + description, + publishedTime: post.publishDate, + authors: authors.map((author) => author.name), + tags: post.tags, + }, + }; } -const IndividualBlogPage = async ({ params }: PostPageProps) => { - const data = await loadPost(params); +export default async function PostPage({ params }: PostPageProps) { + const post = await loadPost(params); + const [authors, { newer, older }] = await Promise.all([ + resolveAuthors(post.authors), + getAdjacentPosts(post.id), + ]); + return ( - <> -
-

{data.title}

- -
-
-

WRITTEN BY

-

{data.authors.join(', ')}

-
-
-

PUBLISHED ON

- -
-
-
- - - - Return to blog - -
- + // data-wide widens the site's main column so the sidebar fits beside the text. +
+ + + + + + + + +
+ + + + + + + +
+
); -}; - -export default IndividualBlogPage; +} diff --git a/app/blog/page.tsx b/app/blog/page.tsx index 800ea53..85a2f2a 100644 --- a/app/blog/page.tsx +++ b/app/blog/page.tsx @@ -1,27 +1,41 @@ import type { Metadata } from 'next'; -import BlogCard from '../../components/BlogCard'; -import { getPublishedPosts } from '../../lib/posts'; +import PostList from '@/components/blog/PostList'; +import Breadcrumbs from '@/components/common/Breadcrumbs'; +import Container from '@/components/common/Container'; +import Link from '@/components/common/TransitionLink'; +import { getPublishedPosts } from '@/lib/content/posts'; -export const metadata: Metadata = { title: 'Blog | Manipal OSF' }; +export const metadata: Metadata = { title: 'Blog' }; -const BlogPage = async () => { +export default async function BlogPage() { const posts = await getPublishedPosts(); - return ( - <> -
-

Featured

- {posts.length === 0 ? ( -

No posts yet.

- ) : ( -
- {posts.map((item) => ( - - ))} -
- )} -
- + // Posts are sorted newest first, so years come out in descending order. + const postsByYear = Map.groupBy(posts, (post) => + post.publishDate.slice(0, 4) ); -}; -export default BlogPage; + return ( + +
+ + + Authors + +
+ {posts.length === 0 ? ( +

No posts yet.

+ ) : ( + [...postsByYear].map(([year, yearPosts]) => ( +
+

{year}

+ +
+ )) + )} +
+ ); +} diff --git a/app/error.tsx b/app/error.tsx index 88c4bf1..d5074fa 100644 --- a/app/error.tsx +++ b/app/error.tsx @@ -1,6 +1,6 @@ 'use client'; -import ServerError from '../components/ServerError'; +import ServerError from '@/components/common/ServerError'; export default function ErrorPage({ retry }: { retry: () => void }) { return ; diff --git a/app/events/page.tsx b/app/events/page.tsx deleted file mode 100644 index bfcea77..0000000 --- a/app/events/page.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import type { Metadata } from 'next'; -import UnderDev from '../../components/UnderDev'; - -export const metadata: Metadata = { title: 'Under development' }; - -const Events = () => { - return ; -}; - -export default Events; diff --git a/app/global-error.tsx b/app/global-error.tsx index 14212e1..9605d8c 100644 --- a/app/global-error.tsx +++ b/app/global-error.tsx @@ -1,14 +1,14 @@ 'use client'; -import ServerError from '../components/ServerError'; -import { themeScript } from '../lib/theme-script'; -import '../styles/globals.css'; +import ServerError from '@/components/common/ServerError'; +import ThemeScript from '@/components/common/ThemeScript'; +import '@/styles/globals.css'; export default function GlobalError({ retry }: { retry: () => void }) { return ( -