Skip to content

Commit

Permalink
Add a mdx override for the edit on github link
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonRomano committed Dec 28, 2024
1 parent b014dc5 commit d142596
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/config/keybind/reference.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: Keybinding Action Reference
description: Reference of all Ghostty keybinding actions.
editOnGithubLink: https://github.com/ghostty-org/ghostty/edit/main/src/input/Binding.zig
---

This is a reference of all Ghostty keybinding actions.
Expand Down
2 changes: 1 addition & 1 deletion docs/config/reference.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: Reference
description: Reference of all Ghostty configuration options.
editOnGithubLink: https://github.com/ghostty-org/ghostty/edit/main/src/config/Config.zig
---

This is a reference of all Ghostty configuration options. These
Expand Down Expand Up @@ -2061,4 +2062,3 @@ Changing this configuration requires a full restart of
Ghostty to take effect.

This only works on macOS since only macOS has an auto-update feature.

8 changes: 8 additions & 0 deletions src/lib/fetch-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export interface DocsPageData {
slug: string;
title: string;
description: string;
// There are scenarios in which the GitHub link should
// not be the website source MDX file, due to the MDX being
// generated from some upstream source. This is an optional
// frontmatter that can override the link.
editOnGithubLink: string | null;
hideSidecar: boolean;
content: MDXRemoteSerializeResult;
relativeFilePath: string;
Expand Down Expand Up @@ -94,6 +99,9 @@ async function loadDocsPageFromRelativeFilePath(
relativeFilePath,
title: mdxFileContent.data.title,
description: mdxFileContent.data.description,
editOnGithubLink: mdxFileContent.data.editOnGithubLink
? mdxFileContent.data.editOnGithubLink
: null,
hideSidecar: mdxFileContent.data.hasOwnProperty("hideSidecar")
? mdxFileContent.data.hideSidecar
: false,
Expand Down
9 changes: 8 additions & 1 deletion src/pages/docs/[...path]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,20 @@ export default function DocsPage({
docsPageData: {
title,
description,
editOnGithubLink,
content,
relativeFilePath,
pageHeaders,
hideSidecar,
},
breadcrumbs,
}: DocsPageProps) {
// Calculate the "Edit in Github" link. If it's not provided
// in the frontmatter, point to the website repo mdx file.
editOnGithubLink = editOnGithubLink
? editOnGithubLink
: `${GITHUB_REPO_URL}/edit/main/${relativeFilePath}`;

return (
<NavFooterLayout
docsNavTree={navTreeData}
Expand Down Expand Up @@ -126,7 +133,7 @@ export default function DocsPage({
<CustomMDX content={content} />
<br />
<div className={s.editOnGithub}>
<a href={`${GITHUB_REPO_URL}/edit/main/${relativeFilePath}`}>
<a href={editOnGithubLink}>
Edit on GitHub <Pencil size={14} />
</a>
</div>
Expand Down

0 comments on commit d142596

Please sign in to comment.