Skip to content

Commit

Permalink
feat: add edit-on-github link to pages
Browse files Browse the repository at this point in the history
  • Loading branch information
A-Najmabadi committed Nov 14, 2024
1 parent 3e6fc38 commit 607e59b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/components/Common/editOnGitHubLink.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// components/EditOnGitHubLink.jsx
import { useRouter } from "next/router";
import { GoPencil } from "react-icons/go";

const EditOnGitHubLink = () => {
const router = useRouter();
const path = router.asPath.replace(/\/$/, "");
const githubUrl = `https://github.com/liara-cloud/docs/blob/master/src/pages${path}.mdx`;

return (
<div
dir="ltr"
className="text-blue-500"
style={{ textAlign: "right", marginTop: "2em" }}
>
<a
href={githubUrl}
className="flex gap-2 bg-[#0e9cff34] hover:bg-[#0e9cff24] transition-all w-[max-content] py-1 rounded-lg align-center border-gray-400 px-2"
target="_blank"
rel="noopener noreferrer"
>
ویرایش در گیت‌هاب
<GoPencil className="mt-[4px]" />
</a>
</div>
);
};

export default EditOnGitHubLink;
7 changes: 6 additions & 1 deletion src/components/Layout/index.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import React, { useState } from "react";
import Header from "@/components/Header";
import Sidebar from "@/components/Sidebar";
import EditOnGitHubLink from "@/components/Common/editOnGitHubLink";
import { useRouter } from "next/router";

const Layout = ({ children }) => {
const [showSidebar, setShowSidebar] = useState(false);


const router = useRouter();

return (
<main>
<div>
<div className="flex">
<Sidebar showSidebar={showSidebar} setShowSidebar={setShowSidebar} />
<div className="w-[100%] px-4 mt-[80px] md:px-0 overflow-x-hidden md:w-[1350px] layout md:pr-[300px] md:mt-[100px] md:mx-auto pb-10">
{children}
{router.pathname !== "/" && <EditOnGitHubLink />}
</div>
</div>
<Header setShowSidebar={setShowSidebar} />
Expand Down

0 comments on commit 607e59b

Please sign in to comment.