@@ -7,11 +7,13 @@ import Icons from 'uikit/dist/js/uikit-icons';
7
7
import Mustache from 'mustache' ;
8
8
import NotionClient from './notion.js' ;
9
9
import thenChrome from 'then-chrome' ;
10
+ import urlParser from './parsers.js' ;
10
11
11
12
UIKit . use ( Icons ) ;
12
13
13
14
const TEST_URL = 'https://arxiv.org/abs/2308.04079' ;
14
- const ARXIV_API = 'http://export.arxiv.org/api/query/search_query' ;
15
+ // const TEST_URL = 'https://aclanthology.org/2023.ijcnlp-main.1/';
16
+
15
17
class UI {
16
18
constructor ( ) {
17
19
this . setupProgressBar ( ) ;
@@ -97,13 +99,11 @@ class UI {
97
99
return url && url . split ( '.' ) . pop ( ) === 'pdf' ;
98
100
}
99
101
async getPaperInfo ( url ) {
100
- if ( this . isArxivUrl ( url ) ) return this . getArXivInfo ( url ) ;
101
- if ( this . isOpenReviewUrl ( url ) ) return this . getOpenReviewInfo ( url ) ;
102
+ this . showProgressBar ( ) ;
103
+ const data = await urlParser . parse ( url ) ;
104
+ this . setFormContents ( data . title , data . abst , data . comment , data . authors ) ;
105
+ return data ;
102
106
}
103
- // ref: https://info.arxiv.org/help/arxiv_identifier.html
104
- // e.g. (new id format: 2404.16782) | (old id format: hep-th/0702063)
105
- parseArXivId = ( str ) => str . match ( / ( \d + \. \d + $ ) | ( ( \w | - ) + \/ \d + $ ) / ) ?. [ 0 ] ;
106
-
107
107
setFormContents ( paperTitle , abst , comment , authors ) {
108
108
document . getElementById ( 'js-title' ) . value = paperTitle ;
109
109
document . getElementById ( 'js-abst' ) . value = abst ;
@@ -118,87 +118,6 @@ class UI {
118
118
} ) ;
119
119
}
120
120
121
- async getArXivInfo ( url ) {
122
- this . showProgressBar ( ) ;
123
- const paperId = this . parseArXivId ( url ) ;
124
-
125
- const res = await fetch ( ARXIV_API + '?id_list=' + paperId . toString ( ) ) ;
126
- if ( res . status != 200 ) {
127
- console . error ( 'arXiv API request failed' ) ;
128
- return ;
129
- }
130
- const data = await res . text ( ) ; // TODO: error handling
131
- console . log ( res . status ) ;
132
- const xmlData = new window . DOMParser ( ) . parseFromString ( data , 'text/xml' ) ;
133
- console . log ( xmlData ) ;
134
-
135
- const entry = xmlData . querySelector ( 'entry' ) ;
136
- const id = this . parseArXivId ( entry . querySelector ( 'id' ) ?. textContent ) ;
137
- const paperTitle = entry . querySelector ( 'title' ) . textContent ;
138
- const abst = entry . querySelector ( 'summary' ) . textContent ;
139
- const authors = Array . from ( entry . querySelectorAll ( 'author' ) ) . map (
140
- ( author ) => {
141
- return author . textContent . trim ( ) ;
142
- }
143
- ) ;
144
- const published = entry . querySelector ( 'published' ) . textContent ;
145
- const comment = entry . querySelector ( 'comment' ) ?. textContent ?? 'none' ;
146
- this . setFormContents ( paperTitle , abst , comment , authors ) ;
147
- return {
148
- id : id ,
149
- title : paperTitle ,
150
- abst : abst ,
151
- authors : authors ,
152
- url : url ,
153
- published : published ,
154
- comment : comment ,
155
- publisher : 'arXiv' ,
156
- } ;
157
- }
158
-
159
- async getOpenReviewInfo ( url ) {
160
- this . showProgressBar ( ) ;
161
- const id = new URLSearchParams ( new URL ( url ) . search ) . get ( 'id' ) ;
162
-
163
- const res = await fetch ( url ) ;
164
- const html = await res . text ( ) ;
165
- const parser = new DOMParser ( ) ;
166
- const xml = parser . parseFromString ( html , 'text/html' ) ;
167
-
168
- const authorsArray = Array . from (
169
- xml . querySelectorAll ( 'meta[name="citation_author"]' ) ,
170
- ( author ) => author . getAttribute ( 'content' )
171
- ) ;
172
- const authors = authorsArray . length ? authorsArray : [ 'Anonymous' ] ;
173
-
174
- const paperTitle = xml
175
- . querySelector ( 'meta[name="citation_title"]' )
176
- . getAttribute ( 'content' ) ;
177
-
178
- const abst = xml
179
- . querySelector ( 'meta[name="citation_abstract"]' )
180
- . getAttribute ( 'content' ) ;
181
-
182
- const date = xml
183
- . querySelector ( 'meta[name="citation_publication_date"]' )
184
- . getAttribute ( 'content' ) ;
185
- // -> ISO 8601 date string
186
- const published = new Date ( date ) . toISOString ( ) . split ( 'T' ) [ 0 ] ;
187
- const comment = 'none' ;
188
-
189
- this . setFormContents ( paperTitle , abst , comment , authors ) ;
190
- return {
191
- id : id ,
192
- title : paperTitle ,
193
- abst : abst ,
194
- authors : authors ,
195
- url : url ,
196
- published : published ,
197
- comment : comment ,
198
- publisher : 'OpenReview' ,
199
- } ;
200
- }
201
-
202
121
renderMessage ( type , message , overwrite = false ) {
203
122
// type: warning, danger, success, primary
204
123
const template = `<div class="uk-alert-{{type}}" uk-alert><a class="uk-alert-close" uk-close></a><p>{{message}}</p></div>` ;
0 commit comments