mirror of
https://github.com/wassname/template.git
synced 2026-06-27 16:32:20 +08:00
Add bibtex-key to d-cite for framework compatability
This commit is contained in:
+1
-44
@@ -1,44 +1 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules
|
||||
bower_components
|
||||
jspm_packages
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# Copied fonts
|
||||
examples/fonts
|
||||
dist
|
||||
article-rendered.html
|
||||
|
||||
# dependency graph
|
||||
rollup-grapher.html
|
||||
.DS_Store
|
||||
|
||||
+119
-86
@@ -17,14 +17,14 @@
|
||||
|
||||
<head>
|
||||
<script src="../dist/template.v2.js"></script>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" >
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta charset="utf8">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<distill-header></distill-header>
|
||||
<d-front-matter>
|
||||
<script id='distill-front-matter' type="text/json">{
|
||||
<d-front-matter>
|
||||
<script id='distill-front-matter' type="text/json">{
|
||||
"title": "Why Momentum Really Works",
|
||||
"description": "Although \" extremely useful for visualizing high-dimensional data, t-SNE plots can sometimes be mysterious or misleading.",
|
||||
"published": "Jan 10, 2017",
|
||||
@@ -54,96 +54,129 @@
|
||||
]
|
||||
}
|
||||
}</script>
|
||||
</d-front-matter>
|
||||
<d-title>
|
||||
<figure style="grid-column: page; margin: 1rem 0;"><img src="momentum.png" style="width:100%; border: 1px solid rgba(0, 0, 0, 0.2);"/></figure>
|
||||
<p>We often think of Momentum<d-cite key="mercier2011humans"></d-cite> as a means of dampening oscillations and speeding up the iterations, leading to faster convergence. But it has other interesting behavior. It allows a larger range of step-sizes to be used, and creates its own oscillations. What is going on?</p>
|
||||
</d-title>
|
||||
<d-byline></d-byline>
|
||||
<d-article>
|
||||
<a class="marker" href="#section-1" id="section-1"><span>1</span></a>
|
||||
<h2>A Brief Survey of Techniques</h2>
|
||||
<p>Before diving in: if you haven’t encountered t-SNE before, here’s what you need to know about the math behind it. The goal is to take a set of points in a high-dimensional space and find a faithful representation of those points in a lower-dimensional space, typically the 2D plane. The algorithm is non-linear and adapts to the underlying data, performing different transformations on different regions. Those differences can be a major source of confusion.</p>
|
||||
<p>This is the first paragraph of the article. Test a long — dash -- here it is.</p>
|
||||
<p>Test for owner's possessive. Test for "quoting a passage." And another sentence. Or two. Some flopping fins; for diving.</p>
|
||||
<aside>Some text in an aside, margin notes, etc...</aside>
|
||||
<p>Here's a test of an inline equation <d-math>c = a^2 + b^2</d-math>. Also with configurable katex standards just using inline '$' signs: $$x^2$$ And then there's a block equation:</p>
|
||||
<d-math block>
|
||||
c = \pm \sqrt{ \sum_{i=0}^{n}{a^{222} + b^2}}
|
||||
</d-math>
|
||||
<p>Math can also be quite involved:</p>
|
||||
<d-math block>
|
||||
\frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} = 1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}} {1+\cdots} } } }
|
||||
</d-math>
|
||||
<a class="marker" href="#section-1.1" id="section-1.1"><span>1.1</span></a>
|
||||
<h3>Citations</h3>
|
||||
<p><d-slider style="width: 200px;"></d-slider></p>
|
||||
<p>We can<d-cite key="mercier2011humans"></d-cite> also cite <d-cite key="gregor2015draw,mercier2011humans,openai2018charter"></d-cite> external publications. <d-cite key="dong2014image,dumoulin2016guide,mordvintsev2015inceptionism"></d-cite>. We should also be testing footnotes<d-footnote>This will become a hoverable footnote. This will become a hoverable footnote. This will become a hoverable footnote. This will become a hoverable footnote. This will become a hoverable footnote. This will become a hoverable footnote. This will become a hoverable footnote. This will become a hoverable footnote.</d-footnote>. There are multiple footnotes, and they appear in the appendix<d-footnote>Given I have coded them right. Also, here's math in a footnote: <d-math>c = \sum_0^i{x}</d-math>. Also, a citation. Box-ception<d-cite key='gregor2015draw'></d-cite>!</d-footnote> as well.</p>
|
||||
<a class="marker" href="#section-2" id="section-2"><span>2</span></a>
|
||||
<h2>Displaying code snippets</h2>
|
||||
<p>Some inline javascript:<d-code language="javascript">var x = 25;</d-code>. And here's a javascript code block.</p>
|
||||
<d-code block language="javascript">
|
||||
</d-front-matter>
|
||||
<d-title>
|
||||
<figure style="grid-column: page; margin: 1rem 0;"><img src="momentum.png"
|
||||
style="width:100%; border: 1px solid rgba(0, 0, 0, 0.2);" /></figure>
|
||||
<p>We often think of Momentum<d-cite key="mercier2011humans"></d-cite> as a means of dampening oscillations and
|
||||
speeding up the iterations, leading to faster convergence. But it has other interesting behavior. It allows a
|
||||
larger range of step-sizes to be used, and creates its own oscillations. What is going on?</p>
|
||||
</d-title>
|
||||
<d-byline></d-byline>
|
||||
<d-article>
|
||||
<a class="marker" href="#section-1" id="section-1"><span>1</span></a>
|
||||
<h2>A Brief Survey of Techniques</h2>
|
||||
<p>Before diving in: if you haven’t encountered t-SNE before, here’s what you need to know about the math behind it.
|
||||
The goal is to take a set of points in a high-dimensional space and find a faithful representation of those points
|
||||
in a lower-dimensional space, typically the 2D plane. The algorithm is non-linear and adapts to the underlying
|
||||
data, performing different transformations on different regions. Those differences can be a major source of
|
||||
confusion.</p>
|
||||
<p>This is the first paragraph of the article. Test a long — dash -- here it is.</p>
|
||||
<p>Test for owner's possessive. Test for "quoting a passage." And another sentence. Or two. Some flopping fins; for
|
||||
diving.</p>
|
||||
<aside>Some text in an aside, margin notes, etc...</aside>
|
||||
<p>Here's a test of an inline equation <d-math>c = a^2 + b^2</d-math>. Also with configurable katex standards just
|
||||
using inline '$' signs: $$x^2$$ And then there's a block equation:</p>
|
||||
<d-math block>
|
||||
c = \pm \sqrt{ \sum_{i=0}^{n}{a^{222} + b^2}}
|
||||
</d-math>
|
||||
<p>Math can also be quite involved:</p>
|
||||
<d-math block>
|
||||
\frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} = 1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}}
|
||||
{1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}} {1+\cdots} } } }
|
||||
</d-math>
|
||||
<a class="marker" href="#section-1.1" id="section-1.1"><span>1.1</span></a>
|
||||
<h3>Citations</h3>
|
||||
<p>
|
||||
<d-slider style="width: 200px;"></d-slider>
|
||||
</p>
|
||||
<p>We can<d-cite bibtex-key="mercier2011humans"></d-cite> also cite <d-cite
|
||||
key="gregor2015draw,mercier2011humans,openai2018charter"></d-cite> external publications. <d-cite
|
||||
key="dong2014image,dumoulin2016guide,mordvintsev2015inceptionism"></d-cite>. We should also be testing footnotes
|
||||
<d-footnote>This will become a hoverable footnote. This will become a hoverable footnote. This will become a
|
||||
hoverable footnote. This will become a hoverable footnote. This will become a hoverable footnote. This will
|
||||
become a hoverable footnote. This will become a hoverable footnote. This will become a hoverable footnote.
|
||||
</d-footnote>. There are multiple footnotes, and they appear in the appendix<d-footnote>Given I have coded them
|
||||
right. Also, here's math in a footnote: <d-math>c = \sum_0^i{x}</d-math>. Also, a citation. Box-ception<d-cite
|
||||
key='gregor2015draw'></d-cite>!</d-footnote> as well.</p>
|
||||
<a class="marker" href="#section-2" id="section-2"><span>2</span></a>
|
||||
<h2>Displaying code snippets</h2>
|
||||
<p>Some inline javascript:<d-code language="javascript">var x = 25;</d-code>. And here's a javascript code block.
|
||||
</p>
|
||||
<d-code block language="javascript">
|
||||
var x = 25;
|
||||
function(x){
|
||||
return x * x;
|
||||
return x * x;
|
||||
}
|
||||
</d-code>
|
||||
<p>We also support python.</p>
|
||||
<d-code block language="python">
|
||||
# Python 3: Fibonacci series up to n
|
||||
def fib(n):
|
||||
</d-code>
|
||||
<p>We also support python.</p>
|
||||
<d-code block language="python">
|
||||
# Python 3: Fibonacci series up to n
|
||||
def fib(n):
|
||||
a, b = 0, 1
|
||||
while a < n:
|
||||
print(a, end=' ')
|
||||
a, b = b, a+b
|
||||
</d-code>
|
||||
<p>And a table</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr><th>First</th><th>Second</th><th>Third</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr><td>23</td><td>654</td><td>23</td></tr>
|
||||
<tr><td>14</td><td>54</td><td>34</td></tr>
|
||||
<tr><td>234</td><td>54</td><td>23</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<d-figure id="last-figure"></d-figure>
|
||||
<script>
|
||||
const figure = document.querySelector("d-figure#last-figure");
|
||||
const initTag = document.createElement("span");
|
||||
initTag.textContent = "initialized!"
|
||||
figure.appendChild(initTag);
|
||||
figure.addEventListener("ready", function() {
|
||||
const initTag = figure.querySelector("span");
|
||||
initTag.textContent = "ready"
|
||||
console.log('ready')
|
||||
});
|
||||
figure.addEventListener("onscreen", function() {
|
||||
const initTag = figure.querySelector("span");
|
||||
initTag.textContent = "onscreen"
|
||||
console.log('onscreen')
|
||||
});
|
||||
figure.addEventListener("offscreen", function() {
|
||||
const initTag = figure.querySelector("span");
|
||||
initTag.textContent = "offscreen!"
|
||||
console.log('offscreen')
|
||||
});
|
||||
</script>
|
||||
<p>That's it for the example article!</p>
|
||||
while a < n: print(a, end=' ' ) a, b=b, a+b </d-code> <p>And a table</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>First</th>
|
||||
<th>Second</th>
|
||||
<th>Third</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>23</td>
|
||||
<td>654</td>
|
||||
<td>23</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>14</td>
|
||||
<td>54</td>
|
||||
<td>34</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>234</td>
|
||||
<td>54</td>
|
||||
<td>23</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<d-figure id="last-figure"></d-figure>
|
||||
<script>
|
||||
const figure = document.querySelector("d-figure#last-figure");
|
||||
const initTag = document.createElement("span");
|
||||
initTag.textContent = "initialized!"
|
||||
figure.appendChild(initTag);
|
||||
figure.addEventListener("ready", function () {
|
||||
const initTag = figure.querySelector("span");
|
||||
initTag.textContent = "ready"
|
||||
console.log('ready')
|
||||
});
|
||||
figure.addEventListener("onscreen", function () {
|
||||
const initTag = figure.querySelector("span");
|
||||
initTag.textContent = "onscreen"
|
||||
console.log('onscreen')
|
||||
});
|
||||
figure.addEventListener("offscreen", function () {
|
||||
const initTag = figure.querySelector("span");
|
||||
initTag.textContent = "offscreen!"
|
||||
console.log('offscreen')
|
||||
});
|
||||
</script>
|
||||
<p>That's it for the example article!</p>
|
||||
|
||||
</d-article>
|
||||
</d-article>
|
||||
|
||||
<d-appendix>
|
||||
<d-appendix>
|
||||
|
||||
<h3>Contributions</h3>
|
||||
<p>Some text describing who did what.</p>
|
||||
<h3>Reviewers</h3>
|
||||
<p>Some text with links describing who reviewed the article.</p>
|
||||
<h3>Contributions</h3>
|
||||
<p>Some text describing who did what.</p>
|
||||
<h3>Reviewers</h3>
|
||||
<p>Some text with links describing who reviewed the article.</p>
|
||||
|
||||
<d-bibliography src="bibliography.bib"></d-bibliography>
|
||||
</d-appendix>
|
||||
<d-bibliography src="bibliography.bib"></d-bibliography>
|
||||
</d-appendix>
|
||||
|
||||
<distill-footer></distill-footer>
|
||||
<distill-footer></distill-footer>
|
||||
|
||||
</body>
|
||||
</body>
|
||||
+31
-27
@@ -12,10 +12,12 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { Template } from '../mixins/template';
|
||||
import { hover_cite, bibliography_cite } from '../helpers/citation';
|
||||
import { Template } from "../mixins/template";
|
||||
import { hover_cite, bibliography_cite } from "../helpers/citation";
|
||||
|
||||
const T = Template('d-cite', `
|
||||
const T = Template(
|
||||
"d-cite",
|
||||
`
|
||||
<style>
|
||||
|
||||
:host {
|
||||
@@ -69,10 +71,10 @@ ul li:last-of-type {
|
||||
<div id="citation-" class="citation">
|
||||
<span class="citation-number"></span>
|
||||
</div>
|
||||
`);
|
||||
`
|
||||
);
|
||||
|
||||
export class Cite extends T(HTMLElement) {
|
||||
|
||||
/* Lifecycle */
|
||||
constructor() {
|
||||
super();
|
||||
@@ -81,53 +83,53 @@ export class Cite extends T(HTMLElement) {
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
this.outerSpan = this.root.querySelector('#citation-');
|
||||
this.innerSpan = this.root.querySelector('.citation-number');
|
||||
this.hoverBox = this.root.querySelector('d-hover-box');
|
||||
window.customElements.whenDefined('d-hover-box').then(() => {
|
||||
this.outerSpan = this.root.querySelector("#citation-");
|
||||
this.innerSpan = this.root.querySelector(".citation-number");
|
||||
this.hoverBox = this.root.querySelector("d-hover-box");
|
||||
window.customElements.whenDefined("d-hover-box").then(() => {
|
||||
this.hoverBox.listen(this);
|
||||
});
|
||||
// in case this component got connected after values were set
|
||||
if (this.numbers) {
|
||||
this.displayNumbers(this.numbers)
|
||||
this.displayNumbers(this.numbers);
|
||||
}
|
||||
if (this.entries) {
|
||||
this.displayEntries(this.entries)
|
||||
this.displayEntries(this.entries);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO This causes an infinite loop on firefox with polyfills.
|
||||
// This is only needed for interactive editing so no priority.
|
||||
// disconnectedCallback() {
|
||||
// const options = { detail: [this, this.keys], bubbles: true };
|
||||
// const event = new CustomEvent('onCiteKeyRemoved', options);
|
||||
// document.dispatchEvent(event);
|
||||
// const options = { detail: [this, this.keys], bubbles: true };
|
||||
// const event = new CustomEvent('onCiteKeyRemoved', options);
|
||||
// document.dispatchEvent(event);
|
||||
// }
|
||||
|
||||
/* observe 'key' attribute */
|
||||
|
||||
static get observedAttributes() {
|
||||
return ['key'];
|
||||
return ["key", "bibtex-key"];
|
||||
}
|
||||
|
||||
attributeChangedCallback(name, oldValue, newValue) {
|
||||
const eventName = oldValue ? 'onCiteKeyChanged' : 'onCiteKeyCreated';
|
||||
const keys = newValue.split(',').map(k => k.trim());
|
||||
const eventName = oldValue ? "onCiteKeyChanged" : "onCiteKeyCreated";
|
||||
const keys = newValue.split(",").map(k => k.trim());
|
||||
const options = { detail: [this, keys], bubbles: true };
|
||||
const event = new CustomEvent(eventName, options);
|
||||
document.dispatchEvent(event);
|
||||
}
|
||||
|
||||
set key(value) {
|
||||
this.setAttribute('key', value);
|
||||
this.setAttribute("key", value);
|
||||
}
|
||||
|
||||
get key() {
|
||||
return this.getAttribute('key');
|
||||
return this.getAttribute("key") || this.getAttribute("bibtex-key");
|
||||
}
|
||||
|
||||
get keys() {
|
||||
return this.getAttribute('key').split(',');
|
||||
return this.key.split(",");
|
||||
}
|
||||
|
||||
/* Setters & Rendering */
|
||||
@@ -143,16 +145,16 @@ export class Cite extends T(HTMLElement) {
|
||||
|
||||
displayNumbers(numbers) {
|
||||
if (!this.innerSpan) return;
|
||||
const numberStrings = numbers.map( index => {
|
||||
return index == -1 ? '?' : index + 1 + '';
|
||||
const numberStrings = numbers.map(index => {
|
||||
return index == -1 ? "?" : index + 1 + "";
|
||||
});
|
||||
const textContent = '[' + numberStrings.join(', ') + ']';
|
||||
const textContent = "[" + numberStrings.join(", ") + "]";
|
||||
this.innerSpan.textContent = textContent;
|
||||
}
|
||||
|
||||
set entries(entries) {
|
||||
this._entries = entries;
|
||||
this.displayEntries(entries)
|
||||
this.displayEntries(entries);
|
||||
}
|
||||
|
||||
get entries() {
|
||||
@@ -160,10 +162,12 @@ export class Cite extends T(HTMLElement) {
|
||||
}
|
||||
|
||||
displayEntries(entries) {
|
||||
if (!this.hoverBox) return
|
||||
if (!this.hoverBox) return;
|
||||
this.hoverBox.innerHTML = `<ul>
|
||||
${entries.map(hover_cite).map(html => `<li>${html}</li>`).join('\n')}
|
||||
${entries
|
||||
.map(hover_cite)
|
||||
.map(html => `<li>${html}</li>`)
|
||||
.join("\n")}
|
||||
</ul>`;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+4
-2
@@ -173,8 +173,10 @@ export const Controller = {
|
||||
}
|
||||
|
||||
const frontMatterTag = document.querySelector('d-front-matter');
|
||||
const data = parseFrontmatter(frontMatterTag);
|
||||
Controller.listeners.onFrontMatterChanged({detail: data});
|
||||
if (frontMatterTag) {
|
||||
const data = parseFrontmatter(frontMatterTag);
|
||||
Controller.listeners.onFrontMatterChanged({detail: data});
|
||||
}
|
||||
|
||||
// Resolving "citations" dependency due to initial DOM load
|
||||
frontMatter.citations = collect_citations();
|
||||
|
||||
+103
-90
@@ -12,74 +12,85 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
export function collect_citations(dom=document) {
|
||||
export function collect_citations(dom = document) {
|
||||
const citations = new Set();
|
||||
const citeTags = dom.querySelectorAll('d-cite');
|
||||
const citeTags = dom.querySelectorAll("d-cite");
|
||||
for (const tag of citeTags) {
|
||||
const keys = tag.getAttribute('key').split(',');
|
||||
for (const key of keys) {
|
||||
for (const key of tag.keys) {
|
||||
citations.add(key);
|
||||
}
|
||||
}
|
||||
return [...citations];
|
||||
}
|
||||
|
||||
export function inline_cite_short(keys){
|
||||
function cite_string(key){
|
||||
if (key in data.bibliography){
|
||||
var n = data.citations.indexOf(key)+1;
|
||||
return ''+n;
|
||||
export function inline_cite_short(keys) {
|
||||
function cite_string(key) {
|
||||
if (key in data.bibliography) {
|
||||
var n = data.citations.indexOf(key) + 1;
|
||||
return "" + n;
|
||||
} else {
|
||||
return '?';
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
return '['+keys.map(cite_string).join(', ')+']';
|
||||
return "[" + keys.map(cite_string).join(", ") + "]";
|
||||
}
|
||||
|
||||
export function inline_cite_long(keys){
|
||||
function cite_string(key){
|
||||
if (key in data.bibliography){
|
||||
export function inline_cite_long(keys) {
|
||||
function cite_string(key) {
|
||||
if (key in data.bibliography) {
|
||||
var ent = data.bibliography[key];
|
||||
var names = ent.author.split(' and ');
|
||||
names = names.map(name => name.split(',')[0].trim());
|
||||
var names = ent.author.split(" and ");
|
||||
names = names.map(name => name.split(",")[0].trim());
|
||||
var year = ent.year;
|
||||
if (names.length == 1) return names[0] + ', ' + year;
|
||||
if (names.length == 2) return names[0] + ' & ' + names[1] + ', ' + year;
|
||||
if (names.length > 2) return names[0] + ', et al., ' + year;
|
||||
if (names.length == 1) return names[0] + ", " + year;
|
||||
if (names.length == 2) return names[0] + " & " + names[1] + ", " + year;
|
||||
if (names.length > 2) return names[0] + ", et al., " + year;
|
||||
} else {
|
||||
return '?';
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
return keys.map(cite_string).join(', ');
|
||||
return keys.map(cite_string).join(", ");
|
||||
}
|
||||
|
||||
function author_string(ent, template, sep, finalSep){
|
||||
if (ent.author == null) { return ''; }
|
||||
var names = ent.author.split(' and ');
|
||||
function author_string(ent, template, sep, finalSep) {
|
||||
if (ent.author == null) {
|
||||
return "";
|
||||
}
|
||||
var names = ent.author.split(" and ");
|
||||
let name_strings = names.map(name => {
|
||||
name = name.trim();
|
||||
if (name.indexOf(',') != -1){
|
||||
var last = name.split(',')[0].trim();
|
||||
var firsts = name.split(',')[1];
|
||||
} else if (name.indexOf(' ') != -1) {
|
||||
var last = name.split(' ').slice(-1)[0].trim();
|
||||
var firsts = name.split(' ').slice(0,-1).join(' ');
|
||||
if (name.indexOf(",") != -1) {
|
||||
var last = name.split(",")[0].trim();
|
||||
var firsts = name.split(",")[1];
|
||||
} else if (name.indexOf(" ") != -1) {
|
||||
var last = name
|
||||
.split(" ")
|
||||
.slice(-1)[0]
|
||||
.trim();
|
||||
var firsts = name
|
||||
.split(" ")
|
||||
.slice(0, -1)
|
||||
.join(" ");
|
||||
} else {
|
||||
var last = name.trim();
|
||||
}
|
||||
var initials = '';
|
||||
var initials = "";
|
||||
if (firsts != undefined) {
|
||||
initials = firsts.trim().split(' ').map(s => s.trim()[0]);
|
||||
initials = initials.join('.')+'.';
|
||||
initials = firsts
|
||||
.trim()
|
||||
.split(" ")
|
||||
.map(s => s.trim()[0]);
|
||||
initials = initials.join(".") + ".";
|
||||
}
|
||||
return template.replace('${F}', firsts)
|
||||
.replace('${L}', last)
|
||||
.replace('${I}', initials)
|
||||
return template
|
||||
.replace("${F}", firsts)
|
||||
.replace("${L}", last)
|
||||
.replace("${I}", initials)
|
||||
.trim(); // in case one of first or last was empty
|
||||
});
|
||||
if (names.length > 1) {
|
||||
var str = name_strings.slice(0, names.length-1).join(sep);
|
||||
str += (finalSep || sep) + name_strings[names.length-1];
|
||||
var str = name_strings.slice(0, names.length - 1).join(sep);
|
||||
str += (finalSep || sep) + name_strings[names.length - 1];
|
||||
return str;
|
||||
} else {
|
||||
return name_strings[0];
|
||||
@@ -87,69 +98,71 @@ function author_string(ent, template, sep, finalSep){
|
||||
}
|
||||
|
||||
function venue_string(ent) {
|
||||
var cite = (ent.journal || ent.booktitle || '');
|
||||
if ('volume' in ent){
|
||||
var cite = ent.journal || ent.booktitle || "";
|
||||
if ("volume" in ent) {
|
||||
var issue = ent.issue || ent.number;
|
||||
issue = (issue != undefined)? '('+issue+')' : '';
|
||||
cite += ', Vol ' + ent.volume + issue;
|
||||
issue = issue != undefined ? "(" + issue + ")" : "";
|
||||
cite += ", Vol " + ent.volume + issue;
|
||||
}
|
||||
if ('pages' in ent){
|
||||
cite += ', pp. ' + ent.pages;
|
||||
if ("pages" in ent) {
|
||||
cite += ", pp. " + ent.pages;
|
||||
}
|
||||
if (cite != '') cite += '. ';
|
||||
if ('publisher' in ent){
|
||||
if (cite != "") cite += ". ";
|
||||
if ("publisher" in ent) {
|
||||
cite += ent.publisher;
|
||||
if (cite[cite.length-1] != '.') cite += '.';
|
||||
if (cite[cite.length - 1] != ".") cite += ".";
|
||||
}
|
||||
return cite;
|
||||
}
|
||||
|
||||
function link_string(ent){
|
||||
if ('url' in ent){
|
||||
function link_string(ent) {
|
||||
if ("url" in ent) {
|
||||
var url = ent.url;
|
||||
var arxiv_match = (/arxiv\.org\/abs\/([0-9\.]*)/).exec(url);
|
||||
if (arxiv_match != null){
|
||||
var arxiv_match = /arxiv\.org\/abs\/([0-9\.]*)/.exec(url);
|
||||
if (arxiv_match != null) {
|
||||
url = `http://arxiv.org/pdf/${arxiv_match[1]}.pdf`;
|
||||
}
|
||||
|
||||
if (url.slice(-4) == '.pdf'){
|
||||
var label = 'PDF';
|
||||
} else if (url.slice(-5) == '.html') {
|
||||
var label = 'HTML';
|
||||
if (url.slice(-4) == ".pdf") {
|
||||
var label = "PDF";
|
||||
} else if (url.slice(-5) == ".html") {
|
||||
var label = "HTML";
|
||||
}
|
||||
return `  <a href="${url}">[${label||'link'}]</a>`;
|
||||
}/* else if ("doi" in ent){
|
||||
return `  <a href="${url}">[${label || "link"}]</a>`;
|
||||
} /* else if ("doi" in ent){
|
||||
return `  <a href="https://doi.org/${ent.doi}" >[DOI]</a>`;
|
||||
}*/ else {
|
||||
return '';
|
||||
return "";
|
||||
}
|
||||
}
|
||||
function doi_string(ent, new_line){
|
||||
if ('doi' in ent) {
|
||||
return `${new_line?'<br>':''} <a href="https://doi.org/${ent.doi}" style="text-decoration:inherit;">DOI: ${ent.doi}</a>`;
|
||||
function doi_string(ent, new_line) {
|
||||
if ("doi" in ent) {
|
||||
return `${new_line ? "<br>" : ""} <a href="https://doi.org/${
|
||||
ent.doi
|
||||
}" style="text-decoration:inherit;">DOI: ${ent.doi}</a>`;
|
||||
} else {
|
||||
return '';
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
function title_string(ent) {
|
||||
return '<span class="title">' + ent.title + '</span> ';
|
||||
return '<span class="title">' + ent.title + "</span> ";
|
||||
}
|
||||
|
||||
export function bibliography_cite(ent, fancy){
|
||||
if (ent){
|
||||
export function bibliography_cite(ent, fancy) {
|
||||
if (ent) {
|
||||
var cite = title_string(ent);
|
||||
cite += link_string(ent) + '<br>';
|
||||
cite += link_string(ent) + "<br>";
|
||||
if (ent.author) {
|
||||
cite += author_string(ent, '${L}, ${I}', ', ', ' and ');
|
||||
cite += author_string(ent, "${L}, ${I}", ", ", " and ");
|
||||
if (ent.year || ent.date) {
|
||||
cite += ', ';
|
||||
cite += ", ";
|
||||
}
|
||||
}
|
||||
if (ent.year || ent.date) {
|
||||
cite += (ent.year || ent.date) + '. ';
|
||||
cite += (ent.year || ent.date) + ". ";
|
||||
} else {
|
||||
cite += '. ';
|
||||
cite += ". ";
|
||||
}
|
||||
cite += venue_string(ent);
|
||||
cite += doi_string(ent);
|
||||
@@ -166,39 +179,39 @@ export function bibliography_cite(ent, fancy){
|
||||
cite += link_string(ent);
|
||||
return cite*/
|
||||
} else {
|
||||
return '?';
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
export function hover_cite(ent){
|
||||
if (ent){
|
||||
var cite = '';
|
||||
cite += '<strong>' + ent.title + '</strong>';
|
||||
export function hover_cite(ent) {
|
||||
if (ent) {
|
||||
var cite = "";
|
||||
cite += "<strong>" + ent.title + "</strong>";
|
||||
cite += link_string(ent);
|
||||
cite += '<br>';
|
||||
cite += "<br>";
|
||||
|
||||
var a_str = author_string(ent, '${I} ${L}', ', ') + '.';
|
||||
var v_str = venue_string(ent).trim() + ' ' + ent.year + '. ' + doi_string(ent, true);
|
||||
var a_str = author_string(ent, "${I} ${L}", ", ") + ".";
|
||||
var v_str =
|
||||
venue_string(ent).trim() + " " + ent.year + ". " + doi_string(ent, true);
|
||||
|
||||
if ((a_str+v_str).length < Math.min(40, ent.title.length)) {
|
||||
cite += a_str + ' ' + v_str;
|
||||
if ((a_str + v_str).length < Math.min(40, ent.title.length)) {
|
||||
cite += a_str + " " + v_str;
|
||||
} else {
|
||||
cite += a_str + '<br>' + v_str;
|
||||
cite += a_str + "<br>" + v_str;
|
||||
}
|
||||
return cite;
|
||||
} else {
|
||||
return '?';
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//https://scholar.google.com/scholar?q=allintitle%3ADocument+author%3Aolah
|
||||
function get_GS_URL(ent){
|
||||
if (ent){
|
||||
var names = ent.author.split(' and ');
|
||||
names = names.map(name => name.split(',')[0].trim());
|
||||
var title = ent.title.split(' ');//.replace(/[,:]/, "")
|
||||
var url = 'http://search.labs.crossref.org/dois?';//""https://scholar.google.com/scholar?"
|
||||
url += uris({q: names.join(' ') + ' ' + title.join(' ')});
|
||||
function get_GS_URL(ent) {
|
||||
if (ent) {
|
||||
var names = ent.author.split(" and ");
|
||||
names = names.map(name => name.split(",")[0].trim());
|
||||
var title = ent.title.split(" "); //.replace(/[,:]/, "")
|
||||
var url = "http://search.labs.crossref.org/dois?"; //""https://scholar.google.com/scholar?"
|
||||
url += uris({ q: names.join(" ") + " " + title.join(" ") });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user