-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.tsx
More file actions
54 lines (48 loc) · 2.03 KB
/
index.tsx
File metadata and controls
54 lines (48 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import React, { useRef, useEffect } from "react";
import BlogPostPage from "@theme-original/BlogPostPage";
import Authors from "@site/src/theme/BlogPostItem/Header/Authors";
import { useScrollReset } from "@site/src/hooks/useScrollReset";
export default function BlogPostPageWrapper(props: any) {
const Content = props?.content as React.ComponentType<any> & { metadata?: any };
const meta = Content?.metadata || props?.metadata || {};
const headerRef = useRef<HTMLDivElement | null>(null);
const titleRef = useRef<HTMLHeadingElement | null>(null);
const resetScrollToTop = useScrollReset(['/blog']);
useEffect(() => {
resetScrollToTop();
}, [resetScrollToTop]);
return (
<div className="wl-post-page-wrapper">
{/* Custom Header */}
<div className="wl-post-header" ref={headerRef}>
{meta?.title ? <h1 className="wl-post-title" ref={titleRef}>{meta.title}</h1> : null}
<Authors authors={meta?.authors} date={meta?.date} />
</div>
{/* Original BlogPostPage (keeps default markdown + code styles) */}
<div className="wl-post-original">
<BlogPostPage {...props} />
</div>
{/* Custom Share Section */}
<section className="wl-post-extras">
<div className="wl-share">
{(() => {
const currentUrl = typeof window !== "undefined" ? window.location.href : meta?.permalink ?? "";
const shareText = `I went through the @Wonderland's blog rabbit hole 🐇 Take a look at this post 👉${meta?.title ?? ""}\n${currentUrl}`;
const intent = `https://twitter.com/intent/tweet?text=${encodeURIComponent(shareText)}`;
return (
<a
className="wl-share-button"
href={intent}
target="_blank"
rel="noopener noreferrer"
aria-label="Share this article"
>
<img src="/img/sharing-button.svg" alt="" aria-hidden />
</a>
);
})()}
</div>
</section>
</div>
);
}