Skip to content

Commit fc8f5e2

Browse files
committed
feat: add edit page links
1 parent 60b68bd commit fc8f5e2

2 files changed

Lines changed: 78 additions & 1 deletion

File tree

src/docs-app/ui/components/content/ContentPage.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useEffect } from "react";
22
import MarkdownContent from "@/docs-app/ui/components/content/MarkdownContent.tsx";
3+
import EditPageLinks from "@/docs-app/ui/components/content/EditPageLinks.tsx";
34
import { useDocLayoutData } from "@/docs-app/ui/components/layout/DocLayout.tsx";
45
import { useContent } from "@/docs-app/ui/hooks/useContent.ts";
56
import { toast } from "@/shared/components/use-toast.ts";
@@ -97,7 +98,10 @@ const ContentPage: React.FC<ContentPageProps> = ({
9798
</p>
9899
</div>
99100
) : (
100-
<MarkdownContent content={content} />
101+
<>
102+
<MarkdownContent content={content} />
103+
<EditPageLinks contentPath={contentPath} />
104+
</>
101105
)}
102106
</div>
103107
);
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import React from "react";
2+
import { Pencil, Bug } from "lucide-react";
3+
import { Separator } from "@/shared/components/separator.tsx";
4+
5+
interface EditPageLinksProps {
6+
/** The content path like /sdk/01-sdk-getting-started.md */
7+
contentPath: string;
8+
}
9+
10+
const GITHUB_REPO = "showpass/api-docs-guide";
11+
const GITHUB_BRANCH = "master";
12+
const DOCS_BASE_PATH = "src/docs-app/data";
13+
14+
/**
15+
* Generates the GitHub edit URL for a documentation page
16+
*/
17+
const getEditUrl = (contentPath: string): string => {
18+
// contentPath is like /sdk/01-sdk-getting-started.md
19+
// We need: https://github.com/showpass/api-docs-guide/edit/master/src/docs-app/data/sdk/01-sdk-getting-started.md
20+
const relativePath = contentPath.startsWith("/")
21+
? contentPath.slice(1)
22+
: contentPath;
23+
return `https://github.com/${GITHUB_REPO}/edit/${GITHUB_BRANCH}/${DOCS_BASE_PATH}/${relativePath}`;
24+
};
25+
26+
/**
27+
* Generates the GitHub new issue URL for reporting a documentation issue
28+
*/
29+
const getIssueUrl = (contentPath: string): string => {
30+
const pageTitle = contentPath.split("/").pop()?.replace(".md", "") || "page";
31+
const issueTitle = encodeURIComponent(`Documentation issue: ${pageTitle}`);
32+
const issueBody = encodeURIComponent(
33+
`## Page\n\`${contentPath}\`\n\n## Issue Description\n\n<!-- Please describe what's incorrect or needs to be updated -->\n\n## Suggested Fix\n\n<!-- If you have a suggestion for how to fix it -->\n`
34+
);
35+
return `https://github.com/${GITHUB_REPO}/issues/new?title=${issueTitle}&body=${issueBody}&labels=documentation`;
36+
};
37+
38+
const EditPageLinks: React.FC<EditPageLinksProps> = ({ contentPath }) => {
39+
const editUrl = getEditUrl(contentPath);
40+
const issueUrl = getIssueUrl(contentPath);
41+
42+
return (
43+
<div className="mt-16 not-prose">
44+
<Separator className="mb-6 opacity-40" />
45+
<div className="flex flex-wrap items-center gap-4 text-sm">
46+
<span className="text-muted-foreground/70">Help us improve this page</span>
47+
<div className="flex items-center gap-3">
48+
<a
49+
href={editUrl}
50+
target="_blank"
51+
rel="noopener noreferrer"
52+
className="inline-flex items-center gap-1.5 text-muted-foreground hover:text-primary transition-colors group"
53+
>
54+
<Pencil className="h-3.5 w-3.5 opacity-70 group-hover:opacity-100 transition-opacity" />
55+
<span>Edit this page</span>
56+
</a>
57+
<span className="text-muted-foreground/30"></span>
58+
<a
59+
href={issueUrl}
60+
target="_blank"
61+
rel="noopener noreferrer"
62+
className="inline-flex items-center gap-1.5 text-muted-foreground hover:text-primary transition-colors group"
63+
>
64+
<Bug className="h-3.5 w-3.5 opacity-70 group-hover:opacity-100 transition-opacity" />
65+
<span>Report an issue</span>
66+
</a>
67+
</div>
68+
</div>
69+
</div>
70+
);
71+
};
72+
73+
export default EditPageLinks;

0 commit comments

Comments
 (0)