Repository navigation
Add prev/next nav to blog posts, reduce index gap #859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,43 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "use client"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import Link from "next/link"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { usePathname } from "next/navigation"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { blogPosts } from "./blog-posts"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export function BlogPager() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const pathname = usePathname(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const index = blogPosts.findIndex( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (post) => `/blog/${post.slug}` === pathname | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const prev = index > 0 ? blogPosts[index - 1] : null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const next = index < blogPosts.length - 1 ? blogPosts[index + 1] : null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Guard against Prompt for AI agents
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!prev && !next) return null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+9
to
+15
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pager shows incorrectly on index page when
Suggested change
Comment on lines
+9
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard unmatched paths before deriving neighbors. When 💡 Suggested fix export function BlogPager() {
const pathname = usePathname();
const index = blogPosts.findIndex(
(post) => `/blog/${post.slug}` === pathname
);
+ if (index === -1) return null;
+
const prev = index > 0 ? blogPosts[index - 1] : null;
const next = index < blogPosts.length - 1 ? blogPosts[index + 1] : null;
if (!prev && !next) return null;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <nav className="flex items-center justify-between mt-12 pt-6 border-t border-border text-[14px]"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {prev ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Link | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| href={`/blog/${prev.slug}`} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| className="flex items-center gap-1.5 text-muted hover:text-foreground transition-colors" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <span aria-hidden>←</span> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {prev.title} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </Link> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) : ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <span /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {next ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Link | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| href={`/blog/${next.slug}`} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| className="flex items-center gap-1.5 text-muted hover:text-foreground transition-colors" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {next.title} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <span aria-hidden>→</span> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </Link> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) : ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <span /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </nav> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| export const blogPosts = [ | ||
| { | ||
| slug: "cmd-shift-u", | ||
| title: "Cmd+Shift+U", | ||
| date: "2026-03-04", | ||
| summary: | ||
| "How Cmd+Shift+U navigates between finished agents across workspaces in cmux.", | ||
| }, | ||
| { | ||
| slug: "zen-of-cmux", | ||
| title: "The Zen of cmux", | ||
| date: "2026-02-27", | ||
| summary: | ||
| "cmux is a primitive, not a solution. It gives you composable pieces and your workflow is up to you.", | ||
| }, | ||
| { | ||
| slug: "show-hn-launch", | ||
| title: "Launching cmux on Show HN", | ||
| date: "2026-02-21", | ||
| summary: | ||
| "cmux hit #2 on Hacker News, got shared by Mitchell Hashimoto, and went viral in Japan.", | ||
| }, | ||
| { | ||
| slug: "introducing-cmux", | ||
| title: "Introducing cmux", | ||
| date: "2026-02-12", | ||
| summary: | ||
| "A native macOS terminal built on Ghostty, designed for running multiple AI coding agents side by side.", | ||
| }, | ||
| ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
findIndexreturns-1for routes that are not a specific post (for example/blog), but the currentnextexpression treats-1 < blogPosts.length - 1as true and setsnexttoblogPosts[0]. This causes the pager to render on non-post pages and can show an incorrect link whenever the pathname format does not exactly match (e.g., trailing-slash variants). Add an earlyindex === -1guard before computingprev/nextso unmatched routes returnnull.Useful? React with 👍 / 👎.