Skip to content

refactor: code quality and feature improvements - dedupe fetch, safe pagination, sitemap, SEO, homepage optimization#2

Open
ghost wants to merge 1 commit into
deployfrom
feature/code-quality-improvements
Open

refactor: code quality and feature improvements - dedupe fetch, safe pagination, sitemap, SEO, homepage optimization#2
ghost wants to merge 1 commit into
deployfrom
feature/code-quality-improvements

Conversation

@ghost

@ghost ghost commented Mar 29, 2026

Copy link
Copy Markdown

Changes

Code Quality

A1 - Deduplicate article fetching logic

  • Replaced inline getArticle() in articles/[slug]/page.tsx with the shared getArticleBySlug() from lib/api.ts
  • Eliminates duplicate implementation with different error handling

A2 - Safe pagination metadata handling

  • Replaced all res.pagination! non-null assertions with runtime guards
  • Now throws explicit errors when pagination metadata is missing instead of silently producing undefined

A3 - Extract hardcoded category slugs

  • Created src/lib/constants.ts with HOMEPAGE_LEFT_COLUMN_SLUGS, HOMEPAGE_RIGHT_COLUMN_SLUGS, and HOMEPAGE_ARTICLES_PER_CATEGORY
  • Homepage now imports from constants instead of hardcoding slugs inline

Features

B1 - generateStaticParams for article SEO

  • Added generateStaticParams() to articles/[slug]/page.tsx
  • Pre-renders up to 100 article pages at build time for improved SEO and initial load performance

B5 - Sitemap

  • Added src/app/sitemap.ts route handler
  • Dynamically generates sitemap.xml from all published articles and categories
  • Includes proper lastModified, changeFrequency, and priority values

B8 - Homepage over-fetching fix

  • Changed from fetching ALL articles (limit: 100) then filtering client-side to fetching per-category with limit: 4
  • Reduced initial homepage fetch to limit: 10 (only needed for featured/trending)
  • Removed unused groupArticlesByCategory function

…pagination, sitemap, generateStaticParams, constants extraction, homepage optimization
@ghost

ghost commented Mar 29, 2026

Copy link
Copy Markdown
Author

Rooviewer Clock   See task

Reviewed the changes across all 5 files. Found 2 issues worth addressing:

  • Error handling regression in article page -- getArticleBySlug swallows all API errors (including 500s) as null, so server errors now render as "not found" instead of hitting the error boundary (comment)
  • Possible loss of subcategory articles on homepage -- the removed groupArticlesByCategory recursed into child categories; the replacement getArticlesByCategory API call may not, depending on backend behavior (comment)

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {
const { slug } = await params;
const article = await getArticle(slug);
const article = await getArticleBySlug(slug, { next: { revalidate: 3600 } });

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old inline getArticle() returned null only on HTTP 404 and threw on other status codes (500, 502, etc.), letting the error propagate to Next.js error boundaries. getArticleBySlug catches all errors and returns null, so a server outage or 500 now silently renders a "not found" page instead of showing the error UI. If distinguishing "not found" from "server error" matters here, getArticleBySlug would need to re-throw non-404 errors or accept an option to do so.

Fix it with Roo Code or mention @roomote and request a fix.

Comment thread src/app/page.tsx
Comment on lines +57 to +63
const sectionResults = await Promise.all(
allSlugs.map(async (slug) => {
const category = categories.find((cat) => cat.slug === slug);
if (!category) return { slug, name: slug, articles: [] as Article[] };
const articles = await getArticlesByCategory(slug, { limit: HOMEPAGE_ARTICLES_PER_CATEGORY }).catch(() => [] as Article[]);
return { slug, name: category.name, articles };
})

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removed groupArticlesByCategory explicitly walked child categories recursively (via collectIds) and matched articles belonging to any descendant. The replacement getArticlesByCategory(slug, { limit: 4 }) hits /categories/${slug}/articles -- if that API endpoint only returns articles directly assigned to the parent category (not its children), articles nested under subcategories will silently disappear from the homepage. Worth verifying the API behavior here; if it doesn't recurse, the homepage sections will show fewer articles than before.

Fix it with Roo Code or mention @roomote and request a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant