Skip to content

Commit 1a1ab4b

Browse files
committed
fix links for static internal files
1 parent de5fdd4 commit 1a1ab4b

File tree

5 files changed

+17
-31
lines changed

5 files changed

+17
-31
lines changed

src/components/AssetDownload/index.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,12 @@ const AssetDownload = ({
5656
)}
5757
</div>
5858
<Flex className="mt-4 gap-5">
59-
<ButtonLink
60-
href={imgSrc}
61-
onClick={matomoHandler}
62-
target="_blank"
63-
locale={false}
64-
>
59+
<ButtonLink href={imgSrc} onClick={matomoHandler} target="_blank">
6560
{t("page-assets-download-download")} (
6661
{extname(imgSrc).slice(1).toUpperCase()})
6762
</ButtonLink>
6863
{svgUrl && (
69-
<ButtonLink
70-
href={svgUrl}
71-
onClick={matomoHandler}
72-
target="_blank"
73-
locale={false}
74-
>
64+
<ButtonLink href={svgUrl} onClick={matomoHandler} target="_blank">
7565
{t("page-assets-download-download")} (SVG)
7666
</ButtonLink>
7767
)}

src/components/MarkdownImage.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { extname } from "path"
22

3+
import NextLink from "next/link"
4+
35
import { Image, type ImageProps } from "@/components/Image"
46

57
import { toPosixPath } from "@/lib/utils/relativePath"
68

79
import { CONTENT_IMAGES_MAX_WIDTH } from "@/lib/constants"
810

9-
import InlineLink from "./ui/Link"
10-
1111
interface MarkdownImageProps extends Omit<ImageProps, "width" | "height"> {
1212
width: string
1313
height: string
@@ -42,12 +42,7 @@ const MarkdownImage = ({
4242
// display the wrapper as a `span` to avoid dom nesting warnings as mdx
4343
// sometimes wraps images in `p` tags
4444
<span className="flex justify-center">
45-
<InlineLink
46-
href={transformedSrc}
47-
target="_blank"
48-
rel="noopener"
49-
locale={false}
50-
>
45+
<NextLink href={transformedSrc} target="_blank" rel="noopener">
5146
<Image
5247
alt={alt}
5348
width={imageWidth}
@@ -58,7 +53,7 @@ const MarkdownImage = ({
5853
className="h-auto"
5954
{...rest}
6055
/>
61-
</InlineLink>
56+
</NextLink>
6257
</span>
6358
)
6459
}

src/components/ui/Link.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AnchorHTMLAttributes, forwardRef } from "react"
1+
import { AnchorHTMLAttributes, ComponentProps, forwardRef } from "react"
22
import NextLink from "next/link"
33
import { RxExternalLink } from "react-icons/rx"
44
import { VisuallyHidden } from "@radix-ui/react-visually-hidden"
@@ -23,7 +23,7 @@ type BaseProps = {
2323

2424
export type LinkProps = BaseProps &
2525
AnchorHTMLAttributes<HTMLAnchorElement> &
26-
Omit<typeof I18nLink, "href">
26+
Omit<ComponentProps<typeof I18nLink>, "href">
2727

2828
/**
2929
* Link wrapper which handles:
@@ -60,14 +60,14 @@ export const BaseLink = forwardRef<HTMLAnchorElement, LinkProps>(function Link(
6060

6161
const isActive = url.isHrefActive(href, pathname, isPartiallyActive)
6262
const isDiscordInvite = url.isDiscordInvite(href)
63-
const isPdf = url.isPdf(href)
63+
const isFile = url.isFile(href)
6464
const isExternal = url.isExternal(href)
65-
const isInternalPdf = isPdf && !isExternal
65+
const isInternalFile = isFile && !isExternal
6666
const isHash = url.isHash(href)
6767

68-
// Get proper download link for internally hosted PDF's & static files (ex: whitepaper)
68+
// Get proper download link for internally hosted files (ex: whitepaper.pdf)
6969
// Opens in separate window.
70-
if (isInternalPdf) {
70+
if (isInternalFile && !href.startsWith("/")) {
7171
href = "/" + getRelativePath(pathname, href)
7272
}
7373

@@ -113,7 +113,7 @@ export const BaseLink = forwardRef<HTMLAnchorElement, LinkProps>(function Link(
113113
)
114114
}
115115

116-
if (isInternalPdf) {
116+
if (isInternalFile) {
117117
return (
118118
<NextLink
119119
target="_blank"

src/lib/utils/url.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { join } from "path"
1+
import { extname, join } from "path"
22

33
import {
44
DEFAULT_LOCALE,
@@ -21,6 +21,8 @@ export const isGlossary = (href: string): boolean =>
2121

2222
export const isPdf = (href: string): boolean => href.endsWith(".pdf")
2323

24+
export const isFile = (href: string): boolean => extname(href).length > 0
25+
2426
export const sanitizeHitUrl = (url: string): string =>
2527
url
2628
.replace(/^https?:\/\/[^/]+(?=\/)/, "")

src/pages/[locale]/assets.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ export const getStaticProps = (async ({ params }) => {
132132
const AssetsPage = () => {
133133
// Ignore locale in the URL for SVG path in public directory to fix broken link
134134
// SVG path changes from /en/images => /images
135-
const svgPathFromOrigin =
136-
typeof window !== `undefined` ? window.location.origin : ""
135+
const svgPathFromOrigin = ""
137136

138137
const { t } = useTranslation("page-assets")
139138
const assetPageHeroImage = useColorModeValue(

0 commit comments

Comments
 (0)