Skip to content

Commit 3245937

Browse files
committed
Add a link for creating a GitHub issue
Closes #110 In the previous docs site (github.com/gravitational/docs), a "Create issue on GitHub button" was a valuable source of feedback. This change adds a link that opens a new tab with the GitHub Create Issue form, prepopulated with the URL path of the current docs page. The best positioning for such a link is not obvious. In the previous docs site, we placed the button on the right sidebar under the table of contents for a given docs page. However, on the Docusaurus site, in-page tables of contents sometimes span the entire viewport height, e.g., in the main FAQ page with its 20 H2 headers, making a button on the right sidebar difficult to find. Further, Docusaurus makes some styling assumptions about the right sidebar, like the fact that the `TOCItems` component includes a left border but the column containing it does not, that make it non-trivial to style a new component there. We would need to rework the styling of the entire right sidebar component layout. The left sidebar is also not an ideal place to add this link, since it handles navigation for the entire docs site, and it would be unexpected to find a component there that is scoped to a single page. The solution this change proposes is to add the GitHub issue link below the main title of each page, swizzling the `@theme/DocItem/Content` component. This approach requires minimal reworking of the Docusaurus component layout, but still offers users a highly visible option to report an issue that, if a user is not interested in reporting an issue, remains relatively unobtrusive. This change adds a self-contained `GitHubIssueLink` component, and we can move this to a more suitable location (or turn it from a link into a button) when time opens up.
1 parent 38c6b3a commit 3245937

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.githubLink {
2+
font-style: italic;
3+
box-sizing: border-box;
4+
min-width: 0;
5+
transition: color var(--t-interaction);
6+
color: var(--ifm-font-color-base);
7+
8+
&:hover,
9+
&:active,
10+
&:focus {
11+
text-decoration: underline;
12+
}
13+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import styles from "./GitHubIssueLink.module.css";
2+
3+
export interface GitHubIssueLinkProps {
4+
pathname: string;
5+
}
6+
7+
const getIssueTitle = function (pagePath: string) {
8+
return encodeURIComponent(`[docs] ${pagePath}: <DESCRIBE YOUR ISSUE>`);
9+
};
10+
11+
const getIssueBody = function (pagePath: string) {
12+
return encodeURIComponent(`## Applies To
13+
14+
${pagePath}
15+
16+
## Details
17+
18+
<!-- Describe the documentation improvements you wish to see. -->
19+
20+
## How will we know this is resolved?
21+
22+
<!-- Briefly describe a test we can carry out. Scope this as narrowly as possible. -->
23+
24+
## Related Issues
25+
26+
<!-- Please make an effort to find related issues on GitHub and list them here. This makes a big difference in how we prioritize and schedule work. -->
27+
`);
28+
};
29+
30+
export const getReportIssueURL = function (pagePath: string): string {
31+
const mdxPath = "`" + pagePath + "`";
32+
return `https://github.com/gravitational/teleport/issues/new?labels=documentation&title=${getIssueTitle(mdxPath)}&body=${getIssueBody(mdxPath)}`;
33+
};
34+
export const GitHubIssueLink = function ({ pathname }: GitHubIssueLinkProps) {
35+
return (
36+
<p>
37+
<a
38+
className={styles.githubLink}
39+
href={getReportIssueURL(pathname)}
40+
target={"_blank"}
41+
>
42+
{"Report an issue with this page."}
43+
</a>
44+
</p>
45+
);
46+
};

src/theme/DocItem/Content/index.tsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React, {type ReactNode} from 'react';
2+
import clsx from 'clsx';
3+
import {ThemeClassNames} from '@docusaurus/theme-common';
4+
import {useDoc} from '@docusaurus/plugin-content-docs/client';
5+
import Heading from '@theme/Heading';
6+
import MDXContent from '@theme/MDXContent';
7+
import type {Props} from '@theme/DocItem/Content';
8+
import {GitHubIssueLink} from "/src/components/GitHubIssueLink";
9+
import { useLocation } from "@docusaurus/router";
10+
11+
/**
12+
Title can be declared inside md content or declared through
13+
front matter and added manually. To make both cases consistent,
14+
the added title is added under the same div.markdown block
15+
See https://github.com/facebook/docusaurus/pull/4882#issuecomment-853021120
16+
17+
We render a "synthetic title" if:
18+
- user doesn't ask to hide it with front matter
19+
- the markdown content does not already contain a top-level h1 heading
20+
*/
21+
function useSyntheticTitle(): string | null {
22+
const {metadata, frontMatter, contentTitle} = useDoc();
23+
const shouldRender =
24+
!frontMatter.hide_title && typeof contentTitle === 'undefined';
25+
if (!shouldRender) {
26+
return null;
27+
}
28+
return metadata.title;
29+
}
30+
31+
export default function DocItemContent({children}: Props): ReactNode {
32+
const location = useLocation();
33+
const syntheticTitle = useSyntheticTitle();
34+
return (
35+
<div className={clsx(ThemeClassNames.docs.docMarkdown, 'markdown')}>
36+
{syntheticTitle && (
37+
<header>
38+
<Heading as="h1">{syntheticTitle}</Heading>
39+
<GitHubIssueLink pathname={location.pathname}/>
40+
</header>
41+
)}
42+
<MDXContent>{children}</MDXContent>
43+
</div>
44+
);
45+
}

0 commit comments

Comments
 (0)