Skip to content
This repository was archived by the owner on Feb 15, 2024. It is now read-only.

Commit 55622aa

Browse files
authored
Fixed <a href> not updating (#19)
* Fixed `<a href>` not updating Closes #18 * Updated CHANGELOG.md
1 parent 1ef80ff commit 55622aa

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ This project tries to follow [SemVer 2.0.0](https://semver.org/).
2727
- Fixed links to open in new tab via `target="_blank"` instead of the invalid
2828
value `target="about:blank"`. (#17)
2929

30+
- Fixed compiler links in episode info not updating when switching episode. (#19)
31+
3032
- Fixed issue where `Ctrl` + left mouse button clicking a link did not open the
3133
link in a new tab. (#20)
3234

src/Link.svelte

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@
33
44
import { addWindowEventListener } from "./libs/util";
55
6-
export let link: LinkOrHref = null;
7-
export let href: string = linkHref(link);
8-
export let target: string = href.startsWith("?") ? undefined : "_blank";
6+
export let href: LinkOrHref = null;
7+
export let target: string = null;
98
export let download: boolean | undefined = undefined;
109
11-
$: label = linkLabel(link) ?? href;
10+
$: actualHref = linkHref(href);
11+
$: actualLabel = linkLabel(href) ?? actualHref;
12+
$: actualTarget =
13+
target ??
14+
(!actualHref || actualHref.startsWith("?") ? undefined : "_blank");
1215
1316
let search = window.location.search;
14-
$: isCurrent = href.startsWith("?") && search === href;
17+
$: isCurrent =
18+
actualHref && actualHref.startsWith("?") && search === actualHref;
1519
1620
function onclick(e: MouseEvent) {
17-
if (!e.ctrlKey && href.startsWith("?") && window.history?.pushState) {
21+
if (!e.ctrlKey && actualHref.startsWith("?") && window.history?.pushState) {
1822
e.preventDefault();
19-
window.history.pushState(null, href, href);
23+
window.history.pushState(null, actualHref, actualHref);
2024
window.dispatchEvent(new PopStateEvent("onpushstate", { state: null }));
2125
}
2226
}
@@ -31,9 +35,13 @@
3135
<svelte:window on:popstate={onstatechanged} />
3236

3337
{#if isCurrent}
34-
<span class="selected"><slot>{label}</slot></span>
38+
<span class="selected"><slot>{actualLabel}</slot></span>
3539
{:else}
36-
<a {href} {target} {download} on:click={onclick} referrerpolicy="no-referrer"
37-
><slot>{label}</slot></a
40+
<a
41+
href={actualHref}
42+
target={actualTarget}
43+
{download}
44+
referrerpolicy="no-referrer"
45+
on:click={onclick}><slot>{actualLabel}</slot></a
3846
>
3947
{/if}

src/sections/EpisodeSection.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@
3636
</p>
3737
<p>
3838
{#if currentEpisode.compilerLinks.length === 1}
39-
Compiler link: <Link link={currentEpisode.compilerLinks[0]} />
39+
Compiler link: <Link href={currentEpisode.compilerLinks[0]} />
4040
{:else}
4141
Compiler links:
4242
<ul>
43-
{#each currentEpisode.compilerLinks as link}
44-
<li><Link {link} /></li>
43+
{#each currentEpisode.compilerLinks as href}
44+
<li><Link {href} /></li>
4545
{/each}
4646
</ul>
4747
{/if}

0 commit comments

Comments
 (0)