Skip to content

Commit

Permalink
Show twohop links
Browse files Browse the repository at this point in the history
  • Loading branch information
mottox2 committed Nov 29, 2022
1 parent a4a6653 commit fd42679
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ type StoreValue = {
links: string[];
backLinks: string[];
newLinks: string[];
twoHopLinks: Record<string, string[]>
}

const store = writable<StoreValue>({
noActiveFile: true,
links: [],
backLinks: [],
newLinks: [],
twoHopLinks: {},
});

export default store
26 changes: 25 additions & 1 deletion src/ui/Pane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import LinkIcon from "./LinkIcon.svelte"
import NewLinkIcon from "./NewLinkIcon.svelte"
export let openLink: (event: MouseEvent, link: string) => void;
export let openLink: (event: MouseEvent, link: string) => void
const extractExt = (name: string) => name.replace(/.md$/, "")
</script>
Expand Down Expand Up @@ -54,6 +54,30 @@
<div class="search-empty-state">No back links found.</div>
{/if}
</div>
{#each Object.keys($store.twoHopLinks) as file}
{@const links = $store.twoHopLinks[file]}
{#if links.length > 0}
{@const title = file.replace(/.md$/, "") || ""}
<div class="tree-item-self">
<div class="tree-item-inner">{title}</div>
<div class="tree-item-flair-counter">
<div class="tree-item-flair">{links.length}</div>
</div>
</div>
<div class="search-result-container">
{#each links as link}
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div
class="tree-item-self search-result-file-title is-clickable"
on:click={(e) => openLink(e, link)}
>
<LinkIcon />
{extractExt(link)}
</div>
{/each}
</div>
{/if}
{/each}
<div class="tree-item-self">
<div class="tree-item-inner">New Links</div>
<div class="tree-item-flair-counter">
Expand Down
2 changes: 2 additions & 0 deletions src/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class RelationView extends ItemView {
links: [],
newLinks: [],
backLinks: [],
twoHopLinks: {},
})
return
}
Expand Down Expand Up @@ -95,6 +96,7 @@ export class RelationView extends ItemView {
links,
newLinks,
backLinks,
twoHopLinks,
})
}
}

0 comments on commit fd42679

Please sign in to comment.