diff --git a/README.md b/README.md index d4f1883..746637d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Hunchly Obsidian Sample Plugin +[Hunchly](https://www.hunch.ly) is a web capture tool designed For online investigations + This is an obsidian plugin to convert Hunchly notes and captioned images into obsidian notes. Also adds the selector as obsidian tags. ## How to use diff --git a/src/hunchly.ts b/src/hunchly.ts index f450de0..e36cc1b 100644 --- a/src/hunchly.ts +++ b/src/hunchly.ts @@ -100,11 +100,6 @@ export class Hunchly{ } } - private async updateStatus(status: string) { - const statusBarItemEl = this.plugin.addStatusBarItem(); - statusBarItemEl.setText(status); - } - private async processNotes(notes: Map, pages: Map, selectors: Map, selectorHits: Map, extractionPath : string){ await this.createDirectoryIfNotExists(path.join("hunchly_notes", "screenshots")) const urlMap = new Map() @@ -127,17 +122,21 @@ export class Hunchly{ } } - fileContent = fileContent + `${await this.processNoteContent(value.note)}\n\n` + let note = await this.processNoteContent(value.note) + if(note && note != null){ + fileContent = fileContent + `${note}\n\n` + } + fileContent = await this.addImages(path.join(extractionPath, "note_screenshots"), path.join(this.vaultPath, "hunchly_notes", "screenshots"), `${key}.jpeg`, fileContent) fileContent = fileContent + "\n---\n" if (urlMap.has(page.url) && this.consolidate) { const notePath = urlMap.get(page.url) if (notePath){ - await this.updateNoteFile(notePath, fileContent) + await this.updateNoteFile(notePath, fileContent, "hunchly_notes") } } else { - await this.createNoteFile(`${title}.md`, fileContent) + await this.createNoteFile(`${title}.md`, fileContent, "hunchly_notes") urlMap.set(page.url, `${title}.md`) } } @@ -145,7 +144,7 @@ export class Hunchly{ } private async processImages(photos: Map, pages: Map, selectors: Map, selectorHits: Map, extractionPath : string){ - await this.createDirectoryIfNotExists(path.join("hunchly_notes", "screenshots")) + await this.createDirectoryIfNotExists(path.join("hunchly_captioned_images", "screenshots")) const urlMap = new Map() for (const [key, value] of photos) { const page = pages.get(value.pageid) @@ -166,18 +165,21 @@ export class Hunchly{ fileContent = await addSelectors(selectorhits, selectors, fileContent) } } - - fileContent = fileContent + `${await this.processNoteContent(value.caption)}\n\n` + + let caption = await this.processNoteContent(value.caption) + if(caption && caption != "null"){ + fileContent = fileContent + `${caption}\n\n` + } fileContent = await this.addImages(path.join(extractionPath, "tagged_photos"), path.join(this.vaultPath, "hunchly_notes", "screenshots"), value.photopath, fileContent) fileContent = fileContent + "\n---\n" if (urlMap.has(page.url) && this.consolidate) { const notePath = urlMap.get(page.url) if (notePath){ - await this.updateNoteFile(notePath, fileContent) + await this.updateNoteFile(notePath, fileContent, "hunchly_captioned_images") } } else { - await this.createNoteFile(`${title}.md`, fileContent) + await this.createNoteFile(`${title}.md`, fileContent, "hunchly_captioned_images") urlMap.set(page.url, `${title}.md`) } } @@ -212,18 +214,18 @@ export class Hunchly{ return fileContent } - private async createNoteFile(filename: string, content: string): Promise { + private async createNoteFile(filename: string, content: string, location: string): Promise { try { - const notepath = path.join(this.hunchlyLocation, "hunchly_notes", filename) + const notepath = path.join(this.hunchlyLocation, location, filename) await this.vault.create(notepath, content) } catch (error) { console.log(`Error creating the file in ${filename}: ${error}`); } } - private async updateNoteFile(filename: string, content: string): Promise { + private async updateNoteFile(filename: string, content: string, location: string): Promise { try { - const notepath = path.join(this.hunchlyLocation, "hunchly_notes", filename) + const notepath = path.join(this.hunchlyLocation, location, filename) const notefile = this.vault.getAbstractFileByPath(notepath) if (notefile instanceof TFile){ diff --git a/src/main.ts b/src/main.ts index be8e78e..4d1b8b9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,26 +2,13 @@ import { Notice, Plugin, addIcon } from 'obsidian'; import { FileModal } from './fileModal'; import { Hunchly } from './hunchly'; -// Remember to rename these classes and interfaces! - -interface HunchlyObsidianPluginSettings { - mySetting: string; -} - -const DEFAULT_SETTINGS: HunchlyObsidianPluginSettings = { - mySetting: 'default' -} - export default class HunchlyObsidianPlugin extends Plugin { - settings: HunchlyObsidianPluginSettings; - async onload() { - await this.loadSettings(); //https://en.wikipedia.org/wiki/File:Eo_circle_blue_white_letter-h.svg creative common license addIcon("hunchly", ``); // This creates an icon in the left ribbon. - this.addRibbonIcon('hunchly', 'Hunchly Obsidian Plugin', (evt: MouseEvent) => { + this.addRibbonIcon('hunchly', 'Hunchly', (evt: MouseEvent) => { // Called when the user clicks the icon. new FileModal(this.app, "Select the exported hunchly case file (zip format).", (result) => { if (result.zipPath){ @@ -33,16 +20,5 @@ export default class HunchlyObsidianPlugin extends Plugin { }); } - - onunload() { - - } - - async loadSettings() { - this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); - } - - async saveSettings() { - await this.saveData(this.settings); - } + onunload() { } }