|
1 | 1 | <script lang="ts"> |
| 2 | + import { run } from "svelte/legacy"; |
| 3 | +
|
2 | 4 | import { ArrowRight } from "lucide-svelte"; |
3 | 5 | import { Button } from "$lib/components/ui/button"; |
| 6 | + type Props = { |
| 7 | + children?: import("svelte").Snippet; |
| 8 | + }; |
| 9 | +
|
| 10 | + let { children }: Props = $props(); |
4 | 11 |
|
5 | | - let data: HTMLLIElement | undefined = undefined; |
| 12 | + let data = $state<HTMLLIElement>(); |
6 | 13 | let pullsLinks: string[] = []; |
7 | 14 | let issuesLinks: string[] = []; |
8 | | - let allLinks: string[] = []; |
| 15 | + let allLinks = $state<string[]>([]); |
9 | 16 |
|
10 | | - $: if (data) { |
11 | | - const links = data.innerHTML.match(/https?:\/\/[^"]+/g) || []; |
12 | | - for (const link of links) { |
13 | | - if (link.includes("/pull/")) { |
14 | | - pullsLinks.push(link); |
15 | | - } else if (link.includes("/issues/")) { |
16 | | - issuesLinks.push(link); |
| 17 | + run(() => { |
| 18 | + if (data) { |
| 19 | + const links = data.innerHTML.match(/https?:\/\/[^"]+/g) || []; |
| 20 | + for (const link of links) { |
| 21 | + if (link.includes("/pull/")) { |
| 22 | + pullsLinks.push(link); |
| 23 | + } else if (link.includes("/issues/")) { |
| 24 | + issuesLinks.push(link); |
| 25 | + } |
17 | 26 | } |
| 27 | + allLinks = [...pullsLinks, ...issuesLinks]; |
18 | 28 | } |
19 | | - allLinks = [...pullsLinks, ...issuesLinks]; |
20 | | - } |
| 29 | + }); |
21 | 30 |
|
22 | 31 | /** |
23 | 32 | * Replaces a link with `https://github.com/username/repo/[pull|issues]/123` |
|
39 | 48 | class:font-semibold={data?.innerText.startsWith("breaking:")} |
40 | 49 | class="group *:inline" |
41 | 50 | > |
42 | | - <slot /> |
| 51 | + {@render children?.()} |
43 | 52 | {#if allLinks.length > 0} |
44 | 53 | <Button |
45 | 54 | href={ghLinkToHref(allLinks[0] ?? "")} |
|
0 commit comments