From 1d1e9f82c934fcd2e375ef2dbe67c7866925d5bc Mon Sep 17 00:00:00 2001 From: Ru Chern Chong Date: Fri, 29 Nov 2024 15:17:06 +0800 Subject: [PATCH] fix: Refactor Journals to Notes --- app/{journals => notes}/[slug]/page.tsx | 28 ++++++++-------- app/{journals => notes}/page.tsx | 18 +++++------ config/index.ts | 2 +- content/{journals => notes}/console-table.mdx | 0 .../{journals => notes}/css-line-clamp.mdx | 0 .../double-tilde-operator-in-javascript.mdx | 0 content/{journals => notes}/import-meta.mdx | 0 .../{journals => notes}/module-federation.mdx | 0 .../new-array-prototype-methods.mdx | 0 ...rse-string-to-boolean-using-json-parse.mdx | 0 .../{journals => notes}/repeat-in-string.mdx | 0 .../rss-autodiscovery-to-site.mdx | 0 .../ways-to-use-exclude-in-typescript.mdx | 0 contentlayer.config.ts | 32 +++++++++---------- 14 files changed, 40 insertions(+), 40 deletions(-) rename app/{journals => notes}/[slug]/page.tsx (65%) rename app/{journals => notes}/page.tsx (87%) rename content/{journals => notes}/console-table.mdx (100%) rename content/{journals => notes}/css-line-clamp.mdx (100%) rename content/{journals => notes}/double-tilde-operator-in-javascript.mdx (100%) rename content/{journals => notes}/import-meta.mdx (100%) rename content/{journals => notes}/module-federation.mdx (100%) rename content/{journals => notes}/new-array-prototype-methods.mdx (100%) rename content/{journals => notes}/parse-string-to-boolean-using-json-parse.mdx (100%) rename content/{journals => notes}/repeat-in-string.mdx (100%) rename content/{journals => notes}/rss-autodiscovery-to-site.mdx (100%) rename content/{journals => notes}/ways-to-use-exclude-in-typescript.mdx (100%) diff --git a/app/journals/[slug]/page.tsx b/app/notes/[slug]/page.tsx similarity index 65% rename from app/journals/[slug]/page.tsx rename to app/notes/[slug]/page.tsx index fe90b1a..5067ca7 100644 --- a/app/journals/[slug]/page.tsx +++ b/app/notes/[slug]/page.tsx @@ -1,6 +1,6 @@ import type { Metadata } from "next"; import { notFound } from "next/navigation"; -import { allJournals } from "contentlayer/generated"; +import { allNotes } from "contentlayer/generated"; import { Mdx } from "@/components/Mdx"; import { StructuredData } from "@/components/StructuredData"; import { Typography } from "@/components/Typography"; @@ -12,13 +12,13 @@ export const generateMetadata = async (props: { params: Params; }): Promise => { const params = await props.params; - const journal = allJournals.find((journal) => journal.slug === params.slug)!; + const note = allNotes.find((note) => note.slug === params.slug)!; - const title = journal.title; - const description = journal.title; - const publishedTime = journal.publishedAt; + const title = note.title; + const description = note.title; + const publishedTime = note.publishedAt; const images = `${BASE_URL}/og?title=${title}`; - const url = journal.url; + const url = note.url; return { title, @@ -44,27 +44,27 @@ export const generateMetadata = async (props: { }; export const generateStaticParams = () => - allJournals.map(({ slug }) => ({ slug })); + allNotes.map(({ slug }) => ({ slug })); -const JournalPage = async (props: { params: Params }) => { +const NotePage = async (props: { params: Params }) => { const params = await props.params; - const journal = allJournals.find((journal) => journal.slug === params.slug); + const note = allNotes.find((note) => note.slug === params.slug); - if (!journal) { + if (!note) { return notFound(); } return ( <> - +
- {journal.title} + {note.title} - +
); }; -export default JournalPage; +export default NotePage; diff --git a/app/journals/page.tsx b/app/notes/page.tsx similarity index 87% rename from app/journals/page.tsx rename to app/notes/page.tsx index bbd4a1e..30636c6 100644 --- a/app/journals/page.tsx +++ b/app/notes/page.tsx @@ -1,6 +1,6 @@ import type { Metadata } from "next"; import Link from "next/link"; -import { allJournals } from "contentlayer/generated"; +import { allNotes } from "contentlayer/generated"; import { format, formatISO, parseISO } from "date-fns"; import globalMetadata from "@/app/metadata"; import { openGraphImage, twitterImage } from "@/app/shared-metadata"; @@ -9,18 +9,18 @@ import { Typography } from "@/components/Typography"; import { sortByLatest } from "@/lib/sortByLatest"; import type { WebPage, WithContext } from "schema-dts"; -const title = `Journals`; +const title = "Notes"; const description = "A collection containing fun and interesting things I came across randomly."; export const metadata: Metadata = { - title: "Journals", + title, description, openGraph: { ...globalMetadata.openGraph, title, description, - url: "/journals", + url: "/notes", ...openGraphImage, }, twitter: { @@ -30,11 +30,11 @@ export const metadata: Metadata = { ...twitterImage, }, alternates: { - canonical: "/journals", + canonical: "/notes", }, }; -const JournalsPage = () => { +const NotesPage = () => { const structuredData: WithContext = { "@context": "https://schema.org", "@type": "WebPage", @@ -47,14 +47,14 @@ const JournalsPage = () => { <> - Journals + Notes {description}
- {allJournals.sort(sortByLatest).map(({ title, publishedAt, url }) => { + {allNotes.sort(sortByLatest).map(({ title, publishedAt, url }) => { const formattedDate = format(parseISO(publishedAt), "dd MMM yyyy"); return ( @@ -83,4 +83,4 @@ const JournalsPage = () => { ); }; -export default JournalsPage; +export default NotesPage; diff --git a/config/index.ts b/config/index.ts index 58a2d22..be6a534 100644 --- a/config/index.ts +++ b/config/index.ts @@ -9,7 +9,7 @@ export const BASE_URL: string = export const navLinks: NavLink[] = [ // { title: "Blog", href: "/blog" }, { title: "About", href: "/about" }, - { title: "Journals", href: "/journals" }, + { title: "Notes", href: "/notes" }, { title: "Projects", href: "/projects" }, // { title: "Resume", href: "/resume" }, ]; diff --git a/content/journals/console-table.mdx b/content/notes/console-table.mdx similarity index 100% rename from content/journals/console-table.mdx rename to content/notes/console-table.mdx diff --git a/content/journals/css-line-clamp.mdx b/content/notes/css-line-clamp.mdx similarity index 100% rename from content/journals/css-line-clamp.mdx rename to content/notes/css-line-clamp.mdx diff --git a/content/journals/double-tilde-operator-in-javascript.mdx b/content/notes/double-tilde-operator-in-javascript.mdx similarity index 100% rename from content/journals/double-tilde-operator-in-javascript.mdx rename to content/notes/double-tilde-operator-in-javascript.mdx diff --git a/content/journals/import-meta.mdx b/content/notes/import-meta.mdx similarity index 100% rename from content/journals/import-meta.mdx rename to content/notes/import-meta.mdx diff --git a/content/journals/module-federation.mdx b/content/notes/module-federation.mdx similarity index 100% rename from content/journals/module-federation.mdx rename to content/notes/module-federation.mdx diff --git a/content/journals/new-array-prototype-methods.mdx b/content/notes/new-array-prototype-methods.mdx similarity index 100% rename from content/journals/new-array-prototype-methods.mdx rename to content/notes/new-array-prototype-methods.mdx diff --git a/content/journals/parse-string-to-boolean-using-json-parse.mdx b/content/notes/parse-string-to-boolean-using-json-parse.mdx similarity index 100% rename from content/journals/parse-string-to-boolean-using-json-parse.mdx rename to content/notes/parse-string-to-boolean-using-json-parse.mdx diff --git a/content/journals/repeat-in-string.mdx b/content/notes/repeat-in-string.mdx similarity index 100% rename from content/journals/repeat-in-string.mdx rename to content/notes/repeat-in-string.mdx diff --git a/content/journals/rss-autodiscovery-to-site.mdx b/content/notes/rss-autodiscovery-to-site.mdx similarity index 100% rename from content/journals/rss-autodiscovery-to-site.mdx rename to content/notes/rss-autodiscovery-to-site.mdx diff --git a/content/journals/ways-to-use-exclude-in-typescript.mdx b/content/notes/ways-to-use-exclude-in-typescript.mdx similarity index 100% rename from content/journals/ways-to-use-exclude-in-typescript.mdx rename to content/notes/ways-to-use-exclude-in-typescript.mdx diff --git a/contentlayer.config.ts b/contentlayer.config.ts index 491b963..15c7562 100644 --- a/contentlayer.config.ts +++ b/contentlayer.config.ts @@ -63,9 +63,9 @@ export const Post = defineDocumentType(() => ({ }, })); -export const Journal = defineDocumentType(() => ({ - name: "Journal", - filePathPattern: "journals/**/*.mdx", +export const Note = defineDocumentType(() => ({ + name: "Note", + filePathPattern: "notes/**/*.mdx", contentType: "mdx", fields: { title: { type: "string", required: true }, @@ -76,27 +76,27 @@ export const Journal = defineDocumentType(() => ({ computedFields: { slug: { type: "string", - resolve: (journal) => { - const [_, slug] = journal._raw.flattenedPath.split("/"); + resolve: (note) => { + const [_, slug] = note._raw.flattenedPath.split("/"); return slug; }, }, structuredData: { type: "json", - resolve: (journal) => + resolve: (note) => ({ "@context": "https://schema.org", "@type": "BlogPosting", - headline: journal.title, - dateModified: journal.publishedAt, - datePublished: journal.publishedAt, - description: journal.title, + headline: note.title, + dateModified: note.publishedAt, + datePublished: note.publishedAt, + description: note.title, image: [ - journal.image - ? encodeURI(`${BASE_URL}/${journal.image}`) - : encodeURI(`${BASE_URL}/og?title=${journal.title}`), + note.image + ? encodeURI(`${BASE_URL}/${note.image}`) + : encodeURI(`${BASE_URL}/og?title=${note.title}`), ], - url: `${BASE_URL}/${journal._raw.flattenedPath}`, + url: `${BASE_URL}/${note._raw.flattenedPath}`, author: { "@type": "Person", name: "Ru Chern Chong", @@ -106,14 +106,14 @@ export const Journal = defineDocumentType(() => ({ }, url: { type: "string", - resolve: (journal) => `/${journal._raw.flattenedPath}`, + resolve: (note) => `/${note._raw.flattenedPath}`, }, }, })); export default makeSource({ contentDirPath: "content", - documentTypes: [Post, Journal], + documentTypes: [Post, Note], mdx: { remarkPlugins: [remarkGfm, remarkUnwrapImages], rehypePlugins: [