forked from LuaLS/LuaLS.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExternalLink.astro
65 lines (57 loc) · 1.47 KB
/
ExternalLink.astro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
---
import Tooltip from "./Tooltip.astro";
const {
url,
newTab = true,
class: className,
refer = false,
icon = true,
} = Astro.props;
const hostname = new URL(url).hostname;
let child = await Astro.slots.render("default");
child = child.trim();
export interface Props {
/** The url to link to */
url: string;
/** Whether the linked page should be opened in another tab. Defaults to `true`. */
newTab?: boolean;
/** Whether to [refer](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer) when navigating away. Defaults to `false`. */
refer?: boolean;
/** Whether or not to display the "external" icon next to the link. Defaults to `false`. */
icon?: boolean;
/** Allows you to pass in a class to be applied to the link. */
class?: string;
}
const classes = [className, "external"];
if (icon === false) {
classes.push("no-icon");
}
const relationships = ["noopener", "nofollow"];
if (!refer) {
relationships.push("noreferrer");
}
---
<Tooltip content={hostname}>
<a
href={url}
target={newTab ? "_blank" : null}
rel={relationships.join(" ")}
class={classes.join(" ")}
set:html={child}
/>
</Tooltip>
<style lang="scss">
a.external {
color: var(--link-color);
font-weight: 500;
white-space: normal;
}
a.external:not(.no-icon)::after {
content: "\f08e";
vertical-align: text-top;
font-family: "Font Awesome 6 Free";
font-size: 0.5em;
display: inline-block;
padding-left: 0.2em;
}
</style>