Skip to content

Commit

Permalink
fix lib/References.svelte mixing authors and titles on page reloads
Browse files Browse the repository at this point in the history
sync references.yaml with Zotero collection
  • Loading branch information
janosh committed Jul 27, 2023
1 parent a549532 commit 3aad858
Show file tree
Hide file tree
Showing 2 changed files with 680 additions and 26 deletions.
50 changes: 26 additions & 24 deletions site/src/lib/References.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,40 @@
import type { Reference } from '.'
export let references: Reference[]
export let ref_selector: string = `a[href^='#']`
export let ref_selector: string = `a.ref[href^='#']`
export let found_on_page: Reference[] = references
function filter_refs() {
const ref_links = document.querySelectorAll<HTMLAnchorElement>(ref_selector)
const hrefs = Array.from(ref_links).map((ref) => ref.hash)
found_on_page = references.filter((ref) => hrefs.includes(`#${ref.id}`))
const hashes = Array.from(ref_links).map((ref) => ref.hash)
found_on_page = references.filter((ref) => hashes.includes(`#${ref.id}`))
}
beforeUpdate(filter_refs)
</script>

<ol>
{#each found_on_page as { title, id, author, DOI, URL, issued }}
<li>
<strong {id}>{title}</strong>
<span>
{@html author.map((a) => `${a.given} ${a.family}`).join(`, &thinsp; `)}
</span>
&mdash;
<small>
{#if DOI}
DOI: <a href="https://doi.org/{DOI}">{DOI}</a>
{:else if URL}
preprint: <a href={URL}>{URL}</a>
{/if}
{#if issued}
&mdash; {issued[0].year}
{/if}
</small>
</li>
{/each}
</ol>
{#key found_on_page}
<ol>
{#each found_on_page as { title, id, author, DOI, URL: href, issued } (id)}
<li>
<strong {id}>{title}</strong>
<span>
{@html author.map((a) => `${a.given} ${a.family}`).join(`, &thinsp; `)}
</span>
&mdash;
<small>
{#if DOI}
DOI: <a href="https://doi.org/{DOI}">{DOI}</a>
{:else if href}
preprint: <a {href}>{href}</a>
{/if}
{#if issued}
&mdash; {issued[0].year}
{/if}
</small>
</li>
{/each}
</ol>
{/key}

<style>
ol > li {
Expand Down
Loading

0 comments on commit 3aad858

Please sign in to comment.