Skip to content
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

chore: replace contentlayer with content-collections #1075

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
**/.contentlayer
**/.content-collections
4 changes: 2 additions & 2 deletions apps/web/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ yarn-error.log*
# vercel
.vercel

# contentlayer
.contentlayer
# content-collections
.content-collections

# Sentry Auth Token
.sentryclirc
165 changes: 165 additions & 0 deletions apps/web/content-collections.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
import { defineCollection, defineConfig } from "@content-collections/core";
import { compileMDX } from "@content-collections/mdx";
import readingTime from "reading-time";
import rehypeAutolinkHeadings from "rehype-autolink-headings";
import rehypePrettyCode from "rehype-pretty-code";
import rehypeSlug from "rehype-slug";

const autolinkHeadings = [
rehypeAutolinkHeadings,
{
behavior: "append",
headingProperties: {
className: "group",
},
properties: {
className: [
"no-underline group-hover:after:content-['#'] after:text-muted-foreground/30 after:hover:text-muted-foreground ml-1 after:p-1",
],
"aria-hidden": "true",
},
},
];

const prettyCode = [
rehypePrettyCode,
{
theme: {
dark: "github-dark-dimmed",
light: "github-light",
},
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
onVisitLine(node: any) {
// Prevent lines from collapsing in `display: grid` mode, and
// allow empty lines to be copy/pasted
if (node.children.length === 0) {
node.children = [{ type: "text", value: " " }];
}
},
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
onVisitHighlightedLine(node: any) {
node.properties.className.push("highlighted");
},
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
onVisitHighlightedWord(node: any) {
node.properties.className = ["word"];
},
},
];

const posts = defineCollection({
name: "Posts",
directory: "src/content/posts",
include: "**/*.mdx",
schema: (z) => ({
title: z.string(),
description: z.string(),
image: z.string(),
publishedAt: z.coerce.date(),
author: z.object({
name: z.string(),
url: z.string().optional(),
avatar: z.string().optional(),
}),
}),
transform: async (document, context) => {
const mdx = await compileMDX(context, document, {
// @ts-expect-error
rehypePlugins: [rehypeSlug, prettyCode, autolinkHeadings],
});
return {
...document,
mdx,
slug: document._meta.fileName.replace(/\.mdx$/, ""),
readingTime: readingTime(document.content).text,
};
},
});

const legals = defineCollection({
name: "Legals",
directory: "src/content/legal",
include: "**/*.mdx",
schema: (z) => ({
title: z.string(),
updatedAt: z.string(),
}),
transform: async (document, context) => {
const mdx = await compileMDX(context, document, {
// @ts-expect-error
rehypePlugins: [rehypeSlug, prettyCode, autolinkHeadings],
});
return {
...document,
mdx,
slug: document._meta.fileName.replace(/\.mdx$/, ""),
};
},
});

const faqs = defineCollection({
name: "FAQs",
directory: "src/content/faq",
include: "**/*.mdx",
schema: (z) => ({
title: z.string(),
order: z.number(),
}),
transform: async (document, context) => {
const mdx = await compileMDX(context, document, {
// @ts-expect-error
rehypePlugins: [rehypeSlug, prettyCode, autolinkHeadings],
});
return {
...document,
mdx,
slug: document._meta.fileName.replace(/\.mdx$/, ""),
};
},
});

const changelogs = defineCollection({
name: "Changelogs",
directory: "src/content/changelog",
include: "**/*.mdx",
schema: (z) => ({
title: z.string(),
description: z.string(),
image: z.string(),
publishedAt: z.coerce.date(),
}),
transform: async (document, context) => {
const mdx = await compileMDX(context, document, {
// @ts-expect-error
rehypePlugins: [rehypeSlug, prettyCode, autolinkHeadings],
});
return {
...document,
mdx,
slug: document._meta.fileName.replace(/\.mdx$/, ""),
readingTime: readingTime(document.content).text,
};
},
});

const unrelateds = defineCollection({
name: "Unrelateds",
directory: "src/content/unrelated",
include: "**/*.mdx",
schema: () => ({}),
transform: async (document, context) => {
const mdx = await compileMDX(context, document, {
// @ts-expect-error
rehypePlugins: [rehypeSlug, prettyCode, autolinkHeadings],
});
return {
...document,
mdx,
slug: document._meta.fileName.replace(/\.mdx$/, ""),
};
},
});

export default defineConfig({
collections: [posts, legals, faqs, changelogs, unrelateds],
});
20 changes: 0 additions & 20 deletions apps/web/contentlayer.config.ts

This file was deleted.

4 changes: 2 additions & 2 deletions apps/web/next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { withContentlayer } = require("next-contentlayer");
const { withContentCollections } = require("@content-collections/next");

/** @type {import('next').NextConfig} */
const nextConfig = {
Expand Down Expand Up @@ -59,7 +59,7 @@ const nextConfig = {
const { withSentryConfig } = require("@sentry/nextjs");

module.exports = withSentryConfig(
withContentlayer(nextConfig),
withContentCollections(nextConfig),
{
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options
Expand Down
5 changes: 3 additions & 2 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,12 @@
"clsx": "2.0.0",
"cmdk": "1.0.0",
"cobe": "0.6.3",
"contentlayer": "0.3.4",
"date-fns": "2.30.0",
"date-fns-tz": "2.0.0",
"lucide-react": "0.279.0",
"nanoid": "5.0.7",
"next": "14.2.15",
"next-auth": "5.0.0-beta.21",
"next-contentlayer": "0.3.4",
"next-plausible": "3.12.0",
"next-themes": "0.2.1",
"nuqs": "1.19.1",
Expand Down Expand Up @@ -92,6 +90,9 @@
"zod": "3.23.8"
},
"devDependencies": {
"@content-collections/core": "^0.7.2",
"@content-collections/mdx": "^0.2.0",
"@content-collections/next": "^0.2.3",
"@headlessui/tailwindcss": "0.2.0",
"@openstatus/tsconfig": "workspace:*",
"@types/node": "20.14.8",
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/(content)/_components/pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Changelog } from "contentlayer/generated";
import type { Changelog } from "content-collections";
import { ChevronLeft, ChevronRight } from "lucide-react";
import Link from "next/link";

Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/app/(content)/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { allPosts } from "contentlayer/generated";
import { allPosts } from "content-collections";
import type { Metadata } from "next";
import { notFound } from "next/navigation";

Expand Down Expand Up @@ -28,7 +28,7 @@ export async function generateMetadata({
if (!post) {
return;
}
const { title, publishedAt: publishedTime, description, slug, image } = post;
const { title, publishedAt, description, slug, image } = post;

return {
...defaultMetadata,
Expand All @@ -39,7 +39,7 @@ export async function generateMetadata({
title,
description,
type: "article",
publishedTime,
publishedTime: publishedAt.toISOString(),
url: `https://www.openstatus.dev/blog/${slug}`,
images: [
{
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/(content)/blog/feed.xml/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { allPosts } from "contentlayer/generated";
import { allPosts } from "content-collections";
import RSS from "rss";

export async function GET() {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/(content)/blog/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
PaginationContent,
PaginationLink,
} from "@openstatus/ui";
import { allPosts } from "contentlayer/generated";
import { allPosts } from "content-collections";
import { Rss } from "lucide-react";
import type { Metadata } from "next";
import Link from "next/link";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/(content)/blog/search-params.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { allPosts } from "contentlayer/generated";
import { allPosts } from "content-collections";
import {
createParser,
createSearchParamsCache,
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/app/(content)/changelog/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { allChangelogs } from "contentlayer/generated";
import { allChangelogs } from "content-collections";
import type { Metadata } from "next";
import { notFound } from "next/navigation";

Expand Down Expand Up @@ -32,7 +32,7 @@ export async function generateMetadata({
return;
}

const { title, publishedAt: publishedTime, description, slug, image } = post;
const { title, publishedAt, description, slug, image } = post;

return {
...defaultMetadata,
Expand All @@ -43,7 +43,7 @@ export async function generateMetadata({
title,
description,
type: "article",
publishedTime,
publishedTime: publishedAt.toISOString(),
url: `https://www.openstatus.dev/changelog/${slug}`,
images: [
{
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/(content)/changelog/feed.xml/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { allChangelogs } from "contentlayer/generated";
import { allChangelogs } from "content-collections";
import RSS from "rss";

export async function GET() {
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/app/(content)/changelog/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
PaginationContent,
PaginationLink,
} from "@openstatus/ui";
import { allChangelogs } from "contentlayer/generated";
import { allChangelogs } from "content-collections";
import { Rss } from "lucide-react";
import type { Metadata } from "next";
import {
Expand Down Expand Up @@ -70,7 +70,7 @@ export default function ChangelogClient({
title={changelog.title}
href={`./changelog/${changelog.slug}`}
>
<Mdx code={changelog.body.code} />
<Mdx code={changelog.mdx} />
</Timeline.Article>
))}
<div className="grid grid-cols-1 gap-4 md:grid-cols-5 md:gap-6">
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/(content)/changelog/search-params.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { allChangelogs } from "contentlayer/generated";
import { allChangelogs } from "content-collections";
import {
createParser,
createSearchParamsCache,
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/app/(content)/features/monitoring/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { flyRegions } from "@openstatus/db/src/schema/constants";
import type { Region } from "@openstatus/tinybird";
import { Button } from "@openstatus/ui/src/components/button";
import { Skeleton } from "@openstatus/ui/src/components/skeleton";
import { allUnrelateds } from "contentlayer/generated";
import { allUnrelateds } from "content-collections";
import type { Metadata } from "next";
import Link from "next/link";
import { Suspense } from "react";
Expand Down Expand Up @@ -129,7 +129,7 @@ export default function FeaturePage() {
component={
code ? (
<Mdx
code={code.body.code}
code={code.mdx}
className="max-w-none prose-pre:overflow-hidden"
/>
) : (
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/app/about/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { allUnrelateds } from "contentlayer/generated";
import { allUnrelateds } from "content-collections";

import { Separator } from "@openstatus/ui/src/components/separator";

Expand Down Expand Up @@ -37,7 +37,7 @@ export default function AboutPage() {
<Shell className="mx-auto w-auto shadow sm:px-8 sm:py-8 md:px-12 md:py-12 dark:border-card-foreground/30">
{story ? (
<Mdx
code={story.body.code}
code={story.mdx}
className="sm:prose-lg mx-auto prose-li:my-0"
/>
) : null}
Expand Down
1 change: 0 additions & 1 deletion apps/web/src/app/api/trpc/edge/[trpc]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const handler = (req: NextRequest) =>
endpoint: "/api/trpc/edge",
router: edgeRouter,
req: req,
// @ts-expect-error
createContext: () => createTRPCContext({ req }),
onError: ({ error }) => {
console.log("Error in tRPC handler (edge)");
Expand Down
1 change: 0 additions & 1 deletion apps/web/src/app/api/trpc/lambda/[trpc]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const handler = (req: NextRequest) =>
endpoint: "/api/trpc/lambda",
router: lambdaRouter,
req: req,
// @ts-expect-error
createContext: () => createTRPCContext({ req }),
onError: ({ error }) => {
console.log("Error in tRPC handler (lambda)");
Expand Down
Loading
Loading