diff --git a/_contents/posts/2024/05/15/first-post.md b/_contents/posts/2024/05/15/first-post.md index 5aeceae..e4a6a7a 100644 --- a/_contents/posts/2024/05/15/first-post.md +++ b/_contents/posts/2024/05/15/first-post.md @@ -6,7 +6,7 @@ title: "Preview Mode for Static Generation" description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit." coverImage: "/assets/blog/preview/cover.jpg" ogImage: - url: "/assets/blog/preview/cover.jpg" + url: "/img/smug-me-export.png" --- ### Table Of Contents diff --git a/src/app/_components/BlogPost/index.tsx b/src/app/_components/BlogPost/index.tsx index b3c9b6c..1f1b4df 100644 --- a/src/app/_components/BlogPost/index.tsx +++ b/src/app/_components/BlogPost/index.tsx @@ -1,18 +1,80 @@ +"use client"; + import Link from "next/link"; import "./markdown.css"; import "./style.scss"; import "highlight.js/styles/monokai.css"; +import { + BiCross, + BiLogoFacebook, + BiLogoFacebookSquare, + BiLogoLinkedinSquare, + BiLogoTwitter, + BiShare, + BiX, +} from "react-icons/bi"; +import { + generateFacebookShare, + generateLinkedInShare, + generateTwitterShare, +} from "@/lib/share"; +import { Post } from "@/interfaces/post"; +import { useState } from "react"; -export type BlogPostProps = { +export type BlogPostProps = Post & { content: string; - title: string; }; export default function BlogPost({ content, ...post }: BlogPostProps) { + const shareLinks = [ + { + href: generateLinkedInShare({ content, ...post }), + title: "share on linkedin", + icon: , + }, + { + href: generateTwitterShare({ content, ...post }), + title: "share on twitter", + icon: , + }, + { + href: generateFacebookShare({ content, ...post }), + title: "share on facebook", + icon: , + }, + ]; + + const [shareOpen, setShareOpen] = useState(false); + return ( <> -
-

+ -

- + + ); } diff --git a/src/app/_components/layout/Footer/index.tsx b/src/app/_components/layout/Footer/index.tsx index f8f5ddf..3543a57 100644 --- a/src/app/_components/layout/Footer/index.tsx +++ b/src/app/_components/layout/Footer/index.tsx @@ -1,3 +1,4 @@ +import { baseURL } from "@/constants"; import style from "./style.module.scss"; const Footer = () => ( @@ -6,7 +7,7 @@ const Footer = () => (
© 2024 - Ridho Azhar + Ridho Azhar Inspired by{" "} diff --git a/src/app/posts/[...path]/page.tsx b/src/app/posts/[...path]/page.tsx index 9f03f3b..45a0118 100644 --- a/src/app/posts/[...path]/page.tsx +++ b/src/app/posts/[...path]/page.tsx @@ -1,5 +1,6 @@ import BlogPost from "@/app/_components/BlogPost"; import BaseLayout from "@/app/_components/layout/BaseLayout"; +import { baseURL } from "@/constants"; import { getAllPosts, getPostBySlug } from "@/lib/api"; import mdToHtml from "@/lib/markdown"; import { Metadata } from "next"; @@ -20,7 +21,7 @@ export default async function Post({ params }: Props) { return (
- +
); @@ -37,9 +38,17 @@ export function generateMetadata({ params }: Props): Metadata { return { title, + description: post.description, + robots: { follow: true, index: true }, openGraph: { title, + url: `${baseURL}/posts/${post.path.join("/")}`, + description: post.description, images: [post.ogImage.url], + type: "article", + authors: "ridhozhr10.github.io", + publishedTime: post.created_at, + modifiedTime: post.updated_at, }, }; } diff --git a/src/constants.ts b/src/constants.ts new file mode 100644 index 0000000..ea08eb4 --- /dev/null +++ b/src/constants.ts @@ -0,0 +1 @@ +export const baseURL = "https://ridhozhr10.github.io"; diff --git a/src/interfaces/post.ts b/src/interfaces/post.ts index b3d7395..2752dbe 100644 --- a/src/interfaces/post.ts +++ b/src/interfaces/post.ts @@ -4,13 +4,14 @@ export type Post = { created_at: string; updated_at?: string; - + title: string; description: string; - coverImage: string; + excerpt?: string; + coverImage?: string; ogImage: { url: string; }; content: string; -}; \ No newline at end of file +}; diff --git a/src/lib/share.ts b/src/lib/share.ts new file mode 100644 index 0000000..8007c82 --- /dev/null +++ b/src/lib/share.ts @@ -0,0 +1,19 @@ +import { baseURL } from "@/constants"; +import { Post } from "@/interfaces/post"; + +export function generateLinkedInShare(post: Post): string { + const url = `${baseURL}/posts/${post.path.join("/")}`; + return `https://www.linkedin.com/sharing/share-offsite/?url=${encodeURI( + url + )}`; +} + +export function generateTwitterShare(post: Post): string { + const url = `${baseURL}/posts/${post.path.join("/")}`; + return `https://twitter.com/intent/tweet/?url=${encodeURI(url)}`; +} + +export function generateFacebookShare(post: Post): string { + const url = `${baseURL}/posts/${post.path.join("/")}`; + return `https://facebook.com/sharer/sharer.php?u=${encodeURI(url)}`; +}