Skip to content

Commit 8620c4c

Browse files
committed
Add base & head links to file header for GH diffs
closes #26 closes #29
1 parent f4cd5cd commit 8620c4c

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

web/src/lib/components/diff/concise-diff-view.svelte.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ import type { IRawThemeSetting } from "shiki/textmate";
1515
import chroma from "chroma-js";
1616
import { getEffectiveGlobalTheme } from "$lib/theme.svelte";
1717
import { onDestroy } from "svelte";
18-
19-
export const DEFAULT_THEME_LIGHT: BundledTheme = "github-light-default";
20-
export const DEFAULT_THEME_DARK: BundledTheme = "github-dark-default";
18+
import { DEFAULT_THEME_LIGHT } from "$lib/global-options.svelte";
2119

2220
export type DiffViewerPatch = {
2321
hunks: DiffViewerPatchHunk[];

web/src/lib/global-options.svelte.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { DEFAULT_THEME_DARK, DEFAULT_THEME_LIGHT } from "$lib/components/diff/concise-diff-view.svelte";
21
import type { BundledTheme } from "shiki";
32
import { browser } from "$app/environment";
43
import { getEffectiveGlobalTheme } from "$lib/theme.svelte";
54
import { watchLocalStorage } from "$lib/util";
65
import { Context } from "runed";
76

7+
export const DEFAULT_THEME_LIGHT: BundledTheme = "github-light-default";
8+
export const DEFAULT_THEME_DARK: BundledTheme = "github-dark-default";
9+
810
export type SidebarLocation = "left" | "right";
911

1012
export class GlobalOptions {

web/src/routes/DiffTitle.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
<span class="iconify size-6 shrink-0 octicon--mark-github-24"></span>
1616
<h1 class="text-base">{details.owner}<span class="mx-1.5 font-light text-em-med">/</span>{details.repo}</h1>
1717
</div>
18-
<h2 class="text-sm text-em-med"><a href={details.backlink} target="_blank" class="hover:text-primary">{details.description}</a></h2>
18+
<h2 class="text-sm text-em-med">
19+
<a href={details.backlink} target="_blank" rel="noopener noreferrer" class="hover:text-primary">{details.description}</a>
20+
</h2>
1921
</div>
2022
{/snippet}
2123

web/src/routes/FileHeader.svelte

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@
3131
}
3232
3333
let patchHeaderDiffOnly = $derived(value.type === "text" && value.patchHeaderDiffOnly);
34+
35+
let { baseFileUrl, headFileUrl } = $derived.by(() => {
36+
if (viewer.diffMetadata?.type === "github") {
37+
const ghDetails = viewer.diffMetadata.details;
38+
return {
39+
baseFileUrl: `https://github.com/${ghDetails.owner}/${ghDetails.repo}/blob/${ghDetails.base}/${value.fromFile}`,
40+
headFileUrl: `https://github.com/${ghDetails.owner}/${ghDetails.repo}/blob/${ghDetails.head}/${value.toFile}`,
41+
};
42+
}
43+
return { baseFileUrl: undefined, headFileUrl: undefined };
44+
});
3445
</script>
3546

3647
{#snippet fileName()}
@@ -85,6 +96,12 @@
8596
}
8697
}
8798
/>
99+
{#if baseFileUrl}
100+
<Button.Root href={baseFileUrl} target="_blank" rel="noopener noreferrer" class="btn-ghost px-2 py-1">View file at base</Button.Root>
101+
{/if}
102+
{#if headFileUrl}
103+
<Button.Root href={headFileUrl} target="_blank" rel="noopener noreferrer" class="btn-ghost px-2 py-1">View file at head</Button.Root>
104+
{/if}
88105
<Popover.Arrow class="text-edge" />
89106
</Popover.Content>
90107
</Popover.Portal>

0 commit comments

Comments
 (0)