-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
301 lines (243 loc) · 8.87 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<!DOCTYPE html>
<html lang="en" dir="ltr" prefix="og: http://ogp.me/ns#">
<head>
<meta charset="utf-8">
<title>CFF generator</title>
<meta name="description" content="Generate Citation File Format files for your GitHub repository">
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@citation_js">
<meta name="twitter:creator" content="@larswillighagen">
<meta name="og:url" content="https://citation.js.org/cff-generator">
<meta name="og:title" content="Citation File Format generator">
<meta name="og:description" content="Generate Citation File Format files for your GitHub repository">
<style media="screen">
body {
font-family: sans-serif;
margin: 0 auto;
max-width: 800px;
}
hr {
margin: 2em 0;
}
textarea {
width: 100%;
}
button, input, select {
padding: 0.5em;
margin: 0.5em 0;
}
pre {
white-space: pre-wrap;
}
input[name="message"] {
width: 50%;
}
output[name="input_error"] {
color: red;
}
#items:empty:before {
color: grey;
content: '(no items)';
font-style: italic;
}
li {
margin-bottom: 1em;
}
li details {
margin-top: 0.5em;
}
li a {
float: right;
}
#banner {
position: relative;
top: -3em;
}
</style>
</head>
<body>
<h1>Citation.js CFF generator</h1>
<p>
Generate
<a href="https://citation-file-format.github.io/">Citation File Format</a>
files
<a href="https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-citation-files">for your GitHub repository</a>.
</p>
<hr>
<form id="input">
<p>
<label for="Input">Add a DOI, an ISBN, a PubMed ID, BibTeX, RIS, a GitHub or npm URL.</label>
<textarea name="input" rows="10"></textarea>
<label for="input_type">Override input type:</label>
<select name="input_type"></select>
</p>
<p><output name="input_error"></output><p>
<button>Add</button>
</form>
<hr>
<ol id="items"></ol>
<hr>
<form id="configure">
<label for="message">
Message
(<a href="https://github.com/citation-file-format/citation-file-format/blob/main/README.md#message-required">docs<a>)
</label><br>
<input type="text" name="message" value="Please cite the following works when using this software."><br><br>
<label for="main">Select the main reference (should be software or dataset)</label><br>
<select name="main"></select><br><br>
<label for="preferred">Select the preferred citation</label><br>
<select name="preferred">
<option value="">—</option>
</select>
<br><br>
<button>Generate</button>
</form>
<hr>
<pre id="output">
</pre>
<form id="use">
<button>Copy</button>
</form>
<hr>
<h2>Built with Citation.js</h2>
<a href="https://citation.js.org">
<img id="banner" src="https://citation.js.org/static/img/banner.png" alt="Citation.js logo">
</a>
<script src="citation.js" charset="utf-8"></script>
<script type="text/javascript">
(function () {
const inputForm = document.getElementById('input')
const configureForm = document.getElementById('configure')
const useForm = document.getElementById('use')
const itemsList = document.getElementById('items')
const outputField = document.getElementById('output')
const c = require('citation-js')
let cite = new c.Cite()
// Add .zenodo.json-from-URL support
c.plugins.input.add('@github/zenodo.json', {
parseType: {
extends: '@github/url'
},
parseAsync (input) {
const [, user, repo] = input.match(/^https?:\/\/github.com\/([^/]+)\/([^/]+)/)
return c.util
.fetchFileAsync('https://raw.githubusercontent.com/' + user + '/' + repo + '/HEAD/.zenodo.json')
.catch(() => 'https://api.github.com/repos/' + user + '/' + repo)
}
})
// Populate format selection
const plugins = {}
for (const type of c.plugins.input.listTypeParser()) {
let [plugin, subtype] = type.split('/')
plugin = plugin.slice(1) // remove leading '@'
if (!plugins[plugin]) plugins[plugin] = []
plugins[plugin].push([subtype, type])
}
for (const plugin of Object.keys(plugins).sort()) {
const optgroup = document.createElement('optgroup')
optgroup.setAttribute('label', plugin)
for (const type of plugins[plugin].sort()) {
const option = document.createElement('option')
option.setAttribute('value', type[1])
option.textContent = type[1]
optgroup.appendChild(option)
}
inputForm.input_type.appendChild(optgroup)
}
// Add interactivity
inputForm.input.addEventListener('input', function () {
inputForm.input_type.value = c.plugins.input.type(this.value)
})
inputForm.input.dispatchEvent(new Event('input'))
inputForm.addEventListener('submit', function (e) {
e.preventDefault()
this.input_error.textContent = ''
cite.addAsync(this.input.value, {
forceType: inputForm.input_type.value,
generateGraph: false
})
.then(renderItems)
.catch(error => {
console.error(error)
this.input_error.textContent = error.message
})
})
configureForm.addEventListener('submit', function (e) {
e.preventDefault()
outputField.textContent = cite.format('cff', {
main: this.main.value,
preferred: this.preferred.value,
message: this.message.value
})
})
useForm.addEventListener('submit', function (e) {
e.preventDefault()
window.getSelection().selectAllChildren(outputField)
document.execCommand('copy')
})
// Render items
let renderedItems = {}
let renderedItemOptions = {}
function renderItems (cite) {
let index = 0
for (const entry of cite.data) {
index++
if (!renderedItems[entry.id]) {
const li = document.createElement('li')
li.textContent = renderSimpleCitation(entry)
const a = document.createElement('a')
a.textContent = 'remove'
a.setAttribute('href', '#')
a.addEventListener('click', function () {
const entryToRemove = entry.id
cite.data.splice(cite.data.findIndex(entry => entry.id === entryToRemove), 1)
renderedItems[entryToRemove].remove()
delete renderedItems[entryToRemove]
for (const option of renderedItemOptions[entryToRemove]) {
option.remove()
}
delete renderedItemOptions[entryToRemove]
})
li.prepend(a)
const detail = document.createElement('details')
const summary = document.createElement('summary')
summary.textContent = 'All metadata'
const pre = document.createElement('pre')
pre.textContent = JSON.stringify(entry, null, 2)
detail.appendChild(summary)
detail.appendChild(pre)
li.appendChild(detail)
renderedItems[entry.id] = li
itemsList.appendChild(renderedItems[entry.id])
}
if (!renderedItemOptions[entry.id]) {
const option = document.createElement('option')
option.textContent = index + '. ' + entry.title.slice(0, 30) + '...'
option.setAttribute('value', entry.id)
renderedItemOptions[entry.id] = [
option,
option.cloneNode(true)
]
configureForm.main.appendChild(renderedItemOptions[entry.id][0])
configureForm.preferred.appendChild(renderedItemOptions[entry.id][1])
}
}
}
function renderSimpleCitation (entry) {
[entry] = c.plugins.input.util.clean([entry])
let citation = []
if (entry.author) {
citation.push(c.plugins.output.format('ris', [entry], { format: 'object' })[0].AU.join('; '))
}
if (entry.issued) {
citation.push(entry.issued.raw || entry.issued['date-parts'][0][0])
}
if (entry.title) {
citation.push(entry.title)
}
return citation.join('. ')
}
})()
</script>
</body>
</html>