Search CTRL + K

up:: Obsidian Plugins
tags:: #obsidian #plugin #query

Obsidian Plugin - DataView

Overview

Treat your Obsidian Vault as a database which you can query from. Provides a JavaScript API and pipeline-based query language for filtering, sorting, and extracting data from Markdown pages. See the Examples section below for some quick examples, or the full reference for all the details.

Usage

Preferences

Important

I configured inline query prefix to be "==", instead of default "="

Tricks


- [Get list of commands sorted by Command ID](https://forum.obsidian.md/t/dataviewjs-snippet-showcase/17847/37): 

	```js
	
	const getNestedObject = (nestedObj, pathArr) => {
	    return pathArr.reduce((obj, key) =>
	        (obj && obj[key] !== 'undefined') ? obj[key] : undefined, nestedObj);
	}
	
	function hilite(keys, how) {
	    // need to check if existing key combo is overridden by undefining it
	    if (keys && keys[1][0] !== undefined) {
	        return how + keys.flat(2).join('+').replace('Mod', 'Ctrl') + how;
	    } else {
	        return how + '–' + how;
	    }
	}
	
	function getHotkey(arr, highlight=true) {
	    let hi = highlight ? '**' : '';
	    let defkeys = arr.hotkeys ? [[getNestedObject(arr.hotkeys, [0, 'modifiers'])],
	    [getNestedObject(arr.hotkeys, [0, 'key'])]] : undefined;
	    let ck = app.hotkeyManager.customKeys[arr.id];
	    var hotkeys = ck ? [[getNestedObject(ck, [0, 'modifiers'])], [getNestedObject(ck, [0, 'key'])]] : undefined;
	    return hotkeys ? hilite(hotkeys, hi) : hilite(defkeys, '');
	}
	
	let cmds = dv.array(Object.entries(app.commands.commands))
	    .sort(v => v[1].id, 'asc');
	
	dv.paragraph(cmds.length + " commands currently enabled; " +
	    "non-default hotkeys <strong>bolded</strong>.<br><br>");
	
	dv.table(["Command ID", "Name in current locale", "Hotkeys"],
	  cmds.map(v => [
	    v[1].id,
	    v[1].name,
	    getHotkey(v[1]),
	    ])
	  );
regexreplace(string(123456), "\B(?=(\d{3})+(?!\d))", ",")

Resources