diff --git a/components/text.js b/components/text.js
index 42593575..d6dd4a7c 100644
--- a/components/text.js
+++ b/components/text.js
@@ -186,6 +186,7 @@ export default memo(function Text ({ rel, imgproxyUrls, children, tab, itemId, o
} catch {
// ignore invalid URLs
}
+
const internalURL = process.env.NEXT_PUBLIC_URL
if (!!text && !/^https?:\/\//.test(text)) {
if (props['data-footnote-ref'] || typeof props['data-footnote-backref'] !== 'undefined') {
@@ -210,6 +211,19 @@ export default memo(function Text ({ rel, imgproxyUrls, children, tab, itemId, o
)
} else if (href.startsWith('/') || url?.origin === internalURL) {
+ try {
+ const linkText = parseInternalLinks(href)
+ if (linkText) {
+ return (
+
+ {text}
+
+ )
+ }
+ } catch {
+ // ignore errors like invalid URLs
+ }
+
return (
!!part)
+ return page === 'items' && /^[0-9]+$/.test(id)
+}
+
export function parseInternalLinks (href) {
const url = new URL(href)
const internalURL = process.env.NEXT_PUBLIC_URL
const { pathname, searchParams } = url
+
// ignore empty parts which exist due to pathname starting with '/'
- const emptyPart = part => !!part
- const parts = pathname.split('/').filter(emptyPart)
- if (parts[0] === 'items' && /^[0-9]+$/.test(parts[1]) && url.origin === internalURL) {
+ if (isItemPath(pathname) && url.origin === internalURL) {
+ const parts = pathname.split('/').filter(part => !!part)
const itemId = parts[1]
// check for valid item page due to referral links like /items/123456/r/ekzyis
const itemPages = ['edit', 'ots', 'related']