@@ -3,21 +3,17 @@ export function fetchTexData(texFilePath, environmentName, fieldsList) {
33 xhr . open ( 'GET' , texFilePath , false ) ;
44 xhr . send ( null ) ;
55 if ( xhr . status === 200 ) {
6- // console.log('tex file loaded')
76 var jsonItems = [ ] ;
87 var file = xhr . responseText ;
98 const codeblocks = file . split ( new RegExp ( '\\\\begin{' + environmentName + '}' ) ) . map ( block => block . replace ( new RegExp ( '\\\\end{' + environmentName + '}' ) , '' ) . trim ( ) ) ;
109 codeblocks . shift ( ) ; // remove the first element of the array, which is empty
11- // add also the content of the \begin{firstenvironmentName} \end{firstenvironmentName} environment to codeblocks, if it exists
1210 if ( file . includes ( '\\begin{first' + environmentName + '}' ) ) {
1311 const codeblocks2 = file . split ( new RegExp ( '\\\\begin{first' + environmentName + '}' ) ) . map ( block => block . replace ( new RegExp ( '\\\\end{first' + environmentName + '}' ) , '' ) . trim ( ) ) ;
1412 codeblocks . push ( codeblocks2 [ 1 ] ) ;
1513 }
1614 for ( let block of codeblocks ) {
17- // Split the LaTeX code into lines
1815 const lines = block . split ( '\n' ) . map ( line => line . trim ( ) ) ;
1916
20- // Find the start and end line of the environmentName environment
2117 const startLine = lines . findIndex ( line => line === '\\begin{' + environmentName + '}' ) ;
2218 const endLine = lines . findIndex ( line => line === '\\end{' + environmentName + '}' ) ;
2319 const fieldsDict = { } ;
@@ -27,9 +23,7 @@ export function fetchTexData(texFilePath, environmentName, fieldsList) {
2723 fieldsDict [ fieldsList [ index ] ] = unescapedLine ;
2824 } ) ;
2925
30- // Create JSON object
3126 const item = fieldsDict ;
32- // Add the JSON object to the array
3327 jsonItems . push ( item ) ;
3428 }
3529 return jsonItems ;
@@ -38,63 +32,34 @@ export function fetchTexData(texFilePath, environmentName, fieldsList) {
3832 }
3933 }
4034
41- // export function fetch
4235
4336
4437
4538
4639export function getResearchItem ( path , researchItem ) {
47- // picks the research item from the tex file in the path
48- // and returns a dictionary with the fields
49-
50- // items usually have the following structure:
51- // @article {researchItem,
52- // year = {2022},
53- // title = {Quantitative John–Nirenberg inequalities at different scales},
54- // author = {Martínez-Perales, Javier C and Rela, Ezequiel and Rivera-Ríos, Israel P},
55- // journal = {Revista Matemática Complutense},
56- // issn = {1139-1138},
57- // doi = {10.1007/s13163-022-00427-0},
58- // abstract = {},
59- // pages = {1--35}
60- // }
61-
62-
63- // path: path to the tex file
64- // researchItem: name of the research item
65- // returns: dictionary with the fields
40+
6641 var xhr = new XMLHttpRequest ( ) ;
6742 xhr . open ( 'GET' , path , false ) ;
6843 xhr . send ( null ) ;
6944 if ( xhr . status === 200 ) {
70- // console.log('tex file loaded, getting research item')
7145 var file = xhr . responseText ;
7246 var listOfItems = file . split ( '@' )
73- // console.log('listOfItems', listOfItems)
74- // search for the item called researchItem
75- // console.log('researchItem', researchItem)
47+
7648 var selectedItem = listOfItems . filter ( item => item . includes ( String ( researchItem ) ) ) [ 0 ]
77- // console.log('selectedItem', selectedItem)
78- // get the fields, which are the elments, separated by commas, of the list, from the second element on
49+
7950 var fields = selectedItem . split ( '\n' )
80- // create the dictionary
8151 var items = { }
8252 items [ 'name' ] = researchItem
8353 for ( var field of fields ) {
84- // console.log('field', field)
8554 if ( field . includes ( '=' ) ) {
8655
87- // just catch = sign if it is not inside a curly bracket
88- // if (field.includes('{') && field.includes('}')){
89- // var equalSign = field.indexOf('=')
56+
9057 var key = field . split ( '=' ) [ 0 ] . toLowerCase ( ) . trim ( )
91- // console.log('key '+key)
92- // value is the union of the remaining elements of field.split('=')
58+
9359 var value = field . split ( '=' ) . slice ( 1 ) . join ( '=' ) . trim ( ) . replaceAll ( / \\ h r e f { ( [ ^ } ] * ) } { ( [ ^ } ] * ) } / g, '<a style="text-decoration: none; " href="$1" >$2</a>' ) . replace ( '},' , '}' ) ;
94- // var value = field.split('=')[1].trim().replace(' },',' }')
95- // console.log(['year', 'title', 'author', 'journal', 'volume', 'number'].includes(key.toString()))
60+
9661 if ( [ 'year' , 'title' , 'author' , 'journal' , 'volume' , 'number' ] . includes ( key . toString ( ) ) ) {
97- // console.log('value in list', value)
62+
9863 items [ key ] = value
9964 }
10065
@@ -115,19 +80,12 @@ export function fetchResearchItems(pathCVResearch,pathReferences) {
11580 xhr . open ( 'GET' , pathCVResearch , false ) ;
11681 xhr . send ( null ) ;
11782 if ( xhr . status === 200 ) {
118- // console.log('tex file loaded, getting research items')
11983 var file = xhr . responseText ;
120- // split into lines
12184 var lines = file . split ( '\n' ) . map ( line => line . trim ( ) )
122- // const lines = block.split('\n').map(line => line.trim());
123- // get the lines that start with \item \fullcite{, but not with %\item \fullcite{
12485 var listOfItems = lines . filter ( line => line . includes ( '\\item \\fullcite{' ) && ! line . includes ( '%\\item \\fullcite{' ) )
12586
126- // get the names of the items
12787 var listOfItemsNames = listOfItems . map ( item => item . split ( '{' ) [ 1 ] . split ( '}' ) [ 0 ] )
128- // get the items dictionaries
12988 for ( var item of listOfItemsNames ) {
130- // console.log('getting item ' + item)
13189 dictItems [ item ] = getResearchItem ( pathReferences , item )
13290 }
13391 return dictItems
@@ -142,7 +100,6 @@ export function fetchResearchItems(pathCVResearch,pathReferences) {
142100
143101export function fetchSpacedTex ( texPath ) {
144102
145- // fetches the tex file and returns a string with the spaces between the words
146103
147104 var xhr = new XMLHttpRequest ( ) ;
148105 xhr . open ( 'GET' , texPath , false ) ;
@@ -152,15 +109,12 @@ export function fetchSpacedTex(texPath) {
152109 var file = xhr . responseText ;
153110 console . log ( 'tex file loaded, getting spaced tex' , file )
154111
155- // split by \spaced
156112 var spaced = file . split ( '\\spaced' )
157- // removes the \, which is present in the last member of the above list
158113 spaced = spaced . map ( item => item . replaceAll ( '\\LaTeX' , 'LaTeX' ) )
159114 spaced [ spaced . length - 1 ] = spaced [ spaced . length - 1 ] . split ( '\\,' ) [ 0 ]
160115 spaced = spaced . map ( item => ' ' + item . trim ( ) )
161116
162117 console . log ( 'spaced' , spaced )
163- // for all items, replace \LaTeX by LaTeX
164118
165119
166120 return spaced
0 commit comments