|
| 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