generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add import from a specific book. Add option to import all highl…
…ights on startup. Other improvements include: - Update README with a list of all available template variables. - Minor textual changes of the plugin commands in the Commands palette.
- Loading branch information
1 parent
f06c47c
commit 878de2c
Showing
8 changed files
with
104 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { App, Notice, SuggestModal } from 'obsidian'; | ||
import IBookHighlightsPlugin from '../main'; | ||
import { CombinedHighlight } from './types'; | ||
|
||
abstract class IBookHighlightsPluginSuggestModal extends SuggestModal<CombinedHighlight> { | ||
plugin: IBookHighlightsPlugin; | ||
constructor( | ||
app: App, | ||
plugin: IBookHighlightsPlugin) { | ||
super(app); | ||
this.plugin = plugin; | ||
} | ||
} | ||
|
||
export class IBookHighlightsPluginSearchModal extends IBookHighlightsPluginSuggestModal { | ||
async getSuggestions(query: string): Promise<CombinedHighlight[]> { | ||
const allBooks = await this.plugin.importHighlights(); | ||
return allBooks.filter(book => { | ||
const titleMatch = book.bookTitle.toLowerCase().includes(query.toLowerCase()); | ||
const authorMatch = book.bookAuthor.toLowerCase().includes(query.toLowerCase()); | ||
|
||
return titleMatch || authorMatch; | ||
}); | ||
} | ||
|
||
renderSuggestion(value: CombinedHighlight, el: HTMLElement) { | ||
el.createEl('div', { text: value.bookTitle }); | ||
el.createEl('small', { text: value.bookAuthor }); | ||
} | ||
|
||
onChooseSuggestion(item: CombinedHighlight, event: MouseEvent | KeyboardEvent) { | ||
this.plugin.saveHighlightsToVault([item]); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"1.0.0": "0.15.0", | ||
"1.0.1": "0.15.0", | ||
"1.0.2": "0.15.0" | ||
"1.0.2": "0.15.0", | ||
"1.1.0": "0.15.0" | ||
} |