|
|
|
@ -19,6 +19,14 @@ export class CardModel {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function buildFileCard(filePath: string, elem: Element, append: boolean = false, $: any = require('jquery')) {
|
|
|
|
export function buildFileCard(filePath: string, elem: Element, append: boolean = false, $: any = require('jquery')) {
|
|
|
|
|
|
|
|
let conf = config.loadUserConfig("user.json");
|
|
|
|
|
|
|
|
console.log(conf);
|
|
|
|
|
|
|
|
let links = conf['links'];
|
|
|
|
|
|
|
|
if (!links) {
|
|
|
|
|
|
|
|
links = [];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
links.push("www.fark.com");
|
|
|
|
|
|
|
|
config.saveUserConfig("user.json", conf);
|
|
|
|
let model = new CardModel(getImagePathFromDocumentName(filePath), fileNameToPrettyString(filePath));
|
|
|
|
let model = new CardModel(getImagePathFromDocumentName(filePath), fileNameToPrettyString(filePath));
|
|
|
|
loadTemplateSingle("file-card.mustache", model, (content: string, id: string) => {
|
|
|
|
loadTemplateSingle("file-card.mustache", model, (content: string, id: string) => {
|
|
|
|
let snip = $(content);
|
|
|
|
let snip = $(content);
|
|
|
|
@ -38,7 +46,7 @@ export function buildFileCard(filePath: string, elem: Element, append: boolean =
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function buildDefaultWebCards(elem: Element) {
|
|
|
|
export function buildDefaultWebCards(elem: Element) {
|
|
|
|
let userPrefs = config.loadConfigMap("user.json");
|
|
|
|
let userPrefs = config.loadAppConfig("user.json");
|
|
|
|
let links = userPrefs['default-links'];
|
|
|
|
let links = userPrefs['default-links'];
|
|
|
|
let $ = require('jquery')
|
|
|
|
let $ = require('jquery')
|
|
|
|
for (let i = 0, l = links.length; i < l; i++) {
|
|
|
|
for (let i = 0, l = links.length; i < l; i++) {
|
|
|
|
@ -48,8 +56,6 @@ export function buildDefaultWebCards(elem: Element) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function buildWebCard(urlText: string, elem: Element, append: boolean = false, $: any = require('jquery')) {
|
|
|
|
export function buildWebCard(urlText: string, elem: Element, append: boolean = false, $: any = require('jquery')) {
|
|
|
|
console.log("adding " + urlText)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let url = new URL(urlText);
|
|
|
|
let url = new URL(urlText);
|
|
|
|
let favicon = WebUtils.getFaviconUrl(url);
|
|
|
|
let favicon = WebUtils.getFaviconUrl(url);
|
|
|
|
let model = new CardModel(favicon, urlText);
|
|
|
|
let model = new CardModel(favicon, urlText);
|
|
|
|
@ -65,14 +71,12 @@ export function buildWebCard(urlText: string, elem: Element, append: boolean = f
|
|
|
|
$.get(url.toString(), (data, status) => {
|
|
|
|
$.get(url.toString(), (data, status) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if ('success' === status) {
|
|
|
|
if ('success' === status) {
|
|
|
|
console.log(`get ${url.toString()} was successful`);
|
|
|
|
|
|
|
|
resolve($(data).filter('title').text());
|
|
|
|
resolve($(data).filter('title').text());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (a) {
|
|
|
|
} catch (a) {
|
|
|
|
console.error("Error while attempting to fetch page title", a)
|
|
|
|
console.error("Error while attempting to fetch page title", a)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).fail((failure) => {
|
|
|
|
}).fail((failure) => {
|
|
|
|
console.log(`get ${url.toString()} failed ${failure}`)
|
|
|
|
|
|
|
|
reject(failure);
|
|
|
|
reject(failure);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}).then((value: string) => {
|
|
|
|
}).then((value: string) => {
|
|
|
|
@ -104,7 +108,9 @@ function fileNameToPrettyString(fileName: string): string {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getImagePathFromDocumentName(name: string): string {
|
|
|
|
function getImagePathFromDocumentName(name: string): string {
|
|
|
|
return fu.getPathToImage(config.getFileExtensionToImageMap()[fu.getFileExtension(name)])
|
|
|
|
let ext = fu.getFileExtension(name);
|
|
|
|
|
|
|
|
let thumbnail = config.getFileExtensionToImageMap()[ext];
|
|
|
|
|
|
|
|
return fu.getPathToImage(thumbnail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function launchDocument(filename: string) {
|
|
|
|
function launchDocument(filename: string) {
|
|
|
|
|