generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(DataviewNotes): ✨ Dataview Notes! Use
BC-dataview-note: query
…
…to run any valid Dataview from-query and add Breadcrumbs to all matching notes
- Loading branch information
1 parent
63f062e
commit bc2681a
Showing
7 changed files
with
125 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
"NamingNotes", | ||
"Codeblock", | ||
"TreeView", | ||
"impliedRelations" | ||
"impliedRelations", | ||
"DataviewNotes" | ||
] | ||
} |
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,61 @@ | ||
import type { MultiGraph } from "graphology"; | ||
import { Notice } from "obsidian"; | ||
import { BC_DV_NOTE, BC_DV_NOTE_FIELD, DATAVIEW_MISSING } from "../constants"; | ||
import type { dvFrontmatterCache } from "../interfaces"; | ||
import type BCPlugin from "../main"; | ||
import { | ||
getSourceOrder, | ||
getTargetOrder, | ||
populateMain, | ||
} from "../Utils/graphUtils"; | ||
import { getFields } from "../Utils/HierUtils"; | ||
import { getDVApi, getDVBasename } from "../Utils/ObsidianUtils"; | ||
|
||
export function addDataviewNotesToGraph( | ||
plugin: BCPlugin, | ||
eligableAlts: dvFrontmatterCache[], | ||
frontms: dvFrontmatterCache[], | ||
mainG: MultiGraph | ||
) { | ||
const { settings } = plugin; | ||
const { userHiers, dataviewNoteField } = settings; | ||
const dv = getDVApi(plugin); | ||
if (!dv) { | ||
new Notice(DATAVIEW_MISSING); | ||
} | ||
|
||
const fields = getFields(userHiers); | ||
|
||
eligableAlts.forEach((altFile) => { | ||
const basename = getDVBasename(altFile.file); | ||
const query = altFile[BC_DV_NOTE] as string; | ||
|
||
let field = | ||
(altFile[BC_DV_NOTE_FIELD] as string) ?? (dataviewNoteField || fields[0]); | ||
|
||
let targets: dvFrontmatterCache[] = []; | ||
try { | ||
targets = dv.pages(query).values; | ||
} catch (er) { | ||
new Notice(`${query} is not a valid Dataview from-query`); | ||
console.log(er); | ||
} | ||
|
||
for (const target of targets) { | ||
const targetBN = getDVBasename(target.file); | ||
const sourceOrder = getSourceOrder(altFile); | ||
const targetOrder = getTargetOrder(frontms, targetBN); | ||
|
||
populateMain( | ||
settings, | ||
mainG, | ||
basename, | ||
field, | ||
targetBN, | ||
sourceOrder, | ||
targetOrder, | ||
true | ||
); | ||
} | ||
}); | ||
} |
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,33 @@ | ||
import { DropdownComponent, Setting } from "obsidian"; | ||
import type BCPlugin from "../main"; | ||
import { refreshIndex } from "../refreshIndex"; | ||
import { getFields } from "../Utils/HierUtils"; | ||
import { fragWithHTML, subDetails } from "./BreadcrumbsSettingTab"; | ||
|
||
export function addDataviewSettings( | ||
plugin: BCPlugin, | ||
alternativeHierarchyDetails: HTMLDetailsElement | ||
) { | ||
const { settings } = plugin; | ||
const { userHiers } = settings; | ||
const fields = getFields(userHiers); | ||
const dvDetails = subDetails("Dataview Notes", alternativeHierarchyDetails); | ||
|
||
new Setting(dvDetails) | ||
.setName("Default Tag Note Field") | ||
.setDesc( | ||
fragWithHTML( | ||
"By default, Dataview notes use the first field in your hierarchies (usually an <code>↑</code> field). Choose a different one to use by default, without having to specify <code>BC-dataview-note-field: {field}</code>.</br>If you don't want to choose a default, select the blank option at the bottom of the list." | ||
) | ||
) | ||
.addDropdown((dd: DropdownComponent) => { | ||
const options = {}; | ||
fields.forEach((field) => (options[field] = field)); | ||
dd.addOptions(Object.assign(options, { "": "" })); | ||
dd.onChange(async (field) => { | ||
settings.dataviewNoteField = field; | ||
await plugin.saveSettings(); | ||
await refreshIndex(plugin); | ||
}); | ||
}); | ||
} |
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