From a6ee20a83695c4dc5acd2abd081d5eb1ba38d3ea Mon Sep 17 00:00:00 2001 From: xnought Date: Mon, 27 Nov 2023 20:51:47 -0800 Subject: [PATCH 01/19] feat: add bibtex parser --- frontend/package.json | 1 + .../routes/protein/[proteinName]/+page.svelte | 24 ++++++++++++++++++- frontend/yarn.lock | 5 ++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/frontend/package.json b/frontend/package.json index 6ef311e6..72df7fa1 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -37,6 +37,7 @@ }, "type": "module", "dependencies": { + "bibtex": "^0.9.0", "marked": "^10.0.0" } } diff --git a/frontend/src/routes/protein/[proteinName]/+page.svelte b/frontend/src/routes/protein/[proteinName]/+page.svelte index 9e86727a..5ad4e0ca 100644 --- a/frontend/src/routes/protein/[proteinName]/+page.svelte +++ b/frontend/src/routes/protein/[proteinName]/+page.svelte @@ -8,6 +8,18 @@ import { humanReadableProteinName, numberWithCommas } from "$lib/format"; import { goto } from "$app/navigation"; + import { parseBibFile, normalizeFieldValue } from "bibtex"; + + const testBib = String.raw`@article{bertucci2022dendromap, + title={{\textbf{\large\texttt{DendroMap}}: Visual Exploration of Large-Scale Image Datasets for Machine Learning with Treemaps}}, + author={\textbf{Bertucci}, \textbf{Donald} and Hamid, Md Montaser and Anand, Yashwanthi and Ruangrotsakun, Anita and Tabatabai, Delyar and Perez, Melissa and Kahng, Minsuk}, + journal={IEEE Transactions on Visualization and Computer Graphics}, + year={2022}, + publisher={IEEE}, + doi={10.1109/TVCG.2022.3209425} +}`; + + const bib = parseBibFile(testBib); export let data; // linked to +page.ts return (aka the id) let entry: ProteinEntry | null = null; let error = false; @@ -93,7 +105,17 @@ {#if entry.content !== null} {:else} - No article added + No article, edit to add one + {/if} + + + + + References + {#if bib.entries_raw.length > 0} + References + {:else} + No references, edit to add some {/if} diff --git a/frontend/yarn.lock b/frontend/yarn.lock index d0365960..60385c12 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -477,6 +477,11 @@ balanced-match@^1.0.0: resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== +bibtex@^0.9.0: + version "0.9.0" + resolved "https://registry.yarnpkg.com/bibtex/-/bibtex-0.9.0.tgz#62126692c8cc897e6d3824dc5948b0bce13b050e" + integrity sha512-2YsG89+ZtFD04Dd+KDDUxjtEdiQMW4lbGsXzs5sa+nCpmOrauyChkOAdbLegVSAH2JKEfgu7SFESIVRKQCfD9Q== + binary-extensions@^2.0.0: version "2.2.0" resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d" From a8a73963d653f2708a73ec0a12b62849c9d9516e Mon Sep 17 00:00:00 2001 From: xnought Date: Mon, 27 Nov 2023 21:35:20 -0800 Subject: [PATCH 02/19] feat: successfully parse the bibtex and display it --- .../routes/protein/[proteinName]/+page.svelte | 63 +++++++++++++++++-- 1 file changed, 57 insertions(+), 6 deletions(-) diff --git a/frontend/src/routes/protein/[proteinName]/+page.svelte b/frontend/src/routes/protein/[proteinName]/+page.svelte index 5ad4e0ca..c1600f36 100644 --- a/frontend/src/routes/protein/[proteinName]/+page.svelte +++ b/frontend/src/routes/protein/[proteinName]/+page.svelte @@ -8,18 +8,28 @@ import { humanReadableProteinName, numberWithCommas } from "$lib/format"; import { goto } from "$app/navigation"; - import { parseBibFile, normalizeFieldValue } from "bibtex"; + import { parseBibFile, normalizeFieldValue, BibEntry } from "bibtex"; const testBib = String.raw`@article{bertucci2022dendromap, - title={{\textbf{\large\texttt{DendroMap}}: Visual Exploration of Large-Scale Image Datasets for Machine Learning with Treemaps}}, - author={\textbf{Bertucci}, \textbf{Donald} and Hamid, Md Montaser and Anand, Yashwanthi and Ruangrotsakun, Anita and Tabatabai, Delyar and Perez, Melissa and Kahng, Minsuk}, + title={DendroMap: Visual Exploration of Large-Scale Image Datasets for Machine Learning with Treemaps}, + author={Bertucci, Donald and Hamid, Md Montaser and Anand, Yashwanthi and Ruangrotsakun, Anita and Tabatabai, Delyar and Perez, Melissa and Kahng, Minsuk}, journal={IEEE Transactions on Visualization and Computer Graphics}, year={2022}, publisher={IEEE}, - doi={10.1109/TVCG.2022.3209425} + doi={10.1109/TVCG.2022.3209425}} + + @misc{silverthorne_2020, + title={A guide to rust programming language}, + url={https://about.gitlab.com/blog/2020/07/21/rust-programming-language/}, + journal={GitLab}, + author={Silverthorne, Valerie}, + year={2020}, + month={Jul} }`; const bib = parseBibFile(testBib); + console.log(bib.entries_raw); + export let data; // linked to +page.ts return (aka the id) let entry: ProteinEntry | null = null; let error = false; @@ -42,6 +52,21 @@ function pdbFileURL(name: string) { return `http://localhost:8000/data/pdbAlphaFold/${name}.pdb`; } + + /** + * @returns string of authors + */ + function parseAuthors(entry: BibEntry) { + const authors = entry.getFieldAsString("author") as string; + const parsed = authors.split(" and ").map((author) => + author + .split(",") + .map((d) => d.trim()) + .reverse() + .join(" ") + ); + return new Intl.ListFormat("en").format(parsed); + }
@@ -110,10 +135,36 @@ - + References {#if bib.entries_raw.length > 0} - References + {#each bib.entries_raw as entry, i} +
+
+ [{i + 1}] +
+
+ {#if entry.getFieldAsString("url")} + + + {entry.getFieldAsString("title")} + + + {:else} + + {entry.getFieldAsString("title")} + + {/if} +

{parseAuthors(entry)}

+ {#if entry.getFieldAsString("journal")} + + {entry.getFieldAsString("journal")} + {entry.getFieldAsString("year")} + + {/if} +
+
+ {/each} {:else} No references, edit to add some {/if} From a9240c52cb6d1d84dc83aed02d83b4364a630116 Mon Sep 17 00:00:00 2001 From: xnought Date: Mon, 27 Nov 2023 21:45:27 -0800 Subject: [PATCH 03/19] refac: move the references to separate component --- frontend/src/lib/References.svelte | 55 +++++++++++++++++++ .../routes/protein/[proteinName]/+page.svelte | 54 +----------------- 2 files changed, 58 insertions(+), 51 deletions(-) create mode 100644 frontend/src/lib/References.svelte diff --git a/frontend/src/lib/References.svelte b/frontend/src/lib/References.svelte new file mode 100644 index 00000000..ece21ac8 --- /dev/null +++ b/frontend/src/lib/References.svelte @@ -0,0 +1,55 @@ + + +{#if bib.entries_raw.length > 0} + {#each bib.entries_raw as entry, i} +
+
+ [{i + 1}] +
+
+
+ {#if entry.getFieldAsString("url")} + + + {entry.getFieldAsString("title")} + + + {:else} + + {entry.getFieldAsString("title")} + + {/if} +
+ +

{parseAuthors(entry)}

+ {#if entry.getFieldAsString("journal")} + + {entry.getFieldAsString("journal")} + {entry.getFieldAsString("year")} + + {/if} +
+
+ {/each} +{/if} diff --git a/frontend/src/routes/protein/[proteinName]/+page.svelte b/frontend/src/routes/protein/[proteinName]/+page.svelte index c1600f36..0dd9e31a 100644 --- a/frontend/src/routes/protein/[proteinName]/+page.svelte +++ b/frontend/src/routes/protein/[proteinName]/+page.svelte @@ -7,8 +7,7 @@ import { Heading, P, Span } from "flowbite-svelte"; import { humanReadableProteinName, numberWithCommas } from "$lib/format"; import { goto } from "$app/navigation"; - - import { parseBibFile, normalizeFieldValue, BibEntry } from "bibtex"; + import References from "$lib/References.svelte"; const testBib = String.raw`@article{bertucci2022dendromap, title={DendroMap: Visual Exploration of Large-Scale Image Datasets for Machine Learning with Treemaps}, @@ -27,9 +26,6 @@ month={Jul} }`; - const bib = parseBibFile(testBib); - console.log(bib.entries_raw); - export let data; // linked to +page.ts return (aka the id) let entry: ProteinEntry | null = null; let error = false; @@ -52,21 +48,6 @@ function pdbFileURL(name: string) { return `http://localhost:8000/data/pdbAlphaFold/${name}.pdb`; } - - /** - * @returns string of authors - */ - function parseAuthors(entry: BibEntry) { - const authors = entry.getFieldAsString("author") as string; - const parsed = authors.split(" and ").map((author) => - author - .split(",") - .map((d) => d.trim()) - .reverse() - .join(" ") - ); - return new Intl.ListFormat("en").format(parsed); - }
@@ -137,37 +118,7 @@ References - {#if bib.entries_raw.length > 0} - {#each bib.entries_raw as entry, i} -
-
- [{i + 1}] -
-
- {#if entry.getFieldAsString("url")} - - - {entry.getFieldAsString("title")} - - - {:else} - - {entry.getFieldAsString("title")} - - {/if} -

{parseAuthors(entry)}

- {#if entry.getFieldAsString("journal")} - - {entry.getFieldAsString("journal")} - {entry.getFieldAsString("year")} - - {/if} -
-
- {/each} - {:else} - No references, edit to add some - {/if} +
@@ -189,6 +140,7 @@