Skip to content

Commit 266e683

Browse files
committed
Add edit-on-github to blog posts too
1 parent 9d25ea5 commit 266e683

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

src/app/(documentation)/docs/[...slug]/page.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import type { Metadata } from 'next/types';
22

3-
import { EditOnGithub } from '../docs.styles';
3+
import { EditOnGithub } from '@/components/elements/edit-on-github';
44

5-
import { PencilSimple } from '@/components/elements/icon';
6-
import { Link } from '@/components/elements/link';
75
import { DocumentationLayout } from '@/components/layout/documentation';
86
import { ROOT_DOCS_DIRECTORY, getAllDocsMeta, getDocBySlug } from '@/lib/mdx/docs';
97
import { findFile } from '@/lib/mdx/utils/find-file';
@@ -52,12 +50,7 @@ export default async function DocsPage({ params }: DocPageProps) {
5250
return (
5351
<DocumentationLayout title={title} links={links}>
5452
{Content}
55-
<EditOnGithub>
56-
<PencilSimple /> Edit this page
57-
<Link href={editUrl} target="_blank">
58-
on GitHub
59-
</Link>
60-
</EditOnGithub>
53+
<EditOnGithub url={editUrl} />
6154
</DocumentationLayout>
6255
);
6356
}

src/app/blog/[slug]/page.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { optimizeExcerptToMetaDescription } from '@/lib/utils';
1313
import { buildMetadata } from '@/lib/utils/build-metadata';
1414
import { Newsletter } from '@/components/modules/newsletter';
1515
import { NEWSLETTER_URLS } from '@/components/modules/newsletter/newsletter.values';
16+
import { EditOnGithub } from '@/components/elements/edit-on-github';
1617

1718
type BlogPostPageProps = {
1819
params: { slug: string };
@@ -54,10 +55,13 @@ export async function generateStaticParams() {
5455
}));
5556
}
5657

58+
const githubBlogUrl = 'https://github.com/httptoolkit/httptoolkit-website/blob/main/src/content/posts';
59+
5760
export default async function BlogPostPage({ params }: BlogPostPageProps) {
5861
const { slug } = params;
5962
const post = await getPostBySlug(slug);
6063
const postNavigation = await getBlogTitlesBySlug(slug);
64+
const editUrl = `${githubBlogUrl}/${slug}.mdx`;
6165

6266
return (
6367
<>
@@ -69,9 +73,10 @@ export default async function BlogPostPage({ params }: BlogPostPageProps) {
6973
$bgVariant="darkGrey"
7074
links={[postNavigation]}
7175
parsedContent={post.content}
72-
additionalContent={
76+
additionalContent={<>
77+
<EditOnGithub url={editUrl} />
7378
<SocialPostShare postTitle={post.title} postUrl={post.slug} socialLinks={post.socialLinks} />
74-
}
79+
</>}
7580
/>
7681

7782
<Container>

src/app/(documentation)/docs/docs.styles.ts renamed to src/components/elements/edit-on-github/index.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
import { styled } from '@/styles';
44

5-
export const EditOnGithub = styled.em`
5+
import { PencilSimple } from '@/components/elements/icon';
6+
import { Link } from '@/components/elements/link';
7+
8+
const EditText = styled.em`
69
margin-top: 20px;
710
display: flex;
811
align-items: center;
@@ -21,3 +24,10 @@ export const EditOnGithub = styled.em`
2124
}
2225
}
2326
`;
27+
28+
export const EditOnGithub = (props: { url: string }) => <EditText>
29+
<PencilSimple /> Edit this page
30+
<Link href={props.url} target="_blank">
31+
on GitHub
32+
</Link>
33+
</EditText>

0 commit comments

Comments
 (0)