Skip to content

Commit 0143571

Browse files
committed
new bibliography custom urls
SQUASHED: AUTO-COMMIT-doc-journal-2020-09-09.md-bibliography_navigation.png,AUTO-COMMIT-doc-journal-2020-09-09.md-index.md,AUTO-COMMIT-doc-journal-2020-09-09.md-literature_overview.png,AUTO-COMMIT-doc-scripts-filename.md,AUTO-COMMIT-doc-scripts-scholar.md,AUTO-COMMIT-doc-scripts-scholoar.md,AUTO-COMMIT-src-client-lively.js,AUTO-COMMIT-src-client-protocols-author.js,AUTO-COMMIT-src-client-protocols-bib.js,AUTO-COMMIT-src-client-protocols-bibliography-scheme.js,AUTO-COMMIT-src-client-protocols-keyword.js,AUTO-COMMIT-src-components-tools-lively-container.js,
1 parent 1a4dc44 commit 0143571

File tree

11 files changed

+191
-84
lines changed

11 files changed

+191
-84
lines changed
400 KB
Loading

doc/journal/2020-09-09.md/index.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,17 @@ var query = decodeURI(container.getURL().pathname)
3434
.replace(/_/g," ")
3535

3636
googleScholar(query)
37-
```
37+
```
38+
39+
## Custom URLs for the win!
40+
41+
An literature overview page also links the papers through it's bibtex keys.
42+
43+
![](literature_overview.png)
44+
45+
And then we enter the world of bibliography entries, authors, and keywords:
46+
47+
![](bibliography_navigation.png)
48+
49+
50+
405 KB
Loading

doc/scripts/filename.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Filename Cleanup
2+
3+
4+
```javascript
5+
6+
import Strings from 'src/client/strings.js'
7+
8+
var input = document.querySelector("lively-dialog").get("input");
9+
10+
11+
var ignore = new Set(["A"]);
12+
13+
input.value = input.value.split(" ")
14+
.map(ea => ea.replace(/[,:;\-]/,""))
15+
.filter(ea => ea.length > 0)
16+
.map(ea => Strings.toUpperCaseFirst(ea))
17+
.filter(ea => !ignore.has(ea))
18+
.join("")
19+
20+
```

doc/scripts/scholar.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Google Scholor IFrame
2+
3+
4+
```javascript
5+
6+
async function googleScholar(queryString) {
7+
const frameId = "googlescholoar"
8+
var iframe = document.body.querySelector("#" + frameId)
9+
10+
if (!iframe) {
11+
iframe = await lively.openComponentInWindow("lively-iframe")
12+
iframe.setAttribute("id", frameId)
13+
iframe.hideMenubar()
14+
}
15+
16+
var query = queryString.replace(/ /g,"+")
17+
iframe.setURL("https://scholar.google.com/scholar?hl=en&as_sdt=0%2C5&btnG=&q=" + query)
18+
19+
}
20+
21+
var container = document.body.querySelector("lively-container");
22+
var query = decodeURI(container.getURL().pathname)
23+
.replace(/.*\//,"")
24+
.replace(/\.pdf$/,"")
25+
.replace(/([a-z])([A-Z])/g,"$1 $2")
26+
.replace(/_/g," ")
27+
28+
googleScholar(query)
29+
```

src/client/lively.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ export default class Lively {
461461
await System.import("src/client/protocols/wikipedia.js")
462462
await System.import("src/client/protocols/tmp.js")
463463
await System.import("src/client/protocols/bib.js")
464+
await System.import("src/client/protocols/author.js")
464465

465466
await System.import("src/client/protocols/microsoft.js")
466467

src/client/protocols/author.js

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,16 @@
1-
import {Scheme} from "src/client/poid.js"
21
import PolymorphicIdentifier from "src/client/poid.js"
3-
import focalStorage from "src/external/focalStorage.js"
4-
import {parseQuery, getDeepProperty} from 'utils'
2+
import BibliographyScheme from "./bibliography-scheme.js";
53

6-
import FileIndex from "src/client/fileindex.js"
7-
8-
export class AuthorScheme extends Scheme {
4+
export class AuthorScheme extends BibliographyScheme {
95

106
get scheme() {
117
return "author"
128
}
139

14-
resolve() {
15-
return true
10+
searchEntries(entries, query) {
11+
var author = query
12+
return entries.filter(entry => entry.authors && entry.authors.find(ea => ea.match(author)))
1613
}
17-
18-
async GET(options) {
19-
var author = this.url.replace(/author\:\/\//,"")
20-
21-
22-
var entries = await FileIndex.current().db.bibref.where("author").equals(author).toArray()
23-
var entry = entries[0] || {}
24-
25-
var content = `<h2>${author}</h2>`
26-
27-
content += "<h3>Articles</h3><ul>" + entries.map(ea => {
28-
return `<li><a href="bib://${entries.key}">[${entries.key}] ${ea.name}</a></li>`
29-
}).join("\n") + "</ul>"
30-
31-
return new Response(content, {
32-
headers: {
33-
"content-type": "text/html",
34-
},
35-
status: 200,
36-
})
37-
}
38-
39-
4014
}
4115

42-
43-
4416
PolymorphicIdentifier.register(AuthorScheme)

src/client/protocols/bib.js

Lines changed: 23 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,51 @@
1-
import {Scheme} from "src/client/poid.js"
21
import PolymorphicIdentifier from "src/client/poid.js"
3-
import focalStorage from "src/external/focalStorage.js"
4-
import {parseQuery, getDeepProperty} from 'utils'
5-
2+
import BibliographyScheme from "./bibliography-scheme.js";
63
import FileIndex from "src/client/fileindex.js"
74

8-
export class BibScheme extends Scheme {
5+
export class BibScheme extends BibliographyScheme {
96

107
get scheme() {
118
return "bib"
129
}
1310

14-
resolve() {
15-
return true
16-
}
11+
async searchEntries(entries, query) {
12+
var key = query
13+
return entries.filter(entry => entry.key == key)
14+
}
1715

18-
async GET(options) {
19-
var key = this.url.replace(/bib\:\/\//,"")
16+
async content(entries, query) {
17+
var entry = entries[0] || {}
2018

19+
var key = query
2120

22-
var entries = await FileIndex.current().db.bibliography.where("key").equals(key).toArray()
23-
var entry = entries[0] || {}
21+
var files = await FileIndex.current().db.files.where("bibkey").equals(key).toArray()
2422

25-
var content = `<h2>[${key}]<br/>${entry.authors ? entry.authors + ".": ""} ${entry.year|| ""}<br/><i> ${entry.title|| ""} </i></h2>`
23+
var content = `<h2>[${key}]<br/>${
24+
entry.authors ?
25+
entry.authors.map(ea => `<a href="author://${ea}">${ea}</a>` ).join(", ") + ".": ""
26+
} ${entry.year|| ""}<br/><i> ${entry.title|| ""} </i></h2>`
2627

27-
if (entry.source) {
28-
content += "<pre>" + entry.source+ "</pre>"
2928

29+
if (entry.keywords) {
30+
content += `<div><b>Keywords:</b> ${entry.keywords.map(ea => `<a href="keyword://${ea}">${ea}</a>`).join(", ") } </div>`
3031
}
3132

32-
33-
var files = await FileIndex.current().db.files.where("bibkey").equals(key).toArray()
3433

34+
35+
if (entry.source) {
36+
content += "<pre>" + entry.source+ "</pre>"
37+
}
38+
3539
content += "<h3>Documents</h3><ul>" + files.map(ea => {
3640
return `<li><a href="${ea.url}">${ea.name}</a></li>`
3741
}).join("\n") + "</ul>"
3842

3943

4044
content += "<h3>Bibliographies</h3><ul>" + entries.map(ea => {
4145
return `<li><a href="${ea.url}">${ea.url}</a></li>`
42-
}).join("\n") + "</ul>"
43-
44-
45-
46-
return new Response(content, {
47-
headers: {
48-
"content-type": "text/html",
49-
},
50-
status: 200,
51-
})
52-
}
53-
54-
55-
async OPTIONS(options) {
56-
57-
var content = JSON.stringify({}, undefined, 2)
58-
59-
60-
return new Response(content, {
61-
headers: {
62-
"content-type": "application/json",
63-
},
64-
status: 200,
65-
})
46+
}).join("\n") + "</ul>"
47+
return content
6648
}
67-
68-
69-
70-
7149
}
7250

73-
74-
7551
PolymorphicIdentifier.register(BibScheme)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import {Scheme} from "src/client/poid.js"
2+
import PolymorphicIdentifier from "src/client/poid.js"
3+
import focalStorage from "src/external/focalStorage.js"
4+
import {parseQuery, getDeepProperty} from 'utils'
5+
6+
import FileIndex from "src/client/fileindex.js"
7+
8+
import _ from 'src/external/lodash/lodash.js'
9+
/*MD # Abstract Class for all Bibliograpgy Schemes MD*/
10+
11+
export default class BibliographyScheme extends Scheme {
12+
13+
get scheme() {
14+
throw new Error("subclass responsibility")
15+
}
16+
17+
resolve() {
18+
return true
19+
}
20+
21+
generateArticlesSource(entries) {
22+
return "<h3>Articles</h3><ul>" + entries.map(ea => {
23+
return `<li><a href="bib://${ea.key}">[${ea.key}]</a> ${
24+
ea.authors.map(ea => `<a href="author://${ea}">${ea}</a>`).join(", ")
25+
}. ${
26+
ea.title
27+
}. ${
28+
ea.keywords.map(ea => `<a href="keyword://${ea}">${ea}</a>`).join(", ")
29+
}.</li>`
30+
}).join("\n") + "</ul>"
31+
}
32+
33+
response(content) {
34+
return new Response(content, {
35+
headers: {
36+
"content-type": "text/html",
37+
},
38+
status: 200,
39+
})
40+
}
41+
42+
async searchEntries(entries, query) {
43+
return entries
44+
}
45+
46+
async content(entries, query) {
47+
var content = `<h2>${this.scheme}: ${query}</h2>`
48+
content += this.generateArticlesSource(entries)
49+
return content
50+
}
51+
52+
async GET(options) {
53+
var query = this.url.replace(new RegExp(this.scheme + "\:\/\/"),"")
54+
if (query.length < 2) return this.response("query to short")
55+
56+
query = decodeURI(query)
57+
var entries = await FileIndex.current().db.bibliography.toArray()
58+
59+
entries = await this.searchEntries(entries, query)
60+
61+
entries = _.uniqBy(entries, ea => ea.key)
62+
63+
64+
var content = await this.content(entries, query)
65+
66+
return this.response(content)
67+
}
68+
69+
async OPTIONS(options) {
70+
var content = JSON.stringify({}, undefined, 2)
71+
return new Response(content, {
72+
headers: {
73+
"content-type": "application/json",
74+
},
75+
status: 200,
76+
})
77+
}
78+
79+
}

src/client/protocols/keyword.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import PolymorphicIdentifier from "src/client/poid.js"
2+
import BibliographyScheme from "./bibliography-scheme.js";
3+
4+
export class KeywordScheme extends BibliographyScheme {
5+
6+
get scheme() {
7+
return "keyword"
8+
}
9+
10+
searchEntries(entries, query) {
11+
var keyword = query
12+
return entries.filter(entry => entry.keywords && entry.keywords.find(ea => ea.match(keyword)))
13+
}
14+
}
15+
16+
PolymorphicIdentifier.register(KeywordScheme)

0 commit comments

Comments
 (0)