From e5e93442ff8a33ea8f4b27ab16a4e128d955dcba Mon Sep 17 00:00:00 2001 From: mcnaveen <8493007+mcnaveen@users.noreply.github.com> Date: Thu, 3 Oct 2024 22:33:09 +0530 Subject: [PATCH] feat: hook link renderer in post desc --- app/[slug]/[board]/(main)/[...post]/page.tsx | 15 +++++++-- app/[slug]/page.tsx | 1 - components/common/link-renderer.tsx | 33 +++++++++----------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/app/[slug]/[board]/(main)/[...post]/page.tsx b/app/[slug]/[board]/(main)/[...post]/page.tsx index cf5ba82..ef2e6ec 100644 --- a/app/[slug]/[board]/(main)/[...post]/page.tsx +++ b/app/[slug]/[board]/(main)/[...post]/page.tsx @@ -9,6 +9,7 @@ import { authOptions } from "@/lib/auth"; import { Button } from "@/components/ui/button"; import { Reply } from "@/components/replies/create"; import { RepliesList } from "@/components/replies/list"; +import { LinkRenderer } from "@/components/common/link-renderer"; export const dynamic = "force-dynamic"; export const revalidate = 0; @@ -62,8 +63,18 @@ export default async function PostPage({
- {post.description} +
+ {post?.description
+ ?.split(/(https?:\/\/[^\s]+)/g)
+ .map((part, index) =>
+ part.match(/https?:\/\/[^\s]+/) ? (
+
{formatDistance(post.createdAt, new Date(), {
diff --git a/app/[slug]/page.tsx b/app/[slug]/page.tsx
index ff6b55a..a330d27 100644
--- a/app/[slug]/page.tsx
+++ b/app/[slug]/page.tsx
@@ -16,7 +16,6 @@ import { BoardFilter } from "@/components/boards/filter";
import NotFound from "./not-found";
import PrivateBoard from "./private";
-// meta data
export async function generateMetadata({
params,
}: {
diff --git a/components/common/link-renderer.tsx b/components/common/link-renderer.tsx
index 558fb95..67e0928 100644
--- a/components/common/link-renderer.tsx
+++ b/components/common/link-renderer.tsx
@@ -4,7 +4,7 @@ import React from "react";
import Link from "next/link";
import Image from "next/image";
import { useQuery } from "@tanstack/react-query";
-import { Globe, ExternalLink } from "lucide-react";
+import { Globe } from "lucide-react";
const fetchMetaTags = async (href: string) => {
const response = await fetch(`/api/metatags?url=${href}`);
@@ -42,22 +42,19 @@ export const LinkRenderer = ({
}
return (
-
-
- {data.favicon ? (
-