Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
marcklingen authored Oct 14, 2024
2 parents 02ebc24 + 16c9ea5 commit 66b24d9
Show file tree
Hide file tree
Showing 46 changed files with 14,562 additions and 6,667 deletions.
288 changes: 203 additions & 85 deletions components/changelog/ChangelogIndex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,95 +3,213 @@ import Link from "next/link";
import Image from "next/image";
import { type Page } from "nextra";
import { CloudflareVideo, Video } from "../Video";
import { useRouter } from "next/router";
import { useState, useEffect } from "react";
import Head from "next/head";
import {
Pagination,
PaginationContent,
PaginationEllipsis,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationPrevious,
} from "@/components/ui/pagination";

export const ChangelogIndex = ({ maxItems }: { maxItems?: number }) => (
<div className="mt-12 max-w-6xl mx-auto divide-y divide-primary/10">
{(getPagesUnderRoute("/changelog") as Array<Page & { frontMatter: any }>)
.slice(0, maxItems)
.sort(
(a, b) =>
new Date(b.frontMatter.date).getTime() -
new Date(a.frontMatter.date).getTime()
)
.map((page, i) => (
<div
className="md:grid md:grid-cols-4 md:gap-5 py-16 transition-all"
id={page.route.replace("/changelog/", "")}
key={page.route.replace("/changelog/", "")}
>
<div className="hidden md:flex opacity-80 text-lg group-hover:opacity-100 sticky top-24 self-start flex-col items-start gap-2">
{page.frontMatter?.date
? new Date(page.frontMatter.date).toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
timeZone: "UTC",
})
: null}
{page.frontMatter?.badge && (
<div className="hidden md:inline-block px-2 py-1 text-xs font-bold bg-primary/10 text-primary rounded-sm mb-5">
{page.frontMatter.badge}
</div>
export const ChangelogIndex = ({
itemsPerPage = 50,
}: {
itemsPerPage?: number;
}) => {
const router = useRouter();
const [currentPage, setCurrentPage] = useState(1);

useEffect(() => {
const page = Number(router.query.page) || 1;
setCurrentPage(page);
}, [router.query.page]);

const allPages = (
getPagesUnderRoute("/changelog") as Array<Page & { frontMatter: any }>
).sort(
(a, b) =>
new Date(b.frontMatter.date).getTime() -
new Date(a.frontMatter.date).getTime()
);

const totalPages = Math.ceil(allPages.length / itemsPerPage);
const paginatedPages = allPages.slice(
(currentPage - 1) * itemsPerPage,
currentPage * itemsPerPage
);

const renderPagination = () => {
const pageNumbers = [];
if (totalPages <= 5) {
pageNumbers.push(...Array.from({ length: totalPages }, (_, i) => i + 1));
} else {
pageNumbers.push(1);
if (currentPage > 3) pageNumbers.push(null); // Ellipsis
if (currentPage > 2) pageNumbers.push(currentPage - 1);
if (currentPage !== 1 && currentPage !== totalPages)
pageNumbers.push(currentPage);
if (currentPage < totalPages - 1) pageNumbers.push(currentPage + 1);
if (currentPage < totalPages - 2) pageNumbers.push(null); // Ellipsis
pageNumbers.push(totalPages);
}

const pageHref = (page: number) => {
if (page === 0 || page > totalPages) return;
if (page === 1) {
return "/changelog";
}
return `/changelog?page=${page}`;
};

const changePage = (page: number) => {
if (page === currentPage) return;
if (page === 1) {
router.push(pageHref(page));
} else {
router.push(pageHref(page));
}
};

return (
<Pagination className="mt-8">
<Head>
{currentPage > 1 && (
<link rel="prev" href={pageHref(currentPage - 1)} />
)}
{currentPage < totalPages && (
<link rel="next" href={pageHref(currentPage + 1)} />
)}
</Head>
<PaginationContent className="gap-1 items-center">
<PaginationItem>
<PaginationPrevious
size="sm"
href={pageHref(currentPage - 1)}
className="cursor-pointer select-none"
/>
</PaginationItem>
<div className="hidden sm:flex gap-1 items-center">
{pageNumbers.map((pageNumber, index) =>
pageNumber === null ? (
<PaginationItem key={`ellipsis-${index}`}>
<PaginationEllipsis size="sm" />
</PaginationItem>
) : (
<PaginationItem key={pageNumber}>
<PaginationLink
href={pageHref(pageNumber)}
isActive={currentPage === pageNumber}
size="sm"
className="cursor-pointer select-none"
>
{pageNumber}
</PaginationLink>
</PaginationItem>
)
)}
</div>
<div className="md:col-span-3">
<Link key={page.route} href={page.route} className="block group">
{page.frontMatter?.ogCloudflareVideo ? (
<CloudflareVideo
videoId={page.frontMatter?.ogCloudflareVideo}
gifStyle
aspectRatio={16 / 9}
className="mb-14 rounded relative overflow-hidden shadow-md group-hover:shadow-lg ring-0 border-0"
/>
) : page.frontMatter?.ogVideo ? (
<Video
src={page.frontMatter.ogVideo}
gifStyle
className="mb-14 rounded relative overflow-hidden shadow-md group-hover:shadow-lg ring-0 border-0"
/>
) : page.frontMatter?.ogImage ? (
<div className="mb-14 rounded relative aspect-video overflow-hidden shadow-md group-hover:shadow-lg border">
<Image
src={page.frontMatter.gif ?? page.frontMatter.ogImage}
className="object-cover"
alt={page.frontMatter?.title ?? "Blog post image"}
fill={true}
sizes="(min-width: 1024px) 1000px, 100vw"
priority={i < 3}
unoptimized={
page.frontMatter.gif !== undefined ||
page.frontMatter.ogImage?.endsWith(".gif")
}
/>
<PaginationItem>
<PaginationNext
size="sm"
href={pageHref(currentPage + 1)}
className="cursor-pointer select-none"
/>
</PaginationItem>
</PaginationContent>
</Pagination>
);
};

return (
<>
<div className="mt-12 max-w-6xl mx-auto divide-y divide-primary/10 border-b border-primary/10">
{paginatedPages.map((page, i) => (
<div
className="md:grid md:grid-cols-4 md:gap-5 py-16 transition-all"
id={page.route.replace("/changelog/", "")}
key={page.route.replace("/changelog/", "")}
>
<div className="hidden md:flex opacity-80 text-lg group-hover:opacity-100 sticky top-24 self-start flex-col items-start gap-2">
{page.frontMatter?.date
? new Date(page.frontMatter.date).toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
timeZone: "UTC",
})
: null}
{page.frontMatter?.badge && (
<div className="hidden md:inline-block px-2 py-1 text-xs font-bold bg-primary/10 text-primary rounded-sm mb-5">
{page.frontMatter.badge}
</div>
) : null}
<div className="md:hidden opacity-80 text-sm mb-4 group-hover:opacity-100">
{page.frontMatter?.date
? new Date(page.frontMatter.date).toLocaleDateString(
"en-US",
{
year: "numeric",
month: "long",
day: "numeric",
timeZone: "UTC",
)}
</div>
<div className="md:col-span-3">
<Link key={page.route} href={page.route} className="block group">
{page.frontMatter?.ogCloudflareVideo ? (
<CloudflareVideo
videoId={page.frontMatter?.ogCloudflareVideo}
gifStyle
aspectRatio={16 / 9}
className="mb-14 rounded relative overflow-hidden shadow-md group-hover:shadow-lg ring-0 border-0"
/>
) : page.frontMatter?.ogVideo ? (
<Video
src={page.frontMatter.ogVideo}
gifStyle
className="mb-14 rounded relative overflow-hidden shadow-md group-hover:shadow-lg ring-0 border-0"
/>
) : page.frontMatter?.ogImage ? (
<div className="mb-14 rounded relative aspect-video overflow-hidden shadow-md group-hover:shadow-lg border">
<Image
src={page.frontMatter.gif ?? page.frontMatter.ogImage}
className="object-cover"
alt={page.frontMatter?.title ?? "Blog post image"}
fill={true}
sizes="(min-width: 1024px) 1000px, 100vw"
priority={i < 3}
unoptimized={
page.frontMatter.gif !== undefined ||
page.frontMatter.ogImage?.endsWith(".gif")
}
)
: null}
{page.frontMatter?.badge && (
<div className="inline-block px-2 py-1 text-xs font-bold bg-primary/10 text-primary rounded-sm ml-3">
{page.frontMatter.badge}
/>
</div>
)}
</div>
<h2 className="block font-mono text-2xl md:text-3xl opacity-90 group-hover:opacity-100">
{page.meta?.title || page.frontMatter?.title || page.name}
</h2>
<div className="opacity-80 mt-4 text-lg group-hover:opacity-100">
{page.frontMatter?.description}
</div>
</Link>
) : null}
<div className="md:hidden opacity-80 text-sm mb-4 group-hover:opacity-100">
{page.frontMatter?.date
? new Date(page.frontMatter.date).toLocaleDateString(
"en-US",
{
year: "numeric",
month: "long",
day: "numeric",
timeZone: "UTC",
}
)
: null}
{page.frontMatter?.badge && (
<div className="inline-block px-2 py-1 text-xs font-bold bg-primary/10 text-primary rounded-sm ml-3">
{page.frontMatter.badge}
</div>
)}
</div>
<h2 className="block font-mono text-2xl md:text-3xl opacity-90 group-hover:opacity-100">
{page.meta?.title || page.frontMatter?.title || page.name}
</h2>
<div className="opacity-80 mt-4 text-lg group-hover:opacity-100">
{page.frontMatter?.description}
</div>
</Link>
</div>
</div>
</div>
))}
</div>
);
))}
</div>
{renderPagination()}
</>
);
};
22 changes: 20 additions & 2 deletions components/supportChat/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,30 @@

import { useEffect } from "react";
import { Crisp } from "crisp-sdk-web";
import { usePostHog } from "posthog-js/react";

const CrispChat = () => {
const posthog = usePostHog();

useEffect(() => {
if (process.env.NEXT_PUBLIC_CRISP_WEBSITE_ID)
if (process.env.NEXT_PUBLIC_CRISP_WEBSITE_ID) {
Crisp.configure(process.env.NEXT_PUBLIC_CRISP_WEBSITE_ID);
});
Crisp.chat.onChatInitiated(() => {
posthog.capture("support_chat:initiated");
});
Crisp.chat.onChatOpened(() => {
posthog.capture("support_chat:opened");
});
Crisp.message.onMessageSent(() => {
posthog.capture("support_chat:message_sent");
});
return () => {
Crisp.chat.offChatInitiated();
Crisp.chat.offChatOpened();
Crisp.message.offMessageSent();
};
}
}, [posthog]);

return null;
};
Expand Down
4 changes: 2 additions & 2 deletions components/ui/accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ const AccordionContent = React.forwardRef<
<AccordionPrimitive.Content
ref={ref}
className={cn(
"overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",
"overflow-hidden transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down bg-card border rounded-t border-b-0 text-sm",
className
)}
{...props}
>
<div className="pb-4 pt-0">{children}</div>
<div className="p-4">{children}</div>
</AccordionPrimitive.Content>
));
AccordionContent.displayName = AccordionPrimitive.Content.displayName;
Expand Down
8 changes: 8 additions & 0 deletions cookbook/_routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,13 @@
{
"notebook": "integration_llama_index_posthog_mistral.ipynb",
"docsPath": null
},
{
"notebook": "example_intent_classification_pipeline.ipynb",
"docsPath": "docs/analytics/example-intent-classification"
},
{
"notebook": "integration_amazon_bedrock.ipynb",
"docsPath": "docs/integrations/amazon-bedrock"
}
]
Loading

0 comments on commit 66b24d9

Please sign in to comment.