|
|
|
|
@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let path = require('path')
|
|
|
|
|
let fs = require('fs');
|
|
|
|
|
const shell = require('electron').shell;
|
|
|
|
|
@ -107,7 +109,6 @@ export class DocumentDirectory {
|
|
|
|
|
|
|
|
|
|
getCards(): object {
|
|
|
|
|
return DocumentDirectory.walkCards(this.root);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static walkCards(d: DirectoryNode): Map<String, object[]> {
|
|
|
|
|
@ -124,7 +125,17 @@ export class DocumentDirectory {
|
|
|
|
|
this.mergeMaps(cardsByCategory, subCards);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let sCards = dir.getDocuments()
|
|
|
|
|
let sCards = dir.getDocuments();
|
|
|
|
|
let category = dir.getCategory();
|
|
|
|
|
for (let sCard in sCards) {
|
|
|
|
|
let scrd = sCards[sCard];
|
|
|
|
|
let cards = cardsByCategory.get(category);
|
|
|
|
|
if (cards === undefined || cards === null) {
|
|
|
|
|
cards = [];
|
|
|
|
|
}
|
|
|
|
|
cards.push(scrd.toCard());
|
|
|
|
|
cardsByCategory.set(category, cards);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
let category = (child.parent as DirectoryNode).getCategory();
|
|
|
|
|
let cards = cardsByCategory.get(category);
|
|
|
|
|
@ -148,7 +159,7 @@ export class DocumentDirectory {
|
|
|
|
|
sa = [];
|
|
|
|
|
}
|
|
|
|
|
let sb = b.get(key)
|
|
|
|
|
if (sb === undefined || sa === null) {
|
|
|
|
|
if (sb === undefined) {
|
|
|
|
|
sb = [];
|
|
|
|
|
}
|
|
|
|
|
sa.push(...sb);
|
|
|
|
|
@ -168,24 +179,50 @@ export class FileNode {
|
|
|
|
|
this.parent = parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static loadAltProps(path: String): object {
|
|
|
|
|
let props = {};
|
|
|
|
|
let jsonPath = path + ".json"
|
|
|
|
|
if (fs.existsSync(jsonPath)) {
|
|
|
|
|
let raw = fs.readFileSync(jsonPath);
|
|
|
|
|
props = JSON.parse(raw.toString());
|
|
|
|
|
}
|
|
|
|
|
return props
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
open() {
|
|
|
|
|
shell.openItem(this.filePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
show() {
|
|
|
|
|
shell.showItemInFolder(this.filePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toCard(): object {
|
|
|
|
|
let altProps = FileNode.loadAltProps(this.filePath)
|
|
|
|
|
let cardObj = {
|
|
|
|
|
"title": this.getTitle(),
|
|
|
|
|
"description": "",
|
|
|
|
|
"imagePath": "",
|
|
|
|
|
"urlText": this.filePath,
|
|
|
|
|
"altText": ""
|
|
|
|
|
"altText": "",
|
|
|
|
|
"fileCard": true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let altKeys = Object.keys(altProps);
|
|
|
|
|
for (let kidx in altKeys) {
|
|
|
|
|
let key = altKeys[kidx];
|
|
|
|
|
cardObj[key] = altProps[key]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cardObj
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getTitle(): String {
|
|
|
|
|
let name = path.basename(this.filePath);
|
|
|
|
|
return name
|
|
|
|
|
let ext = path.extname(name);
|
|
|
|
|
let cName = name.replace(ext, "");
|
|
|
|
|
cName = cName.replace(/[\-._]/ig, " ")
|
|
|
|
|
return `${cName} (${ext.substr(1).toUpperCase()})`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isDescriptor() {
|
|
|
|
|
|