Skip to content

Commit 0cb4f39

Browse files
committed
chore: just throw on invalid site
1 parent bf7126a commit 0cb4f39

2 files changed

Lines changed: 9 additions & 15 deletions

File tree

packages/doom/src/runtime/components/ExternalSiteLink.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isProduction, useLang, useSite } from '@rspress/core/runtime'
1+
import { useLang, useSite } from '@rspress/core/runtime'
22
import {
33
addTrailingSlash,
44
isExternalUrl,
@@ -14,8 +14,6 @@ import { type AnchorHTMLAttributes, type ReactNode, useMemo } from 'react'
1414
import { isUnversioned } from '../../shared/helpers.js'
1515
import { useIsPrint } from '../hooks/index.js'
1616

17-
import { Directive } from './Directive.js'
18-
1917
export interface ExternalSiteLinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
2018
name: string
2119
children: ReactNode
@@ -38,15 +36,13 @@ const ExternalSiteLink_ = ({
3836
const lang = useLang()
3937

4038
if (!site) {
41-
const message = `No site with name \`${name}\` found, please ensure it's already defined at \`sites.yaml\``
42-
if (isProduction()) {
43-
throw new Error(message)
44-
}
45-
return <Directive type="danger">{message}</Directive>
39+
throw new Error(
40+
`No site with name \`${name}\` found, please ensure it's already defined at \`sites.yaml\``,
41+
)
4642
}
4743

4844
if (isExternalUrl(href)) {
49-
return <Directive type="danger">Invalid href `{href}` found</Directive>
45+
throw new Error(`Invalid href \`${href}\` found`)
5046
}
5147

5248
let { url, hash } = parseUrl(href)

packages/doom/src/runtime/components/_ExternalSiteBase.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isProduction, useLang } from '@rspress/core/runtime'
1+
import { useLang } from '@rspress/core/runtime'
22
import virtual from 'doom-@global-virtual'
33
import { type FC, useMemo } from 'react'
44

@@ -107,11 +107,9 @@ export const ExternalSiteBase = ({ name, template }: ExternalSiteBaseProps) => {
107107
)
108108

109109
if (!site) {
110-
const message = `No site with name \`${name}\` found, please ensure it's already defined at \`sites.yaml\``
111-
if (isProduction()) {
112-
throw new Error(message)
113-
}
114-
return <Directive type="danger">{message}</Directive>
110+
throw new Error(
111+
`No site with name \`${name}\` found, please ensure it's already defined at \`sites.yaml\``,
112+
)
115113
}
116114

117115
const Notes = template === 'apisOverview' ? ApisOverviewNotes : SiteNotes

0 commit comments

Comments
 (0)