Skip to content

Commit 37088a1

Browse files
committed
work on bibtex
SQUASHED: work-on-bibtex-listing,
1 parent 3a92b68 commit 37088a1

File tree

6 files changed

+117
-6
lines changed

6 files changed

+117
-6
lines changed

doc/scripts/fileindex.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# FileIndex
2+
3+
4+
## Remove a Directory from Index
5+
6+
```javascript
7+
import FileIndex from 'src/client/fileindex.js'
8+
9+
FileIndex.current().removeDirectory("http://localhost:9005/Dropbox/Thesis/Literature/")
10+
```

src/client/bibliography.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ Bibliography.cleanTitle("{{This is my Title}}")
136136
/*MD
137137
<style>* {background-color:lightgray}</style>
138138
```javascript
139-
Bibliography.filenameToKey("AuthorSecondauthor_1981_TitleInCammelCase_BOOK.pdf")
139+
[Bibliography.filenameToKey("AuthorSecondauthor_1981_TitleInCammelCase_BOOK.pdf"),
140+
Bibliography.filenameToKey("00_Winograd_1996_Introduction.pdf")]
140141
```
141142
142143
<script>
@@ -150,6 +151,8 @@ Bibliography.filenameToKey("AuthorSecondauthor_1981_TitleInCammelCase_BOOK.pdf")
150151
MD*/
151152

152153
static filenameToKey(filename) {
154+
filename = filename.replace(/^[0-9][0-9]*[A-Z]?_/,"") // strip index number
155+
153156
var a = filename.split("_")
154157
if (a.length < 3) return
155158
var authors = a[0]

src/client/fileindex.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,16 @@ export default class FileIndex {
846846
this.db.files.delete(url)
847847
})
848848
}
849+
850+
async removeDirectory(baseURL) {
851+
var files = await this.toArray()
852+
for(let ea of files) {
853+
let eaURL = ea.url
854+
if (eaURL.startsWith(baseURL)) {
855+
this.dropFile(eaURL)
856+
}
857+
}
858+
}
849859

850860
async updateDirectory(baseURL, showProgress, updateDeleted) {
851861
var json = await fetch(baseURL, {
@@ -886,8 +896,6 @@ export default class FileIndex {
886896
try {
887897
for(let ea of files) {
888898
if (showProgress) progress.value = i++ / total;
889-
890-
891899
let eaURL = baseURL.replace(/\/$/,"") + ea.name.replace(/^\./,"")
892900
let name = eaURL.replace(/.*\//,"")
893901
if (lastModified.get(eaURL) !== ea.modified) {

src/components/tools/lively-container.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ export default class Container extends Morph {
817817
}
818818
}
819819

820-
async renameFile(url) {
820+
async renameFile(url, followFile=true) {
821821
url = "" + url
822822
var base = url.replace(/[^/]*$/,"")
823823
var name = url.replace(/.*\//,"")
@@ -831,11 +831,14 @@ export default class Container extends Morph {
831831
if (newURL != url) {
832832
await files.moveFile(url, newURL)
833833

834-
this.setPath(newURL);
835-
this.hideCancelAndSave();
834+
if (followFile) {
835+
this.setPath(newURL);
836+
this.hideCancelAndSave();
837+
}
836838

837839
lively.notify("moved to " + newURL);
838840
}
841+
return newURL
839842
}
840843

841844
async newFile(path="", type="md") {

src/external/title-case.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*Copyright © 2008–2018 David Gouch
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
20+
*/
21+
22+
export default function toTitleCase(s) {
23+
var smallWords = /^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|v.?|vs.?|via)$/i
24+
var alphanumericPattern = /([A-Za-z0-9\u00C0-\u00FF])/
25+
var wordSeparators = /([ :-])/
26+
27+
return s.split(wordSeparators)
28+
.map(function (current, index, array) {
29+
if (
30+
/* Check for small words */
31+
current.search(smallWords) > -1 &&
32+
/* Skip first and last word */
33+
index !== 0 &&
34+
index !== array.length - 1 &&
35+
/* Ignore title end and subtitle start */
36+
array[index - 3] !== ':' &&
37+
array[index + 1] !== ':' &&
38+
/* Ignore small words that start a hyphenated phrase */
39+
(array[index + 1] !== '-' ||
40+
(array[index - 1] === '-' && array[index + 1] === '-'))
41+
) {
42+
return current.toLowerCase()
43+
}
44+
45+
/* Ignore intentional capitalization */
46+
if (current.substr(1).search(/[A-Z]|\../) > -1) {
47+
return current
48+
}
49+
50+
/* Ignore URLs */
51+
if (array[index + 1] === ':' && array[index + 2] !== '') {
52+
return current
53+
}
54+
55+
/* Capitalize the first letter */
56+
return current.replace(alphanumericPattern, function (match) {
57+
return match.toUpperCase()
58+
})
59+
})
60+
.join('')
61+
}

test/bibliography-test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {expect} from 'src/external/chai.js';
2+
import Bibliography from "src/client/bibliography.js"
3+
4+
describe('Bibliography', () => {
5+
6+
describe('filenameToKey', () => {
7+
it('converts normal filename', async function() {
8+
expect(Bibliography.filenameToKey("AuthorSecondauthor_1981_TitleInCammelCase_BOOK.pdf")).to.equal("Author1981TCC")
9+
});
10+
11+
it('converts normal prefixed with index number', async function() {
12+
expect(Bibliography.filenameToKey("00_Winograd_1996_Introduction.pdf")).to.equal("Winograd1996I")
13+
});
14+
15+
it('converts normal prefixed with long index number', async function() {
16+
expect(Bibliography.filenameToKey("121001_Winograd_1996_Introduction.pdf")).to.equal("Winograd1996I")
17+
});
18+
19+
20+
21+
it('converts normal prefixed with index number and letter', async function() {
22+
expect(Bibliography.filenameToKey("00C_Winograd_1996_Introduction.pdf")).to.equal("Winograd1996I")
23+
});
24+
25+
})
26+
});

0 commit comments

Comments
 (0)