diff --git a/src/components/PageMetadata.tsx b/src/components/PageMetadata.tsx index 5bcc4232872..a129284a584 100644 --- a/src/components/PageMetadata.tsx +++ b/src/components/PageMetadata.tsx @@ -44,9 +44,14 @@ const PageMetadata: React.FC = ({ const path = asPath.replace(/[\?\#].*/, "") const slug = path.split("/") - /* Set canonical URL w/ language path to avoid duplicate content */ - /* e.g. set ethereum.org/about/ to ethereum.org/en/about/ */ - const url = new URL(join(locale === DEFAULT_LOCALE ? "" : locale!, path), SITE_URL).href + /** + * Set canonical URL w/ language path to avoid duplicate content + * If English, remove language path + * Remove trailing slash + * @example ethereum.org/about/ -> ethereum.org/about + * @example ethereum.org/pt-br/web3/ -> ethereum.org/pt-br/web3 + */ + const url = new URL(join(locale === DEFAULT_LOCALE ? "" : locale!, path), SITE_URL).href.replace(/\/$/, "") const canonical = canonicalUrl || url /* Set fallback ogImage based on path */ diff --git a/src/layouts/Docs.tsx b/src/layouts/Docs.tsx index 856a95e354d..e7968c0a4c8 100644 --- a/src/layouts/Docs.tsx +++ b/src/layouts/Docs.tsx @@ -47,8 +47,10 @@ import TableOfContents from "@/components/TableOfContents" import Translation from "@/components/Translation" import YouTube from "@/components/YouTube" +import { getEditPath } from "@/lib/utils/editPath" + // Utils -import { DEFAULT_LOCALE, EDIT_CONTENT_URL } from "@/lib/constants" +import { DEFAULT_LOCALE } from "@/lib/constants" import { useClientSideGitHubLastEdit } from "@/hooks/useClientSideGitHubLastEdit" @@ -220,7 +222,7 @@ export const DocsLayout = ({ }: DocsLayoutProps) => { const isPageIncomplete = !!frontmatter.incomplete const { asPath: relativePath } = useRouter() - const absoluteEditPath = `${EDIT_CONTENT_URL}${relativePath}` + const absoluteEditPath = getEditPath(relativePath) const gitHubLastEdit = useClientSideGitHubLastEdit(relativePath) const intlLastEdit = "data" in gitHubLastEdit ? gitHubLastEdit.data! : "" diff --git a/src/layouts/Static.tsx b/src/layouts/Static.tsx index bb8899afa67..4c51b4e460e 100644 --- a/src/layouts/Static.tsx +++ b/src/layouts/Static.tsx @@ -30,11 +30,10 @@ import Translation from "@/components/Translation" import TranslationChartImage from "@/components/TranslationChartImage" import UpcomingEventsList from "@/components/UpcomingEventsList" +import { getEditPath } from "@/lib/utils/editPath" import { getLocaleTimestamp } from "@/lib/utils/time" import { isLangRightToLeft } from "@/lib/utils/translations" -import { CONTENT_DIR } from "@/lib/constants" - import GuideHeroImage from "@/public/heroes/guides-hub-hero.jpg" const Heading1 = (props: HeadingProps) => ( @@ -91,10 +90,7 @@ export const StaticLayout: React.FC = ({ }) => { const { locale } = useRouter() - const repo = - process.env.NEXT_PUBLIC_GITHUB_REPO || "ethereum/ethereum-org-website" - const baseEditPath = `https://github.com/${repo}/tree/dev/${CONTENT_DIR}/` - const absoluteEditPath = baseEditPath + slug + "index.md" + const absoluteEditPath = getEditPath(slug) return ( diff --git a/src/layouts/Tutorial.tsx b/src/layouts/Tutorial.tsx index 4860123746b..26e90177bdb 100644 --- a/src/layouts/Tutorial.tsx +++ b/src/layouts/Tutorial.tsx @@ -35,13 +35,14 @@ import { Heading4 as MdHeading4, } from "@/components/MdComponents" import MdLink from "@/components/MdLink" -import PageMetadata from "@/components/PageMetadata" import { mdxTableComponents } from "@/components/Table" import TableOfContents from "@/components/TableOfContents" import TutorialMetadata from "@/components/TutorialMetadata" import YouTube from "@/components/YouTube" -import { DEFAULT_LOCALE, EDIT_CONTENT_URL } from "@/lib/constants" +import { getEditPath } from "@/lib/utils/editPath" + +import { DEFAULT_LOCALE } from "@/lib/constants" import { useClientSideGitHubLastEdit } from "@/hooks/useClientSideGitHubLastEdit" @@ -180,7 +181,8 @@ export const TutorialLayout = ({ crowdinContributors, }: TutorialLayoutProps) => { const { asPath: relativePath } = useRouter() - const absoluteEditPath = `${EDIT_CONTENT_URL}${relativePath}` + const absoluteEditPath = getEditPath(relativePath) + const borderColor = useToken("colors", "border") const postMergeBannerTranslationString = frontmatter.postMergeBannerTranslation as TranslationKey | null diff --git a/src/layouts/UseCases.tsx b/src/layouts/UseCases.tsx index be56127aaf8..0a07da5b081 100644 --- a/src/layouts/UseCases.tsx +++ b/src/layouts/UseCases.tsx @@ -30,9 +30,10 @@ import { } from "@/components/MdComponents" import TableOfContents from "@/components/TableOfContents" +import { getEditPath } from "@/lib/utils/editPath" import { getSummaryPoints } from "@/lib/utils/getSummaryPoints" -import { EDIT_CONTENT_URL, MAIN_CONTENT_ID } from "@/lib/constants" +import { MAIN_CONTENT_ID } from "@/lib/constants" const HeroContainer = (props: ChildOnlyProp) => ( = ({ const summaryPoints = getSummaryPoints(frontmatter) - const absoluteEditPath = `${EDIT_CONTENT_URL}${relativePath}` + const absoluteEditPath = getEditPath(relativePath) // Assign hero styling, default to "defi" let useCase = "defi" diff --git a/src/lib/utils/editPath.ts b/src/lib/utils/editPath.ts new file mode 100644 index 00000000000..95cbb91cedd --- /dev/null +++ b/src/lib/utils/editPath.ts @@ -0,0 +1,5 @@ +import { join } from 'path' + +import { CONTENT_DIR, EDIT_CONTENT_URL } from '@/lib/constants' + +export const getEditPath = (relativePath: string): string => join(EDIT_CONTENT_URL, CONTENT_DIR, relativePath, "index.md")