Skip to content

blog: list posts on the home page#39

Merged
gapry merged 1 commit intomainfrom
react-homepage
Mar 5, 2026
Merged

blog: list posts on the home page#39
gapry merged 1 commit intomainfrom
react-homepage

Conversation

@gapry
Copy link
Owner

@gapry gapry commented Mar 5, 2026

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a dynamic blog post listing feature to the homepage. It achieves this by enhancing the build process to generate a posts.json file containing metadata for all blog posts, which is then consumed by the frontend application. The App component has been refactored to fetch this data and render a new Home component for the main page, providing a paginated view of posts, while also correctly routing to individual post pages.

Highlights

  • Dynamic Post Listing: The build process was enhanced to generate a posts.json file containing metadata for all blog posts, enabling dynamic listing on the homepage.
  • Homepage Redesign: The homepage now displays a paginated list of blog posts using a new Home component, improving navigation and discoverability.
  • Refactored Routing: The App.jsx component's routing logic was updated to fetch and utilize the posts.json data for both the home page and individual post views, replacing the previous static glob import approach.
  • Post Naming Convention: An existing blog post was renamed, and several new test posts were added, all conforming to a new YYYY-MM-DD-slug.md naming convention.
Changelog
  • .gitignore
    • Added public/posts.json to the ignore list.
  • build.js
    • Initialized allPosts array to store post metadata.
    • Parsed markdown filenames to extract date, slug, and title for each post.
    • Sorted collected posts by date in descending order.
    • Wrote the allPosts data to public/posts.json.
    • Updated the post-copying logic to iterate over the allPosts array.
    • Changed the build success message to reflect the number of posts built.
  • public/posts/2025/2025-12-13-Test7.md
    • Added a new test markdown file.
  • public/posts/2026/2026-01-29-Test3.md
    • Added a new test markdown file.
  • public/posts/2026/2026-01-31-Test123.md
    • Added a new test markdown file.
  • public/posts/2026/2026-02-03-Test5.md
    • Added a new test markdown file.
  • public/posts/2026/2026-03-05-Test.md
    • Renamed a markdown file to include a date prefix.
  • src/App.jsx
    • Imported the new Home component.
    • Removed the direct glob import for markdown files.
    • Implemented useEffect to fetch posts.json on component mount.
    • Updated routing logic to display Home component for the root path or individual posts based on posts.json data.
    • Added a 'Back to Home' link for individual post views.
  • src/Home.jsx
    • Added a new React component to display a paginated list of blog posts.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@amazon-q-developer amazon-q-developer bot left a comment

Choose a reason for hiding this comment

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

Summary

This PR successfully refactors the blog to display posts on the home page with pagination support. The implementation introduces a metadata-driven approach using posts.json and adds a new Home component.

Critical Issues Requiring Fix

I've identified 4 critical issues that must be addressed before merge:

  1. build.js: Missing directory existence check that will cause build script to crash
  2. src/App.jsx: Incorrect error handling that misrepresents network failures as 404 errors
  3. src/App.jsx: Missing UI handling for error status state
  4. src/Home.jsx: Missing default prop value that will cause runtime crash if posts is undefined

These issues will cause crashes or incorrect behavior in production. Please review the inline comments for specific fixes.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

Comment on lines +5 to +11
export default function Home({ posts }) {
const [currentPage, setCurrentPage] = useState(0);

const startIndex = currentPage * POSTS_PER_PAGE;
const currentPosts = posts.slice(startIndex, startIndex + POSTS_PER_PAGE);
const hasNext = startIndex + POSTS_PER_PAGE < posts.length;
const hasPrev = currentPage > 0;

Choose a reason for hiding this comment

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

🛑 Crash Risk: Add validation for posts prop to prevent runtime crash when posts is undefined or null.

Suggested change
export default function Home({ posts }) {
const [currentPage, setCurrentPage] = useState(0);
const startIndex = currentPage * POSTS_PER_PAGE;
const currentPosts = posts.slice(startIndex, startIndex + POSTS_PER_PAGE);
const hasNext = startIndex + POSTS_PER_PAGE < posts.length;
const hasPrev = currentPage > 0;
export default function Home({ posts = [] }) {
const [currentPage, setCurrentPage] = useState(0);
const startIndex = currentPage * POSTS_PER_PAGE;
const currentPosts = posts.slice(startIndex, startIndex + POSTS_PER_PAGE);
const hasNext = startIndex + POSTS_PER_PAGE < posts.length;
const hasPrev = currentPage > 0;

Comment on lines +62 to +66
{status === '404' ? (
<NotFound />
) : status === 'home' ? (
<Home posts={posts} />
) : (

Choose a reason for hiding this comment

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

Add handling for the 'error' status state in the conditional rendering logic to properly display error messages instead of showing NotFound for network/server errors.

Suggested change
{status === '404' ? (
<NotFound />
) : status === 'home' ? (
<Home posts={posts} />
) : (
{status === '404' ? (
<NotFound />
) : status === 'error' ? (
<div>Error loading content. Please try again later.</div>
) : status === 'home' ? (
<Home posts={posts} />

setStatus('404');
}
})
.catch(() => setStatus('404'));

Choose a reason for hiding this comment

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

🛑 Logic Error: The fetch error handler sets status to '404', but this creates confusing user experience when the actual issue is network failure or server error, not a missing page. This misrepresents the error condition.

Suggested change
.catch(() => setStatus('404'));
.catch(() => setStatus('error'));

const distDir = './dist';

const allPosts = [];
const years = fs.readdirSync(postsDir);

Choose a reason for hiding this comment

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

🛑 Crash Risk: Add existence check before reading directory to prevent runtime crash when postsDir doesn't exist.

Suggested change
const years = fs.readdirSync(postsDir);
if (!fs.existsSync(postsDir)) {
console.error(`Error: Posts directory "${postsDir}" does not exist`);
process.exit(1);
}
const years = fs.readdirSync(postsDir);

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces functionality to list blog posts on the home page. It adds a build step to generate a posts.json file from markdown files and updates the React application to use this file for displaying a list of posts and individual post pages. My review focuses on improving the robustness of the build script and enhancing the user experience by enabling client-side navigation to prevent full page reloads, which is more in line with a Single-Page Application (SPA) architecture.

Comment on lines +16 to +18
const parts = fileName.split('-');
const date = parts.slice(0, 3).join('-');
const slug = parts.slice(3).join('-');

Choose a reason for hiding this comment

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

high

The current method of parsing the date and slug from the filename by splitting on '-' is brittle. It assumes a fixed structure that can easily break if a filename doesn't strictly adhere to the YYYY-MM-DD-slug format. For instance, a file named my-new-post.md without a date prefix would lead to incorrect date and slug values. Using a regular expression to explicitly match and extract these parts would be far more robust and would also handle filenames that don't match the pattern gracefully.

Suggested change
const parts = fileName.split('-');
const date = parts.slice(0, 3).join('-');
const slug = parts.slice(3).join('-');
const match = fileName.match(/^(\d{4}-\d{2}-\d{2})-(.*)$/);
if (!match) return;
const [, date, slug] = match;

<article>
<ReactMarkdown>{content}</ReactMarkdown>
<hr />
<a href="/" style={{ display: 'block', marginTop: '20px' }}>← Back to Home</a>

Choose a reason for hiding this comment

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

medium

Using a standard <a> tag with href for navigation within a React application causes a full page reload, which negates the benefits of a single-page application (SPA). This leads to a slower, less fluid user experience. To fix this, you should handle navigation on the client side by preventing the default link behavior and updating the component's state to render the home view.

Suggested change
<a href="/" style={{ display: 'block', marginTop: '20px' }}>← Back to Home</a>
<a href="/" onClick={(e) => { e.preventDefault(); setStatus('home'); }} style={{ display: 'block', marginTop: '20px' }}>← Back to Home</a>

Comment on lines +20 to +22
<a href={`/${post.year}/${post.slug}.html`} className="post-link">
{post.title}
</a>

Choose a reason for hiding this comment

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

medium

These post links use standard <a> tags, which cause a full page reload every time a user clicks on a post. In a Single-Page Application, this is inefficient and provides a poor user experience. You should handle this navigation on the client side.

To implement this, you could pass a navigation handler function from the App component down to the Home component. The <a> tag's onClick handler would then prevent the default behavior and call this function, allowing the App component to fetch the post data and update the view without a page refresh.

@gapry gapry merged commit 38e7fef into main Mar 5, 2026
2 checks passed
@gapry gapry deleted the react-homepage branch March 5, 2026 04:17
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