@alauda/doom 0.15.6 → 0.15.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { NoSSR, useLang } from '@rspress/core/runtime';
|
|
3
|
-
import { addTrailingSlash, isExternalUrl, removeLeadingSlash, } from '@rspress/shared';
|
|
3
|
+
import { addTrailingSlash, isExternalUrl, normalizeHref, parseUrl, removeLeadingSlash, } from '@rspress/shared';
|
|
4
|
+
import { DEFAULT_PAGE_EXTENSIONS } from '@rspress/shared/constants';
|
|
4
5
|
import { clsx } from 'clsx';
|
|
5
6
|
import virtual from 'doom-@global-virtual';
|
|
6
7
|
import { useMemo } from 'react';
|
|
@@ -17,13 +18,21 @@ const ExternalSiteLink_ = ({ name, href = '', className, ...props }) => {
|
|
|
17
18
|
if (isExternalUrl(href)) {
|
|
18
19
|
return _jsxs(Directive, { type: "danger", children: ["Invalid href `", href, "` found"] });
|
|
19
20
|
}
|
|
21
|
+
let { url, hash } = parseUrl(href);
|
|
22
|
+
const extname = url.split('.').pop();
|
|
23
|
+
if (extname) {
|
|
24
|
+
if (DEFAULT_PAGE_EXTENSIONS.includes(`.${extname}`)) {
|
|
25
|
+
url = url.replace(new RegExp(`\\.${extname}$`), '');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
url = removeLeadingSlash(normalizeHref(url));
|
|
20
29
|
return (_jsx("a", { href: (isPrint ? 'https://docs.alauda.io' : '') +
|
|
21
30
|
(virtual.prefix || '') +
|
|
22
31
|
(virtual.version
|
|
23
32
|
? addTrailingSlash(site.base + site.version)
|
|
24
33
|
: site.base) +
|
|
25
34
|
(lang ? addTrailingSlash(lang) : '') +
|
|
26
|
-
|
|
35
|
+
(hash ? `${url}#${hash}` : url), target: "_blank", rel: "noopener noreferrer", className: clsx(classes.link, 'cursor-pointer', className), ...props }));
|
|
27
36
|
};
|
|
28
37
|
export const ExternalSiteLink = (props) => (_jsx(NoSSR, { children: _jsx(ExternalSiteLink_, { ...props }) }));
|
|
29
38
|
export default ExternalSiteLink;
|
package/package.json
CHANGED
package/styles/link.module.scss
CHANGED
|
@@ -9,6 +9,17 @@
|
|
|
9
9
|
&:active {
|
|
10
10
|
opacity: 0.7;
|
|
11
11
|
}
|
|
12
|
+
|
|
13
|
+
&[target='_blank']:after {
|
|
14
|
+
content: '↗';
|
|
15
|
+
margin-left: 0.2em;
|
|
16
|
+
margin-right: 0.1em;
|
|
17
|
+
font-size: 0.7em;
|
|
18
|
+
font-weight: 700;
|
|
19
|
+
transition: transform 0.2s;
|
|
20
|
+
display: inline-block;
|
|
21
|
+
transform: translate(0, -0.3em);
|
|
22
|
+
}
|
|
12
23
|
}
|
|
13
24
|
|
|
14
25
|
.link,
|