@nekm/svelte-core 1.6.1 → 1.6.3

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,15 +1,33 @@
1
1
  <script lang="ts">
2
2
  import type {Snippet} from "svelte";
3
+ import {page} from "$app/state";
3
4
 
4
5
  export interface ExternalLinkProps {
5
6
  readonly href: string;
6
7
  readonly children: Snippet;
7
- readonly type?: "nofollow" | "ugc" | "sponsored";
8
+ readonly type?: "dofollow" | "nofollow" | "ugc" | "sponsored";
9
+ readonly origin?: string;
8
10
  }
9
11
 
10
- const { href, children, type = "nofollow" }: ExternalLinkProps = $props();
12
+ const { href, children, type = "nofollow", origin }: ExternalLinkProps = $props();
13
+
14
+ const host = $derived.by(() => {
15
+ if (!origin) {
16
+ return page.url.host;
17
+ }
18
+
19
+ return origin.replace(/http(s)?:\/\//ig, "");
20
+ });
21
+
22
+ const hrefWithSource = $derived.by(() => {
23
+ const sign = href.includes("?") ? "&" : "?";
24
+ return href + sign + `utm_source=${encodeURIComponent(host)}`;
25
+ });
26
+
27
+ const rel = $derived(type === "dofollow" ? undefined : type);
11
28
  </script>
12
29
 
13
- <a {href} target="_blank" rel="{type} noreferrer noopener">
30
+ <a href={hrefWithSource}
31
+ target="_blank" rel="{rel} noreferrer noopener">
14
32
  {@render children()}
15
33
  </a>
@@ -2,7 +2,8 @@ import type { Snippet } from "svelte";
2
2
  export interface ExternalLinkProps {
3
3
  readonly href: string;
4
4
  readonly children: Snippet;
5
- readonly type?: "nofollow" | "ugc" | "sponsored";
5
+ readonly type?: "dofollow" | "nofollow" | "ugc" | "sponsored";
6
+ readonly origin?: string;
6
7
  }
7
8
  declare const ExternalLink: import("svelte").Component<ExternalLinkProps, {}, "">;
8
9
  type ExternalLink = ReturnType<typeof ExternalLink>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nekm/svelte-core",
3
3
  "description": "Code I find myself re-writing over-and-over, Svelte edition.",
4
- "version": "1.6.1",
4
+ "version": "1.6.3",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
7
7
  "build": "vite build && npm run prepack",