Skip to content

Commit

Permalink
fix: update SEO tags
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchernchong committed Nov 29, 2024
1 parent b72a958 commit 6bff119
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import "@/app/globals.css";
const inter = Inter({ subsets: ["latin"] });

const title = {
default: "Ru Chern",
template: "%s | Ru Chern",
default: "Home - Ru Chern",
template: "%s - Ru Chern",
};
const description =
"Frontend Developer from Singapore. Interested in automating workflows and building in React, Node, and Typescript.";
Expand Down
2 changes: 1 addition & 1 deletion app/notes/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const generateMetadata = async (props: {
const note = allNotes.find((note) => note.slug === params.slug)!;

const title = note.title;
const description = note.title;
const description = `Notes on ${note.title}`;
const publishedTime = note.publishedAt;
const images = `${BASE_URL}/og?title=${title}`;
const url = note.url;
Expand Down
3 changes: 2 additions & 1 deletion app/posts/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
EyeIcon,
InformationCircleIcon,
} from "@heroicons/react/24/outline";
import { truncate } from "@/utils/truncate";

type Params = Promise<{ slug: string }>;

Expand All @@ -26,7 +27,7 @@ export const generateMetadata = async (props: {
const post = allPosts.find((post) => post.slug === params.slug)!;

const title = post.title;
const description = post.excerpt;
const description = truncate(post.excerpt);
const publishedTime = post.publishedAt;
const url = post.url;
const images = `${BASE_URL}/og?title=${title}`;
Expand Down
3 changes: 2 additions & 1 deletion contentlayer.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import remarkGfm from "remark-gfm";
import rehypeSlug from "rehype-slug";
import rehypeAutolinkHeadings from "rehype-autolink-headings";
import remarkUnwrapImages from "remark-unwrap-images";
import { truncate } from "@/utils/truncate";
// import rehypePrettyCode, {
// type Options as PrettyCodeOptions,
// } from "rehype-pretty-code";
Expand Down Expand Up @@ -42,7 +43,7 @@ export const Post = defineDocumentType(() => ({
headline: post.title,
dateModified: post.publishedAt,
datePublished: post.publishedAt,
description: post.excerpt,
description: truncate(post.excerpt),
image: [
post.image
? encodeURI(`${BASE_URL}/${post.image}`)
Expand Down
Empty file.
15 changes: 15 additions & 0 deletions utils/truncate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Truncates a string to a specified maximum length and adds an ellipsis if truncated.
*
* @param str - The input string to truncate
* @param maxLength - Maximum length of the output string (default: 160 characters)
* @returns The truncated string with ellipsis if truncated, or the original string if shorter than maxLength
*
* @example
* truncate("This is a long string", 10) // Returns "This is..."
* truncate("Short", 10) // Returns "Short"
*/
export const truncate = (str: string, maxLength: number = 160) => {
if (str.length <= maxLength) return str;
return str.slice(0, 157) + "...";
};

0 comments on commit 6bff119

Please sign in to comment.