Skip to content

Added sticky share to social media component in blog website#323

Open
DARSHAN-R-DARSHAN wants to merge 1 commit intokeploy:mainfrom
DARSHAN-R-DARSHAN:design/sticky-share
Open

Added sticky share to social media component in blog website#323
DARSHAN-R-DARSHAN wants to merge 1 commit intokeploy:mainfrom
DARSHAN-R-DARSHAN:design/sticky-share

Conversation

@DARSHAN-R-DARSHAN
Copy link
Copy Markdown
Contributor

@DARSHAN-R-DARSHAN DARSHAN-R-DARSHAN commented Feb 12, 2026

Fix: keploy/keploy#3298

What I did

  • Ran the website locally
  • Checked if it works well

Now

Screenshot 2026-02-12 234527 Screenshot 2026-02-12 234555 Screenshot 2026-02-12 234748

Signed-off-by: DARSHAN-R-DARSHAN <darshanramanji07@gmail.com>
@DARSHAN-R-DARSHAN
Copy link
Copy Markdown
Contributor Author

Hi! @amaan-bhati, I think that the share option would look cool if it is on both PostHeader and below the blog banner.
If any changes are required, I would really be happy to fix them. Thanks!

@dhananjay6561
Copy link
Copy Markdown
Member

Hi @DARSHAN-R-DARSHAN

Thank you for contributing and taking the initiative to work on this!
However, since then the component has been revamped in the repository, and this issue is no longer present. Because of that, we won’t be able to proceed with merging this PR.

Feel free to explore other open issues in the repository and pick one that hasn’t been addressed yet. We’d be happy to review another contribution from you. Thanks again for your effort!

@dhananjay6561 dhananjay6561 requested a review from Copilot April 6, 2026 12:07
@dhananjay6561
Copy link
Copy Markdown
Member

Hey @DARSHAN-R-DARSHAN 👋 — thanks for putting this PR together, we appreciate the effort!

We've gone ahead and requested a Copilot review on this. Here's some context from the reviewer:

Share URL broken: missing https://, double slashes from basePath+asPath. Duplicate gap-5/gap-3 classes.

Once you've had a chance to go through the comments, please address the feedback and resolve the threads — and we'll get this across the line. Feel free to ask if anything's unclear. Happy coding! 💙

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a “sticky” social sharing UI to the blog post sidebar so readers can share the current post (Twitter/X, LinkedIn, and copy link) while scrolling.

Changes:

  • Added share URL construction and clipboard-copy behavior to PostBody.
  • Rendered a new “Share this” icon row in the sticky <aside> sidebar.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread components/post-body.tsx
Comment on lines +85 to +97

const currentURL = encodeURIComponent(
`keploy.io/${router.basePath + router.asPath}`
);
const twitterShareUrl = `https://twitter.com/share?url=${currentURL}`;
const linkedinShareUrl = `https://www.linkedin.com/shareArticle?url=${currentURL}`;
const copyToClipboard = async () => {
try {
await navigator.clipboard.writeText(`https://keploy.io/blog${router.asPath}`);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch (err) {
console.error("Failed to copy!", err);
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentURL is built as keploy.io/${router.basePath + router.asPath} which omits the protocol and will produce a double-slash before the path (e.g. keploy.io//blog/... because the path starts with /). This can lead to malformed share URLs. Build the absolute URL from the existing SITE_URL (or window.location.origin) and normalize slashes before encodeURIComponent.

Suggested change
const currentURL = encodeURIComponent(
`keploy.io/${router.basePath + router.asPath}`
);
const twitterShareUrl = `https://twitter.com/share?url=${currentURL}`;
const linkedinShareUrl = `https://www.linkedin.com/shareArticle?url=${currentURL}`;
const copyToClipboard = async () => {
try {
await navigator.clipboard.writeText(`https://keploy.io/blog${router.asPath}`);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch (err) {
console.error("Failed to copy!", err);
const origin =
typeof window !== "undefined"
? window.location.origin
: "https://keploy.io";
const normalizedPath = `${router.basePath || ""}${router.asPath || "/"}`
.replace(/\/{2,}/g, "/")
.replace(/^([^/])/, "/$1");
const absoluteCurrentURL = `${origin.replace(/\/+$/, "")}${normalizedPath}`;
const currentURL = encodeURIComponent(absoluteCurrentURL);
const twitterShareUrl = `https://twitter.com/share?url=${currentURL}`;
const linkedinShareUrl = `https://www.linkedin.com/shareArticle?url=${currentURL}`;
const copyToClipboard = async () => {
try {
await navigator.clipboard.writeText(absoluteCurrentURL);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch (err) {
console.error("Failed to copy the article link. Please copy the URL from your browser address bar instead.", err);

Copilot uses AI. Check for mistakes.
Comment thread components/post-body.tsx
Comment on lines +85 to +97

const currentURL = encodeURIComponent(
`keploy.io/${router.basePath + router.asPath}`
);
const twitterShareUrl = `https://twitter.com/share?url=${currentURL}`;
const linkedinShareUrl = `https://www.linkedin.com/shareArticle?url=${currentURL}`;
const copyToClipboard = async () => {
try {
await navigator.clipboard.writeText(`https://keploy.io/blog${router.asPath}`);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch (err) {
console.error("Failed to copy!", err);
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clipboard URL is hard-coded to https://keploy.io/blog${router.asPath} while the share URLs use a different construction. This can drift if the basePath/domain changes and can create inconsistent shared vs copied URLs. Prefer deriving all three from a single canonical base (e.g. SITE_URL) and the current path.

Suggested change
const currentURL = encodeURIComponent(
`keploy.io/${router.basePath + router.asPath}`
);
const twitterShareUrl = `https://twitter.com/share?url=${currentURL}`;
const linkedinShareUrl = `https://www.linkedin.com/shareArticle?url=${currentURL}`;
const copyToClipboard = async () => {
try {
await navigator.clipboard.writeText(`https://keploy.io/blog${router.asPath}`);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch (err) {
console.error("Failed to copy!", err);
const currentPath = `${router.basePath || ""}${router.asPath || ""}`;
const siteUrl =
typeof window !== "undefined"
? window.location.origin
: "https://keploy.io";
const canonicalUrl = `${siteUrl}${currentPath}`;
const encodedCanonicalUrl = encodeURIComponent(canonicalUrl);
const twitterShareUrl = `https://twitter.com/share?url=${encodedCanonicalUrl}`;
const linkedinShareUrl = `https://www.linkedin.com/shareArticle?url=${encodedCanonicalUrl}`;
const copyToClipboard = async () => {
try {
await navigator.clipboard.writeText(canonicalUrl);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch (err) {
console.error("Failed to copy the link. Please copy the URL from your browser address bar instead.", err);

Copilot uses AI. Check for mistakes.
Comment thread components/post-body.tsx
Comment on lines +94 to +96
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch (err) {
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setTimeout(() => setCopied(false), 2000) is not cleared on unmount, which can cause a state update on an unmounted component when navigating away quickly. Store the timeout id (e.g. in a ref) and clear it in an effect cleanup.

Copilot uses AI. Check for mistakes.
Comment thread components/post-body.tsx
Comment on lines +412 to +427
<Link
href={twitterShareUrl}
target="_blank"
rel="noopener noreferrer"
className="twitter-share-button text-xl text-black transition-colors duration-300 hover:text-blue-500"
>
<FaXTwitter className="icon" />
</Link>
<Link
href={linkedinShareUrl}
target="_blank"
rel="noopener noreferrer"
className="linkedin-share-button text-xl text-black transition-colors duration-300 hover:text-blue-500"
>
<FaLinkedin className="icon" />
</Link>
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Twitter/LinkedIn share links render icon-only content without an accessible name. Add an aria-label (or visually-hidden text) to each link so screen readers can announce what the control does.

Copilot uses AI. Check for mistakes.
Comment thread components/post-body.tsx
className="w-full h-60"
/>
</div> */}
<div className="flex flex-row gap-5 items-center gap-3 sm:gap-5 order-2 sm:order-none mt-2 md:mb-2">
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The container class list includes conflicting gap utilities (gap-5 and gap-3 sm:gap-5) which makes the effective spacing depend on class order and is easy to misread. Remove the redundant gap-* so only the intended spacing remains.

Suggested change
<div className="flex flex-row gap-5 items-center gap-3 sm:gap-5 order-2 sm:order-none mt-2 md:mb-2">
<div className="flex flex-row items-center gap-3 sm:gap-5 order-2 sm:order-none mt-2 md:mb-2">

Copilot uses AI. Check for mistakes.
Comment thread components/post-body.tsx
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch (err) {
console.error("Failed to copy!", err);
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new console.error("Failed to copy!", err) message doesn't give a user-actionable next step. Consider handling this as UI feedback (e.g. show a non-intrusive message like “Copy failed — please copy from the address bar”) instead of (or in addition to) logging.

Suggested change
console.error("Failed to copy!", err);
const copyFailureMessage = "Copy failed — please copy the link from the address bar.";
window.alert(copyFailureMessage);
console.error(copyFailureMessage, err);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature]: add a sticky share to social media component in blog website

3 participants