Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alphaXiv arXiv Labs PR #655

Merged
merged 33 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ee8fed8
sanity check
rehaanahmad2013 Jun 29, 2024
7010796
test addition
rehaanahmad2013 Jun 29, 2024
65aac08
anotherp ush
rehaanahmad2013 Jun 29, 2024
ab03f1b
small test
rehaanahmad2013 Jun 29, 2024
b852c69
alphaXiv integrated
rehaanahmad2013 Jun 29, 2024
1ed1c8b
new labs
rehaanahmad2013 Jun 29, 2024
fb4da0f
trying again
rehaanahmad2013 Jun 29, 2024
eecc848
testagain
rehaanahmad2013 Jun 30, 2024
22cc5c9
prodalphaxiv
rehaanahmad2013 Jun 30, 2024
6fe8d46
nourl
rehaanahmad2013 Jun 30, 2024
2c5441f
fix explore url
rehaanahmad2013 Jun 30, 2024
6d6f9b9
small updates
rehaanahmad2013 Jul 1, 2024
ac5ab58
html cleanup
rehaanahmad2013 Jul 1, 2024
1d09951
fix error
rehaanahmad2013 Jul 1, 2024
c7ed090
different wording
rehaanahmad2013 Jul 4, 2024
981ff82
console log test
rehaanahmad2013 Jul 4, 2024
adc93f7
alphaxiv
rehaanahmad2013 Jul 5, 2024
1c30476
debug statement
rehaanahmad2013 Jul 5, 2024
46b89f0
include subject in id
rehaanahmad2013 Jul 5, 2024
928bc89
more console output
rehaanahmad2013 Jul 5, 2024
bfcd75d
const -> let
rehaanahmad2013 Jul 5, 2024
3f50f87
update debug
rehaanahmad2013 Jul 5, 2024
16131ba
more console
rehaanahmad2013 Jul 5, 2024
e374dfd
labs
rehaanahmad2013 Jul 6, 2024
fe143fb
debug statements
rehaanahmad2013 Jul 6, 2024
ed03e82
labs
rehaanahmad2013 Jul 6, 2024
7e04a3a
update poetry lock + new API url
rehaanahmad2013 Sep 11, 2024
5aea13d
matching poetry.lock reference value
rehaanahmad2013 Sep 11, 2024
69f37a9
Merge branch 'develop' into develop
rehaanahmad2013 Sep 11, 2024
5da97ab
Merge branch 'develop' into develop
rehaanahmad2013 Oct 14, 2024
b030245
Merge branch 'develop' into develop
rehaanahmad2013 Oct 14, 2024
7fb58c9
Merge branch 'develop' into develop
rehaanahmad2013 Oct 17, 2024
69be701
Merge branch 'develop' into develop
cbf66 Oct 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions browse/static/css/arXiv.css
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,16 @@ p.tagline {

/*END Gotit.pub CSS*/

/*BEGIN alphaXiv CSS*/
.alphaXiv-logo {
margin-left: 0pt;
font-weight: 500;
letter-spacing: normal;
line-height: 100%;
font-family: "EB Garamond", ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
}
/*END alphaXiv CSS*/

/*BEGIN Spaces CSS*/

.spaces-summary {
Expand Down
82 changes: 82 additions & 0 deletions browse/static/js/alphaxiv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
(function () {
const container = document.getElementById("alphaxiv-output")
const containerAlreadyHasContent = container.innerHTML.trim().length > 0

// This script is invoked every time the Labs toggle is toggled, even when
// it's toggled to disabled. So this check short-circuits the script if the
// container already has content.
if (containerAlreadyHasContent) {
container.innerHTML = ""
container.setAttribute("style", "display:none")
return
} else {
container.setAttribute("style", "display:block")
}

// Get the arXiv paper ID from the URL, e.g. "2103.17249"
const urlList = window.location.pathname.split('/').reverse()
let arxivPaperId = urlList[0]
if (!arxivPaperId) return

// include the hep-th, math, etc subject tag
if (urlList.length > 0 && urlList[1] != 'abs') {
arxivPaperId = (urlList[1] + "_") + arxivPaperId
}

let versionlessPaperId = arxivPaperId;
if (versionlessPaperId.includes("v")) {
versionlessPaperId = versionlessPaperId.substring(0, versionlessPaperId.indexOf("v"))
}

const alphaxivApi = `https://api.alphaxiv.org/v1/papers/getpaperinfo/${arxivPaperId}`
let alphaXivUrl = `https://alphaxiv.org/abs/${versionlessPaperId}`;


(async () => {
let response = await fetch(alphaxivApi);
if (!response.ok) {
console.error(`Unable to fetch data from ${alphaxivApi}`)
render(0, false);
return;
}
let result = await response.json();
if (result.returnVersion > 0) {
alphaXivUrl = alphaXivUrl + "v" + result.returnVersion;
render(result.numQuestions, result.hasClaimedAuthorship);
return;
}
render(0, false);
})()

// Generate HTML, sanitize it to prevent XSS, and inject into the DOM
function render(numComments, hasClaimedAuthorship) {
container.innerHTML = window.DOMPurify.sanitize(`
<h2 class="alphaxiv-logo">alphaXiv</h2>
${html(numComments, hasClaimedAuthorship)}
`, { ADD_ATTR: ['target'] })
}

function html(numComments, hasClaimedAuthorship) {
let resultStr = ""
if (numComments == 0) {
resultStr += `<h3 class="alphaxiv-summary">Comment directly on top of arXiv papers</h3>
<p> No comments yet for this paper. View recent comments <a href="https://alphaxiv.org/explore" target="_blank">on other papers here</a>.</p>`
} else if (numComments == 1) {
resultStr += `<h3 class="alphaxiv-summary">There is 1 comment on this paper</h3>
<p> View comments on <a href="${alphaXivUrl}" target="_blank">alphaXiv</a> and add your own!</p>`
} else {
resultStr += `<h3 class="alpahxiv-summary">There are ${numComments} comments for this paper on alphaXiv</h3>
<p> View comments on <a href="${alphaXivUrl}" target="_blank">alphaXiv</a>.</p>`
}
if (hasClaimedAuthorship == true) {
resultStr += `<p> For this paper, the author is present on alphaXiv and will be notified of new comments.`
if (numComments == 0) {
resultStr += ` See <a href="${alphaXivUrl}" target="_blank">here</a>.</p>`
} else {
resultStr += `</p>`
}
}

return resultStr
}
})();
13 changes: 13 additions & 0 deletions browse/static/js/toggle-labs.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ $(document).ready(function() {
"influenceflower": $('#influenceflower-toggle').data('script-url'),
"sciencecast": $('#sciencecast-toggle').data('script-url'),
"gotitpub": $('#gotitpub-toggle').data('script-url'),
"alphaxiv": $('#alphaxiv-toggle').data('script-url'),
"bibex": {
"url": "https://static.arxiv.org/js/bibex/bibex.js?20210223",
"container": "#bib-main"
Expand Down Expand Up @@ -120,6 +121,12 @@ $(document).ready(function() {
}).fail(function() {
console.error("failed to load gotitpub script (on cookie check)", arguments)
});
} else if (key === "alphaxiv-toggle") {
$.cachedScript(scripts["alphaxiv"]).done(function(script, textStatus) {
console.log(textStatus);
}).fail(function() {
console.error("failed to load alphaxiv script (on cookie check)", arguments)
});
}
}
}
Expand Down Expand Up @@ -222,6 +229,12 @@ $(document).ready(function() {
}).fail(function() {
console.error("failed to load gotitpub script (on lab toggle)", arguments)
});
} else if ($(this).attr("id") == "alphaxiv-toggle") {
$.cachedScript(scripts["alphaxiv"]).done(function(script, textStatus) {
console.log(textStatus, "alphaxiv (on lab toggle)");
}).fail(function() {
console.error("failed to load alphaxiv script (on lab toggle)", arguments)
});
}


Expand Down
17 changes: 17 additions & 0 deletions browse/templates/abs/labs_tabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ <h1>Bibliographic and Citation Tools</h1>
<div class="tab">
<h1>Code, Data and Media Associated with this Article</h1>
<div class="toggle">
<div class="columns is-mobile lab-row">
<div class="column lab-switch">
<label class="switch">
<input
id="alphaxiv-toggle"
data-script-url="{{ url_for('static', filename='js/alphaxiv.js') }}"
type="checkbox" class="lab-toggle" aria-labelledby="label-for-alphaxiv">
<span class="slider"></span>
<span class="is-sr-only">alphaXiv Toggle</span>
</label>
</div>
<div class="column lab-name">
<span id="label-for-alphaxiv">alphaXiv</span> <em>(<a href="https://alphaxiv.org/" target="_blank">What is alphaXiv?</a>)</em>
</div>
</div>

<div class="columns is-mobile lab-row">
<div class="column lab-switch">
<label class="switch">
Expand Down Expand Up @@ -162,6 +178,7 @@ <h1>Code, Data and Media Associated with this Article</h1>
</div>
</div>

<div id="alphaxiv-output" style="display:none"></div>
<div id="catalyzex-output" style="display:none"></div>
<div id="dagshub-output" style="display:none"></div>
<div id="gotitpub-output" style="display:none"></div>
Expand Down
Loading