Skip to content

Commit

Permalink
🐛 fix(profile): empty profile detail page and meta tag
Browse files Browse the repository at this point in the history
  • Loading branch information
lwinmoepaing committed Oct 21, 2023
1 parent 4e8cd4a commit fd008a4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/app/profile/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Container from "@/components/Common/Container/Container";
import { Mdx } from "@/components/Common/Mdx/Mdx";
import SpacingDivider from "@/components/Common/SpacingDivider/SpacingDivider";
import TitleText from "@/components/Common/TitleText/TitleText";
import { allProfiles } from "contentlayer/generated";
import { notFound } from "next/navigation";
import { FC } from "react";
Expand Down Expand Up @@ -28,7 +29,7 @@ export async function generateMetadata({
openGraph: {
title: `Profile | ${profile.name}`,
description: `Profile | ${profile.description}`,
image: !!profile.image
images: !!profile.image
? profile.image
: "https://mmswe.com/images/landing/galaxy.jpg",
siteName: `https://mmswe.com/profile/${slug}`,
Expand All @@ -52,7 +53,11 @@ const PProfileDetailPage: FC<TPProfileDetailPageProps> = async ({

return (
<Container>
<Mdx code={profile.body.code} />
<Mdx
code={profile.body.code}
extraText={`${profile.name} | ${profile.description}`}
/>

<SpacingDivider size="lg" />
</Container>
);
Expand Down
5 changes: 5 additions & 0 deletions src/app/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import { profileHelperService } from "@/utils/profileHelper";
export const metadata: Metadata = {
title: `Profile List | ${APP_CONFIG.title}`,
description: APP_CONFIG.description,
openGraph: {
title: `Profile List | ${APP_CONFIG.title}`,
description: APP_CONFIG.description,
images: "https://mmswe.com/images/landing/galaxy.jpg",
},
};

const getAllProfileList = async () => {
Expand Down
29 changes: 26 additions & 3 deletions src/components/Common/Mdx/Mdx.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"use client";

import { cn } from "@/utils";
import { useMDXComponent } from "next-contentlayer/hooks";
import React from "react";
import React, { useEffect, useState } from "react";
import TitleText from "../TitleText/TitleText";

const components = {
h1: ({ className, ...rest }: React.HTMLAttributes<HTMLHeadingElement>) => (
Expand Down Expand Up @@ -155,14 +158,34 @@ const components = {

interface MdxProps {
code: string;
extraText?: string;
}

export function Mdx({ code }: MdxProps) {
export function Mdx({ code, extraText }: MdxProps) {
const Component = useMDXComponent(code);
const [showExtraText, setShowExtraText] = useState(false);

useEffect(() => {
const mdxContainer = document.getElementById("mdx_container");
setTimeout(() => {
if (mdxContainer && !mdxContainer.innerHTML) {
setShowExtraText(true);
}
}, 300);
return () => {};
}, []);

return (
<div className="mdx">
<div className="mdx" id="mdx_container">
<Component components={components} />
{showExtraText && !!extraText ? (
<>
<TitleText>{extraText}</TitleText>
<TitleText tag="h2" className="text-sm mt-5">
Note: The profile owner needs to update their Profile Detail Page
</TitleText>
</>
) : null}
</div>
);
}

0 comments on commit fd008a4

Please sign in to comment.