-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
170 lines (150 loc) · 5.57 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<!DOCTYPE html>
<!--
# paper-entry-generator
# Generate HTML entries for the personal papers repository
#
# Author: Álvaro Galisteo (https://alvaro.galisteo.me)
# Copyright 2020 - GPLv3
-->
<html>
<head>
<title>Paper Entry Generator</title>
<style type="text/css">
html {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
.top .left {
display: inline-block;
width: 45%;
vertical-align: top;
}
.top .right {
display: inline-block;
width: 45%;
vertical-align: top;
}
#entries {
margin: 20px 0;
}
#form p {
display: inline-block;
width: 200px;
}
textarea {
width: 100%;
height: 300px;
}
</style>
</head>
<body>
<h1>Paper Entry Generator</h1>
<div class="top">
<div class="left">
<h2>Form</h2>
<form accept-charset="UTF-8" autocomplete="off" id="form">
<p>Paper name</p>
<input name="name" type="text" value="" required/><br />
<p>Authors<br>(comma separated)</p>
<input name="authors" type="text" value="" required/><br />
<p>Year</p>
<input name="year" type="number" value="" required/><br />
<p>Keywords<br>(comma separated)</p>
<input name="keywords" type="text" value="" required/><br />
<p>DOI (Optional)</p>
<input name="doi" type="text" value=""/><br />
</form>
<button type="submit" value="Submit" onclick="addEntry();">Add entry</button>
</div>
<div class="right">
<h2>Entries</h2>
<div id="entries"></div>
</div>
</div>
<h2>HTML Code</h2>
<textarea id="html" name="html"></textarea>
<script type="text/javascript">
var form = document.getElementById("form");
var entries = [];
function getForm(form) {
var object = {};
for (var i = 0; i < form.length; i++) {
object[form[i].name] = form[i].value;
}
return object;
}
function addEntry() {
var entry = getForm(form);
form.reset();
var id = entries.length;
entry.id = id;
entry.authors = entry.authors.split(",");
entry.keywords = entry.keywords.split(",");
entries.push(entry);
displayEntries();
}
function removeEntry(id) {
remove(1, entries);
displayEntries();
}
function remove(id, array) {
for (var i = 0; i < array.length; i++) {
if(array.id === id) {
array.splice(i, 1);
return;
}
}
}
function displayEntries() {
document.getElementById("entries").innerHTML = "";
document.getElementById("html").innerHTML = "";
for (var i = 0; i < entries.length; i++) {
var string = entries[i].name + " " + "<button onclick='removeEntry(" + entries[i].id + ")'>Remove entry</button>";
document.getElementById("entries").innerHTML += string + "<br />";
document.getElementById("html").innerHTML += generateEntry(entries[i]) + "\n";
}
}
/* Entry related functions */
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
function generateEntry(entry) {
var year = entry.year;
var authors = entry.authors.join(", ");
var keywords = entry.keywords;
for (var i = 0; i < keywords.length; i++) {
keywords[i] = capitalizeFirstLetter(keywords[i]);
}
keywords = keywords.join(", ");
var doi = entry.doi;
if (doi !== "") {
doi = "<br>\n DOI: " + doi + "<br>";
} else {
doi = "";
}
var name = entry.name;
var path =
year +
"-" +
authors.replace(/\,/g, "").replace(/\./g, "").replace(/\s/g, "-") +
"-" +
name.replace(/\:/g, "").replace(/\s/g, "_") +
".pdf";
var output =
"<p>\n" +
" <span style='font-size: 1.25em'><a href='%assets_url%/papers/" +
path +
"'>" +
name +
"</a></span><br>\n" +
" <span style='font-size: 1.15em'>" +
authors +
"</span><br>\n" +
" Keywords: " +
keywords +
doi +
"\n</p>";
return output;
}
</script>
</body>
</html>