Openstatus www.openstatus.dev

feat: pagination to next changelog (#701)

authored by

Maximilian Kaske and committed by
GitHub
4d888799 65d73220

+75 -10
+43
apps/web/src/app/(content)/_components/pagination.tsx
··· 1 + import Link from "next/link"; 2 + import type { Changelog } from "contentlayer/generated"; 3 + import { ChevronLeft, ChevronRight } from "lucide-react"; 4 + 5 + import { Button } from "@openstatus/ui"; 6 + 7 + export function Pagination({ 8 + prev, 9 + next, 10 + }: { 11 + prev?: Changelog; 12 + next?: Changelog; 13 + }) { 14 + return ( 15 + <div className="mx-auto flex w-full max-w-prose items-center justify-between"> 16 + <div /> 17 + {/* {prev ? ( 18 + <div className="w-1/2 flex-1 text-left"> 19 + <Button asChild variant="link"> 20 + <Link href={`/changelog/${prev.slug}`}> 21 + <ChevronLeft className="mr-2 h-4 w-4" /> 22 + <span className="truncate">{prev.title}</span> 23 + </Link> 24 + </Button> 25 + </div> 26 + ) : ( 27 + <div /> 28 + )} */} 29 + {next ? ( 30 + <div className="w-1/2 flex-1 text-right"> 31 + <Button asChild variant="link"> 32 + <Link href={`/changelog/${next.slug}`}> 33 + <span className="truncate">{next.title}</span> 34 + <ChevronRight className="ml-2 h-4 w-4" /> 35 + </Link> 36 + </Button> 37 + </div> 38 + ) : ( 39 + <div /> 40 + )} 41 + </div> 42 + ); 43 + }
+22 -1
apps/web/src/app/(content)/changelog/[slug]/page.tsx
··· 2 2 import { notFound } from "next/navigation"; 3 3 import { allChangelogs } from "contentlayer/generated"; 4 4 5 + import { Separator } from "@openstatus/ui"; 6 + 5 7 import { 6 8 defaultMetadata, 7 9 ogMetadata, ··· 10 12 import { Changelog } from "@/components/content/changelog"; 11 13 import { Shell } from "@/components/dashboard/shell"; 12 14 import { BackButton } from "@/components/layout/back-button"; 15 + import { Pagination } from "../../_components/pagination"; 13 16 14 17 // export const dynamic = "force-static"; 15 18 ··· 59 62 }; 60 63 } 61 64 65 + function getChangelogPagination(slug: string) { 66 + const changelogs = allChangelogs.sort( 67 + (a, b) => 68 + new Date(b.publishedAt).getTime() - new Date(a.publishedAt).getTime(), 69 + ); 70 + const findIndex = changelogs.findIndex( 71 + (changelog) => changelog.slug === slug, 72 + ); 73 + return { 74 + prev: changelogs?.[findIndex - 1], 75 + next: changelogs?.[findIndex + 1], 76 + }; 77 + } 78 + 62 79 export default function ChangelogPage({ 63 80 params, 64 81 }: { ··· 70 87 notFound(); 71 88 } 72 89 90 + const { next, prev } = getChangelogPagination(params.slug); 91 + 73 92 return ( 74 93 <> 75 94 <BackButton href="/changelog" /> 76 - <Shell className="sm:py-8 md:py-12"> 95 + <Shell className="flex flex-col gap-8 sm:py-8 md:gap-12 md:py-12"> 77 96 <Changelog post={post} /> 97 + <Separator className="mx-auto max-w-prose" /> 98 + <Pagination {...{ next, prev }} /> 78 99 </Shell> 79 100 </> 80 101 );
+9 -8
apps/web/src/app/(content)/changelog/page.tsx
··· 22 22 title: "Changelog | OpenStatus", 23 23 }, 24 24 }; 25 + 25 26 export default async function Changelog() { 26 - const posts = allChangelogs.sort( 27 + const changelogs = allChangelogs.sort( 27 28 (a, b) => 28 29 new Date(b.publishedAt).getTime() - new Date(a.publishedAt).getTime(), 29 30 ); ··· 34 35 title="Changelog" 35 36 description="All the latest features, fixes and work to OpenStatus." 36 37 > 37 - {posts.map((post) => ( 38 + {changelogs.map((changelog) => ( 38 39 <Timeline.Article 39 - key={post.slug} 40 - publishedAt={post.publishedAt} 41 - imageSrc={post.image} 42 - title={post.title} 43 - href={`./changelog/${post.slug}`} 40 + key={changelog.slug} 41 + publishedAt={changelog.publishedAt} 42 + imageSrc={changelog.image} 43 + title={changelog.title} 44 + href={`./changelog/${changelog.slug}`} 44 45 > 45 - <Mdx code={post.body.code} /> 46 + <Mdx code={changelog.body.code} /> 46 47 </Timeline.Article> 47 48 ))} 48 49 </Timeline>
+1 -1
apps/web/src/content/changelog/terraform-provider.mdx
··· 10 10 enabling you to define and manage your OpenStatus resources as code. 11 11 12 12 Here's the link to the: 13 - https://registry.terraform.io/providers/openstatus/openstatus/latest/docs 13 + [OpenStats Terraform Provider](https://registry.terraform.io/providers/openstatus/openstatus/latest/docs)