Skip to content

Commit 22d6537

Browse files
authored
Merge pull request #11964 from ethereum/edit-path-staging
Fix: Edit path for markdown files
2 parents 8cce4a0 + 0f7c9d6 commit 22d6537

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

src/layouts/Docs.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ import TableOfContents from "@/components/TableOfContents"
4747
import Translation from "@/components/Translation"
4848
import YouTube from "@/components/YouTube"
4949

50+
import { getEditPath } from "@/lib/utils/editPath"
51+
5052
// Utils
51-
import { DEFAULT_LOCALE, EDIT_CONTENT_URL } from "@/lib/constants"
53+
import { DEFAULT_LOCALE } from "@/lib/constants"
5254

5355
import { useClientSideGitHubLastEdit } from "@/hooks/useClientSideGitHubLastEdit"
5456

@@ -220,7 +222,7 @@ export const DocsLayout = ({
220222
}: DocsLayoutProps) => {
221223
const isPageIncomplete = !!frontmatter.incomplete
222224
const { asPath: relativePath } = useRouter()
223-
const absoluteEditPath = `${EDIT_CONTENT_URL}${relativePath}`
225+
const absoluteEditPath = getEditPath(relativePath)
224226

225227
const gitHubLastEdit = useClientSideGitHubLastEdit(relativePath)
226228
const intlLastEdit = "data" in gitHubLastEdit ? gitHubLastEdit.data! : ""

src/layouts/Static.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ import Translation from "@/components/Translation"
3030
import TranslationChartImage from "@/components/TranslationChartImage"
3131
import UpcomingEventsList from "@/components/UpcomingEventsList"
3232

33+
import { getEditPath } from "@/lib/utils/editPath"
3334
import { getLocaleTimestamp } from "@/lib/utils/time"
3435
import { isLangRightToLeft } from "@/lib/utils/translations"
3536

36-
import { CONTENT_DIR } from "@/lib/constants"
37-
3837
import GuideHeroImage from "@/public/heroes/guides-hub-hero.jpg"
3938

4039
const Heading1 = (props: HeadingProps) => (
@@ -91,10 +90,7 @@ export const StaticLayout: React.FC<IProps> = ({
9190
}) => {
9291
const { locale } = useRouter()
9392

94-
const repo =
95-
process.env.NEXT_PUBLIC_GITHUB_REPO || "ethereum/ethereum-org-website"
96-
const baseEditPath = `https://github.com/${repo}/tree/dev/${CONTENT_DIR}/`
97-
const absoluteEditPath = baseEditPath + slug + "index.md"
93+
const absoluteEditPath = getEditPath(slug)
9894

9995
return (
10096
<Box w="full">

src/layouts/Tutorial.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ import {
3535
Heading4 as MdHeading4,
3636
} from "@/components/MdComponents"
3737
import MdLink from "@/components/MdLink"
38-
import PageMetadata from "@/components/PageMetadata"
3938
import { mdxTableComponents } from "@/components/Table"
4039
import TableOfContents from "@/components/TableOfContents"
4140
import TutorialMetadata from "@/components/TutorialMetadata"
4241
import YouTube from "@/components/YouTube"
4342

44-
import { DEFAULT_LOCALE, EDIT_CONTENT_URL } from "@/lib/constants"
43+
import { getEditPath } from "@/lib/utils/editPath"
44+
45+
import { DEFAULT_LOCALE } from "@/lib/constants"
4546

4647
import { useClientSideGitHubLastEdit } from "@/hooks/useClientSideGitHubLastEdit"
4748

@@ -180,7 +181,8 @@ export const TutorialLayout = ({
180181
crowdinContributors,
181182
}: TutorialLayoutProps) => {
182183
const { asPath: relativePath } = useRouter()
183-
const absoluteEditPath = `${EDIT_CONTENT_URL}${relativePath}`
184+
const absoluteEditPath = getEditPath(relativePath)
185+
184186
const borderColor = useToken("colors", "border")
185187
const postMergeBannerTranslationString =
186188
frontmatter.postMergeBannerTranslation as TranslationKey | null

src/layouts/UseCases.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ import {
3030
} from "@/components/MdComponents"
3131
import TableOfContents from "@/components/TableOfContents"
3232

33+
import { getEditPath } from "@/lib/utils/editPath"
3334
import { getSummaryPoints } from "@/lib/utils/getSummaryPoints"
3435

35-
import { EDIT_CONTENT_URL, MAIN_CONTENT_ID } from "@/lib/constants"
36+
import { MAIN_CONTENT_ID } from "@/lib/constants"
3637

3738
const HeroContainer = (props: ChildOnlyProp) => (
3839
<Flex
@@ -94,7 +95,7 @@ export const UseCasesLayout: React.FC<IProps> = ({
9495

9596
const summaryPoints = getSummaryPoints(frontmatter)
9697

97-
const absoluteEditPath = `${EDIT_CONTENT_URL}${relativePath}`
98+
const absoluteEditPath = getEditPath(relativePath)
9899

99100
// Assign hero styling, default to "defi"
100101
let useCase = "defi"

src/lib/utils/editPath.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { join } from 'path'
2+
3+
import { CONTENT_DIR, EDIT_CONTENT_URL } from '@/lib/constants'
4+
5+
export const getEditPath = (relativePath: string): string => join(EDIT_CONTENT_URL, CONTENT_DIR, relativePath, "index.md")

0 commit comments

Comments
 (0)