-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mark Ibrahim
committed
Feb 25, 2024
1 parent
ab2c4e9
commit b1dccff
Showing
21 changed files
with
3,821 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# npm | ||
node_modules | ||
|
||
# Don't include the compiled main.js file in the repo. | ||
# They should be uploaded to GitHub releases instead. | ||
main.js | ||
|
||
# Exclude sourcemaps | ||
*.map | ||
|
||
# obsidian | ||
data.json | ||
|
||
# Exclude macOS Finder (System Explorer) View States | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# top-most EditorConfig file | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = tab | ||
indent_size = 4 | ||
tab_width = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
npm node_modules | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"env": { "node": true }, | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"parserOptions": { | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"no-unused-vars": "off", | ||
"@typescript-eslint/no-unused-vars": ["error", { "args": "none" }], | ||
"@typescript-eslint/ban-ts-comment": "off", | ||
"no-prototype-builtins": "off", | ||
"@typescript-eslint/no-empty-function": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tag-version-prefix="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Download and create note for Arxiv Article | ||
|
||
Based on https://github.com/chauff/paper-note-filler/ | ||
|
||
|
||
1. `downloadarxiv.js` downloads and grabs article info | ||
2. `main.ts` creates note with info filled in | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// // Based on https://github.com/j3soon/arxiv-utils/blob/master/chrome/content.js | ||
|
||
// // Regular expressions for parsing arXiv IDs from URLs. | ||
// // Ref: https://info.arxiv.org/help/arxiv_identifier_for_services.html#urls-for-standard-arxiv-functions | ||
const ID_REGEXP_REPLACE = [ | ||
[/^.*:\/\/(?:export\.|browse\.)?arxiv\.org\/abs\/(\S*?)\/*(\?.*?)?(\#.*?)?$/, "$1", "Abstract"], | ||
[/^.*:\/\/(?:export\.|browse\.)?arxiv\.org\/pdf\/(\S*?)(?:\.pdf)?\/*(\?.*?)?(\#.*?)?$/, "$1", "PDF"], | ||
[/^.*:\/\/(?:export\.|browse\.)?arxiv\.org\/ftp\/(?:arxiv\/|([^\/]*\/))papers\/.*?([^\/]*?)\.pdf(\?.*?)?(\#.*?)?$/, "$1$2", "PDF"], | ||
[/^.*:\/\/ar5iv\.labs\.arxiv\.org\/html\/(\S*?)\/*(\?.*?)?(\#.*?)?$/, "$1", "HTML5"], | ||
]; | ||
var DOMParser = require('xmldom').DOMParser; | ||
const LOG_PREFIX = "[arXiv-utils]"; | ||
const path = require("path"); | ||
const download = require('download'); | ||
|
||
|
||
// // Return the id parsed from the url. | ||
function getId(url) { | ||
for (const [regexp, replacement, pageType] of ID_REGEXP_REPLACE) { | ||
if (regexp.test(url)) | ||
return url.replace(regexp, replacement); | ||
} | ||
return null; | ||
} | ||
// // Return the page type according to the URL. | ||
function getPageType(url) { | ||
for (const [regexp, replacement, pageType] of ID_REGEXP_REPLACE) { | ||
if (regexp.test(url)) | ||
return pageType; | ||
} | ||
return null; | ||
} | ||
// Get article information through arXiv API asynchronously. | ||
// Ref: https://info.arxiv.org/help/api/user-manual.html#31-calling-the-api | ||
async function parseArticleInfoAsync(id, pageType) { | ||
console.log(LOG_PREFIX, "Retrieving title through ArXiv API request..."); | ||
const response = await fetch(`https://export.arxiv.org/api/query?id_list=${id}`); | ||
if (!response.ok) { | ||
console.error(LOG_PREFIX, "Error: ArXiv API request failed."); | ||
return; | ||
} | ||
const xmlDoc = await response.text(); | ||
const parsedXML = new DOMParser().parseFromString(xmlDoc, 'text/xml'); | ||
const entry = parsedXML.getElementsByTagName("entry")[0]; | ||
// title[0] is query string, title[1] is paper name. | ||
const title = entry.getElementsByTagName("title")[0].textContent; | ||
// Long titles will be split into multiple lines, with all lines except the first one starting with two spaces. | ||
const escapedTitle = title.replace("\n", "").replace(" ", " ").replace(":", " -"); | ||
// TODO: May need to escape special characters in title? | ||
const newTitle = `${escapedTitle} | ${pageType}`; | ||
var authorElement = entry.getElementsByTagName("name"); | ||
const firstAuthor = authorElement[0].textContent; | ||
|
||
const authorsArray = []; | ||
let i = 0; | ||
while (i < authorElement.length) { | ||
authorsArray.push(authorElement[i].textContent); | ||
i++; | ||
|
||
}; | ||
const authors = authorsArray.join(", "); | ||
const publishedYear = entry.getElementsByTagName("published")[0].textContent.split('-')[0]; | ||
const updatedYear = entry.getElementsByTagName("updated")[0].textContent.split('-')[0]; | ||
return { | ||
escapedTitle, | ||
newTitle, | ||
firstAuthor, | ||
authors, | ||
publishedYear, | ||
updatedYear, | ||
} | ||
} | ||
|
||
|
||
export async function getArxivInfoAsync(url, downloadFolder = "/Users/markibrahim/Desktop/tmp/arxiv-test/") { | ||
console.log("Starting to run"); | ||
const id = getId(url); | ||
|
||
if (!id) { | ||
console.error("Error: Failed to get paper ID, aborted."); | ||
return; | ||
} | ||
const pageType = getPageType(url); | ||
|
||
// get article info | ||
var apiUrl = "http://export.arxiv.org/api/query?search_query=id:"; | ||
apiUrl = apiUrl + id; | ||
const articleInfo = await parseArticleInfoAsync(id, pageType); | ||
console.log("successfully found article info for " + articleInfo.escapedTitle); | ||
|
||
// download pdf | ||
const downloadUrl = "https://arxiv.org/pdf/" + id + ".pdf"; | ||
const downloadPath = path.join(downloadFolder, articleInfo.escapedTitle + " - " + articleInfo.publishedYear + ".pdf"); | ||
download(downloadUrl, downloadPath) | ||
.then(() => { | ||
console.log("successfully downloaded article to " + downloadPath); | ||
}) | ||
.catch(error => { | ||
if (error.code === 'EEXIST') { | ||
console.log("pdf found, skipping download."); | ||
} | ||
else { | ||
console.error("failed to download pdf"); | ||
console.error(error); | ||
} | ||
} | ||
) | ||
|
||
return [articleInfo.escapedTitle, articleInfo.authors, articleInfo.publishedYear]; | ||
|
||
} | ||
|
||
// Execute main logic. | ||
// getArxivInfoAsync("https://arxiv.org/abs/2305.04160"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import esbuild from "esbuild"; | ||
import process from "process"; | ||
import builtins from 'builtin-modules' | ||
|
||
const banner = | ||
`/* | ||
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD | ||
if you want to view the source, please visit the github repository of this plugin | ||
*/ | ||
`; | ||
|
||
const prod = (process.argv[2] === 'production'); | ||
|
||
esbuild.build({ | ||
banner: { | ||
js: banner, | ||
}, | ||
entryPoints: ['main.ts'], | ||
bundle: true, | ||
external: [ | ||
'obsidian', | ||
'electron', | ||
'@codemirror/autocomplete', | ||
'@codemirror/collab', | ||
'@codemirror/commands', | ||
'@codemirror/language', | ||
'@codemirror/lint', | ||
'@codemirror/search', | ||
'@codemirror/state', | ||
'@codemirror/view', | ||
'@lezer/common', | ||
'@lezer/highlight', | ||
'@lezer/lr', | ||
...builtins], | ||
format: 'cjs', | ||
watch: !prod, | ||
target: 'es2018', | ||
logLevel: "info", | ||
sourcemap: prod ? false : 'inline', | ||
treeShaking: true, | ||
outfile: 'main.js', | ||
}).catch(() => process.exit(1)); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.