From 9115ca583e435907e46413ac359fa90ed4227a34 Mon Sep 17 00:00:00 2001 From: Herbie Vine Date: Fri, 23 Jun 2023 22:59:41 +0200 Subject: [PATCH] added better urls + changed so long post name --- contentlayer.config.js | 2 +- next.config.js | 20 +++++++++++++--- ...> 42-a-comprehensive-guide-to-so_long.mdx} | 2 +- src/app/{ => post}/[slug]/not-found.tsx | 0 src/app/{ => post}/[slug]/page.tsx | 24 ++++++++++--------- src/app/sitemap.ts | 2 +- src/components/{Render.tsx => render.tsx} | 5 ++-- 7 files changed, 36 insertions(+), 19 deletions(-) rename posts/{42-building-a-game-with-the-mlx.mdx => 42-a-comprehensive-guide-to-so_long.mdx} (99%) rename src/app/{ => post}/[slug]/not-found.tsx (100%) rename src/app/{ => post}/[slug]/page.tsx (92%) rename src/components/{Render.tsx => render.tsx} (86%) diff --git a/contentlayer.config.js b/contentlayer.config.js index d55495f..4932ac2 100644 --- a/contentlayer.config.js +++ b/contentlayer.config.js @@ -38,7 +38,7 @@ export const Post = defineDocumentType(() => ({ computedFields: { url: { type: "string", - resolve: (post) => `/${post._raw.flattenedPath}`, + resolve: (post) => `/post/${post._raw.flattenedPath}`, }, slug: { type: "string", diff --git a/next.config.js b/next.config.js index 17ea269..e854c70 100644 --- a/next.config.js +++ b/next.config.js @@ -1,4 +1,4 @@ -const { withContentlayer } = require('next-contentlayer'); +const { withContentlayer } = require("next-contentlayer"); /** @type {import('next').NextConfig} */ const nextConfig = { @@ -7,6 +7,20 @@ const nextConfig = { experimental: { appDir: true, }, -} + redirects() { + return [ + { + source: "/42-a-comprehensive-guide-to-pipex", + destination: "/post/42-a-comprehensive-guide-to-pipex", + permanent: true, + }, + { + source: "/42-building-a-game-with-the-mlx", + destination: "/post/42-a-comprehensive-guide-to-so_long", + permanent: true, + }, + ]; + }, +}; -module.exports = withContentlayer(nextConfig) +module.exports = withContentlayer(nextConfig); diff --git a/posts/42-building-a-game-with-the-mlx.mdx b/posts/42-a-comprehensive-guide-to-so_long.mdx similarity index 99% rename from posts/42-building-a-game-with-the-mlx.mdx rename to posts/42-a-comprehensive-guide-to-so_long.mdx index ec7a6bc..02beb67 100644 --- a/posts/42-building-a-game-with-the-mlx.mdx +++ b/posts/42-a-comprehensive-guide-to-so_long.mdx @@ -1,5 +1,5 @@ --- -title: "42: Building a Game with the MLX" +title: "42: A Comprehensive Guide to So Long" description: "A deep dive into the 42 project so_long, including the MLX library, parsing, and error handling." tags: ["42", "so_long", "unix", "linux", "c", "guide", "tutorial", "mlx", "x11"] createdAt: 2023-06-01 diff --git a/src/app/[slug]/not-found.tsx b/src/app/post/[slug]/not-found.tsx similarity index 100% rename from src/app/[slug]/not-found.tsx rename to src/app/post/[slug]/not-found.tsx diff --git a/src/app/[slug]/page.tsx b/src/app/post/[slug]/page.tsx similarity index 92% rename from src/app/[slug]/page.tsx rename to src/app/post/[slug]/page.tsx index 61841f0..61c0757 100644 --- a/src/app/[slug]/page.tsx +++ b/src/app/post/[slug]/page.tsx @@ -1,7 +1,7 @@ import React from "react"; import { notFound } from "next/navigation"; import { allPosts } from "contentlayer/generated"; -import Render from "@/components/Render"; +import Render from "@/components/render"; import Balancer from "react-wrap-balancer"; import dayjs from "dayjs"; import { Metadata } from "next"; @@ -12,11 +12,19 @@ export async function generateStaticParams() { })); } +type PostPageProps = { + params?: { + slug?: string; + }; +}; + export async function generateMetadata({ params, -}: { - params: { slug: string }; -}): Promise { +}: PostPageProps): Promise { + if (!params?.slug) { + return; + } + const post = allPosts.find((post) => post.slug === params.slug); if (!post) { @@ -32,7 +40,7 @@ export async function generateMetadata({ keywords: post.tags.join(", "), }), openGraph: { - title, + title: `${title} - Reactive`, description, type: "article", publishedTime: dayjs(createdAt).toISOString(), @@ -52,12 +60,6 @@ export async function generateMetadata({ }; } -type PostPageProps = { - params?: { - slug?: string; - }; -}; - export default async function PostPage({ params }: PostPageProps) { const post = allPosts.find(({ slug }) => slug === params?.slug); diff --git a/src/app/sitemap.ts b/src/app/sitemap.ts index e4a1484..d82c792 100644 --- a/src/app/sitemap.ts +++ b/src/app/sitemap.ts @@ -5,7 +5,7 @@ const BASE_URL = "https://reactive.so"; export default function sitemap(): MetadataRoute.Sitemap { const posts = allPosts.map((post) => ({ - url: `${BASE_URL}/${post.slug}`, + url: `${BASE_URL}${post.url}`, lastModified: new Date(post.updatedAt).toISOString().split("T")[0], })); diff --git a/src/components/Render.tsx b/src/components/render.tsx similarity index 86% rename from src/components/Render.tsx rename to src/components/render.tsx index 2fc8a8f..436024e 100644 --- a/src/components/Render.tsx +++ b/src/components/render.tsx @@ -1,10 +1,11 @@ "use client"; + import { useMDXComponent } from "next-contentlayer/hooks"; import React from "react"; -type RenderProps = React.PropsWithChildren<{ +type RenderProps = { code: string; -}>; +}; export default function Render({ code }: RenderProps) { const MDX = useMDXComponent(code);