mirror of
https://github.com/shadowoption/Hunchly-obsidian-plugin.git
synced 2026-07-22 08:50:25 +00:00
Fix PR comments from Obsidian team and few bugs (#2)
This commit is contained in:
parent
239c9367c3
commit
767d02d86f
3 changed files with 23 additions and 43 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<number, INote>, pages: Map<number, IPage>, selectors: Map<number, string>, selectorHits: Map<number, number[]>, extractionPath : string){
|
||||
await this.createDirectoryIfNotExists(path.join("hunchly_notes", "screenshots"))
|
||||
const urlMap = new Map<string, string>()
|
||||
|
|
@ -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<number, IPhoto>, pages: Map<number, IPage>, selectors: Map<number, string>, selectorHits: Map<number, number[]>, extractionPath : string){
|
||||
await this.createDirectoryIfNotExists(path.join("hunchly_notes", "screenshots"))
|
||||
await this.createDirectoryIfNotExists(path.join("hunchly_captioned_images", "screenshots"))
|
||||
const urlMap = new Map<string, string>()
|
||||
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<void> {
|
||||
private async createNoteFile(filename: string, content: string, location: string): Promise<void> {
|
||||
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<void> {
|
||||
private async updateNoteFile(filename: string, content: string, location: string): Promise<void> {
|
||||
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){
|
||||
|
|
|
|||
28
src/main.ts
28
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", `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" enable-background="new 0 0 64 64"><circle cx="32" cy="32" r="30" fill="#fff"/><path d="M32,2C15.432,2,2,15.432,2,32s13.432,30,30,30s30-13.432,30-30S48.568,2,32,2z M43.664,46.508h-6.023V33.555H26.361v12.953
|
||||
h-6.025V17.492h6.025v11.063h11.279V17.492h6.023V46.508z" fill="#1e88e5"/></svg>`);
|
||||
// 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() { }
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue