### Local Development Setup Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/README.md Steps to clone the repository, install dependencies, and build the project for local development. This setup includes a watcher that recompiles code and reloads the test vault on changes. ```console foo@bar:~$ git clone git@github.com:blacksmithgu/obsidian-dataview.git foo@bar:~$ cd obsidian-dataview foo@bar:~/obsidian-dataview$ npm install foo@bar:~/obsidian-dataview$ npm run dev ``` -------------------------------- ### Manual Installation to Other Vaults Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/README.md Instructions for building the Dataview plugin and manually installing it into a specific Obsidian vault. This is useful for dogfooding the plugin in a real vault. ```bash foo@bar:~/obsidian-dataview$ npm run build foo@bar:~/obsidian-dataview$ ./scripts/install-built path/to/your/vault ``` -------------------------------- ### Markdown Frontmatter Example Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/README.md Example of Markdown frontmatter using YAML syntax to store metadata about a document. ```yaml --- alias: "document" last-reviewed: 2021-08-17 thoughts: rating: 8 reviewable: false --- ``` -------------------------------- ### Install Dataview Plugin Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/resources/develop-against-dataview.md Installs the Dataview plugin as a development dependency using npm. It also shows how to verify the installed version and install a specific version. ```bash npm install -D obsidian-dataview npm list obsidian-dataview npm install obsidian-dataview@0.5.64 ``` -------------------------------- ### Building Documentation Locally Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/README.md Steps to install MkDocs and its dependencies, then serve the documentation locally. This allows for live-reloading of documentation changes. ```bash foo@bar:~/obsidian-dataview$ pip3 install mkdocs mkdocs-material mkdocs-redirects foo@bar:~/obsidian-dataview$ cd docs foo@bar:~/obsidian-dataview/docs$ mkdocs serve ``` -------------------------------- ### Dataview Example Query Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/annotation/metadata-pages.md An example Dataview query to display the creation time, length, rating, and reviewed status of movies tagged with #movies. ```dataview TABLE file.ctime, length, rating, reviewed FROM #movies ``` -------------------------------- ### Dataview WHERE Clause Examples Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/data-commands.md Provides examples of the WHERE clause for filtering pages based on conditions. Includes filtering by modification time and checking for completion status and creation time. ```sql LIST WHERE file.mtime >= date(today) - dur(1 day) ``` ```sql LIST FROM #projects WHERE !completed AND file.ctime <= date(today) - dur(1 month) ``` -------------------------------- ### List Tasks in Uncompleted Projects Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/resources/examples.md Retrieves all tasks from files within the 'dataview' folder, useful for project management. ```sql TASK FROM "dataview" ``` -------------------------------- ### List MOBAs or CRPGs Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/resources/examples.md Lists games that are either MOBAs or CRPGs by querying tags associated with these genres. ```sql LIST FROM #games/mobas OR #games/crpg ``` -------------------------------- ### List Files with Dates in Title Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/resources/examples.md Lists files that have a date in their title (format YYYY-MM-DD) and sorts them by date in descending order. ```sql LIST file.day WHERE file.day SORT file.day DESC ``` -------------------------------- ### List Files Sorted by Modification Time Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/resources/examples.md Shows files from the 'books' folder, sorted by their last modification time in descending order. ```sql TABLE file.mtime AS "Last Modified" FROM "books" SORT file.mtime DESC ``` -------------------------------- ### List Example (YAML Frontmatter) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/annotation/types-of-metadata.md Provides an example of defining lists using standard YAML list syntax in the frontmatter. ```yaml --- key3: [one, two, three] key4: - four - five - six --- ``` -------------------------------- ### Dataview FLATTEN Command Examples Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/data-commands.md Demonstrates the FLATTEN command for expanding array fields into individual rows. Includes examples of flattening 'authors' and 'file.tasks' fields and comparing with alternative methods. ```sql TABLE authors FROM #LiteratureNote FLATTEN authors ``` ```sql table T.text as "Task Text" from "Scratchpad" flatten file.tasks as T where T.text ``` ```sql table filter(file.tasks.text, (t) => t) as "Task Text" from "Scratchpad" where file.tasks.text ``` -------------------------------- ### Dataview Query from Tag Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/sources.md Lists files tagged with '#homework'. This is a basic example of using a tag as a source in Dataview. ```dataview LIST FROM #homework ``` -------------------------------- ### Dataview FROM Command Examples Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/data-commands.md Demonstrates how to use the FROM command to select pages based on tags, folders, links, and negations. Supports combining sources with AND/OR and excluding sources with '-'. ```sql FROM #tag FROM "folder" FROM "path/to/file" FROM [[note]] FROM outgoing([[note]]) FROM #tag and "folder" FROM [[Food]] or [[Exercise]] FROM -#tag FROM #tag and -"folder" ``` -------------------------------- ### Show Games Sorted by Rating Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/resources/examples.md Displays games from the 'games' folder, showing 'Time Played', 'Length', and 'Rating', sorted by rating in descending order. ```sql TABLE time-played AS "Time Played", length AS "Length", rating AS "Rating" FROM "games" SORT rating DESC ``` -------------------------------- ### Link Examples Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/annotation/types-of-metadata.md Illustrates the syntax for creating Obsidian links, including simple page links and links with custom display text. ```markdown Example:: [[A Page]] Example:: [[Some Other Page|Render Text]] ``` -------------------------------- ### Custom View Script Example Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md An example of a custom view script (`view1.js`) that logs messages and calls a function with input arguments. This script is intended to be called using `dv.view()`. ```javascript console.log(`Loading view1`); function foo(...args) { console.log('foo is called with args', ...args); } foo(input) ``` -------------------------------- ### Inline JS Expression Example Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/README.md An example of an inline JavaScript expression that displays the modification time of the current file. ```javascript `$= dv.current().file.mtime` ``` -------------------------------- ### SQL Query Structure Example Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/differences-to-sql.md A typical SQL query structure for comparison, showing how clauses like SELECT, FROM, WHERE, and ORDER BY define the query's logic. ```sql SELECT file_mtime AS "Last Modified" FROM notes WHERE file_tags LIKE '%#project%' ORDER BY file_mtime DESC LIMIT 5; ``` -------------------------------- ### Dataview LIMIT Command Example Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/data-commands.md Shows the basic usage of the LIMIT command to restrict the number of results returned by a query. ```sql LIMIT 5 ``` ```sql LIMIT 5 SORT date ASCENDING ``` -------------------------------- ### List Fiction Content Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/test-vault/Books.md This Dataview query lists all pages that have a link to the 'Fiction' page. It helps in organizing and displaying related fiction content. ```dataview list from [[Fiction]] ``` -------------------------------- ### Example Markdown Page with Metadata Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/annotation/metadata-pages.md A sample Markdown page demonstrating the use of YAML frontmatter, tags, and inline fields for metadata. ```markdown --- genre: "action" reviewed: false --- # Movie X #movies **Thoughts**:: It was decent. **Rating**:: 6 [mood:: okay] | [length:: 2 hours] ``` -------------------------------- ### Dataview Query Language (DQL) Example Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/dql-js-inline.md Demonstrates a basic DQL query to display a table of ratings and summaries from pages tagged with #games, sorted by rating in descending order. ```dataview ```dataview TABLE rating AS "Rating", summary AS "Summary" FROM #games SORT rating DESC ``` ``` -------------------------------- ### Dataview FROM Statement Examples Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/structure.md Shows how to use the FROM data command in Dataview queries to filter pages based on folders, tags, or combinations thereof. ```dataview ```dataview LIST FROM "Books" ``` ``` ```dataview ```dataview LIST FROM #status/open OR #status/wip ``` ``` ```dataview ```dataview LIST FROM (#assignment AND "30 School") OR ("30 School/32 Homeworks" AND outgoing([[School Dashboard Current To Dos]])) ``` ``` -------------------------------- ### Basic Dataview LIST Query Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/index.md A fundamental Dataview query that lists all files in the vault. This serves as a starting point for understanding DQL syntax. ```dataview ```dataview LIST ``` ``` -------------------------------- ### Duration Examples Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/annotation/types-of-metadata.md Demonstrates various formats for specifying durations, including abbreviations, multiple units, and comma separators. ```markdown Example:: 7 hours Example:: 16days Example:: 4min Example:: 6hr7min Example:: 9 years, 8 months, 4 days, 16 hours, 2 minutes Example:: 9 yrs 8 min ``` -------------------------------- ### Markdown with YAML Frontmatter Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/index.md Example of a Markdown file structured with YAML frontmatter to include metadata such as author and publication year, along with tags. ```markdown --- author: "Edgar Allan Poe" published: 1845 tags: poems --- # The Raven Once upon a midnight dreary, while I pondered, weak and weary, Over many a quaint and curious volume of forgotten loreโ€” ``` -------------------------------- ### Object Example (YAML Frontmatter) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/annotation/types-of-metadata.md Demonstrates the structure of an object defined in YAML frontmatter, including nested lists. ```yaml --- obj: key1: "Val" key2: 3 key3: - "List1" - "List2" - "List3" --- ``` -------------------------------- ### Markdown with Inline Fields Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/index.md Example of a Markdown file using inline fields for metadata, demonstrating the `[key:: value]` syntax for author and publication date. ```markdown #poems # The Raven From [author:: Edgar Allan Poe], written in (published:: 1845) Once upon a midnight dreary, while I pondered, weak and weary, Over many a quaint and curious volume of forgotten loreโ€” ``` -------------------------------- ### List Non-Fiction Content Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/test-vault/Books.md This Dataview query lists all pages that have a link to the 'Non-Fiction' page. It's useful for organizing and displaying related non-fiction content. ```dataview list from [[Non-Fiction]] ``` -------------------------------- ### Dataview JS Example Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/dql-js-inline.md Illustrates how to use the Dataview JavaScript API to query pages, group them by genre, and display the file names of books within each genre that have a rating of 7 or higher. ```javascript ```dataviewjs let pages = dv.pages("#books and -#books/finished").where(b => b.rating >= 7); for (let group of pages.groupBy(b => b.genre)) { dv.header(3, group.key); dv.list(group.rows.file.name); } ``` ``` -------------------------------- ### YAML Frontmatter Link Example Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/annotation/types-of-metadata.md Demonstrates how to correctly quote links within YAML frontmatter to ensure valid parsing. ```yaml --- parent: "[[parentPage]]" --- ``` -------------------------------- ### Dataview Query Types Examples Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/structure.md Demonstrates the usage of different Dataview Query Types: LIST for pages, TASK for tasks, CALENDAR for date-based views, and TABLE for structured data. ```dataview ```dataview LIST ``` ``` ```dataview ```dataview TASK ``` ``` ```dataview ```dataview CALENDAR file.cday ``` ``` ```dataview ```dataview TABLE due, file.tags AS "tags", average(working-hours) ``` ``` -------------------------------- ### Dataview GROUP BY Command Examples Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/data-commands.md Explains the GROUP BY command for grouping query results by a field. Shows how to group by a field or a computed field and use field swizzling on the 'rows' array. ```sql GROUP BY field ``` ```sql GROUP BY (computed_field) AS name ``` -------------------------------- ### DQL Query Structure Example Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/differences-to-sql.md Illustrates the sequential execution and data manipulation in DQL, where each line processes the result set from the previous one. This contrasts with SQL's clause-based approach. ```dql TABLE file.mtime AS "Last Modified" FROM "notes" WHERE contains(file.tags, "#project") SORT file.mtime DESC LIMIT 5 ``` -------------------------------- ### Duration Literals (Combinations) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/literals.md Provides examples of combined duration literals, showing different syntaxes for specifying multiple time units. ```dataview dur(1 s, 2 m, 3 h) dur(1 s 2 m 3 h) dur(1s 2m 3h) dur(1second 2min 3h) ``` -------------------------------- ### Inline DQL Examples Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/dql-js-inline.md Shows various ways to use inline DQL to display single values, such as the current file name, modification time, metadata fields, and calculations based on dates and task completion. ```dataview `= this.file.name` ``` ```dataview `= this.file.mtime` ``` ```dataview `= this.someMetadataField` ``` ```dataview `= [[secondPage]].file.name` ``` ```dataview `= [[secondPage]].file.mtime` ``` ```dataview `= [[secondPage]].someMetadataField` ``` ```dataview Assignment due in `= this.due - date(today)` ``` ```dataview Final paper due in `= [[Computer Science Theory]].due - date(today)` ``` ```dataview ๐Ÿƒโ€โ™‚๏ธ Goal reached? `= choice(this.steps > 10000, "YES!", "**No**, get moving!")` ``` ```dataview You have `= length(filter(link(dateformat(date(today), "yyyy-MM-dd")).file.tasks, (t) => !t.completed))` tasks to do. `= choice(date(today).weekday > 5, "Take it easy!", "Time to get work done!")` ``` -------------------------------- ### Metadata Field Examples Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/annotation/add-metadata.md Demonstrates how various metadata keys are sanitized by Dataview, including handling of spaces, capitalization, and formatting tokens. It also shows the data type of the associated values. ```markdown | Metadata Key | Sanitized Metadata key | Value | Data Type of Value | | ----------- | ------------------------|----------- | ----------- | | `Basic Field` | `basic-field` | Some random Value | Text | | `Bold Field` | `bold-field` | Nice! | Text | | `rating` | - | 9 | Number | | `mood` | - | acceptable | Text | | `due` | - | Date Object for 2022-04-05 | Date | | `longKeyIDontNeedWhenReading` | `longkeyidontneedwhenreading` | key | Text | ``` -------------------------------- ### Dataview SORT Command Examples Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/data-commands.md Illustrates the SORT command for ordering query results by one or more fields. Supports ascending and descending order and multi-field sorting for tie-breaking. ```sql SORT date [ASCENDING/DESCENDING/ASC/DESC] ``` ```sql SORT field1 [ASCENDING/DESCENDING/ASC/DESC], ..., fieldN [ASC/DESC] ``` -------------------------------- ### General Dataview Literals Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/literals.md Provides examples of various general literals in Dataview Query Language, including numbers, text, links, lists, objects, dates, and durations. ```dataview 0 1337 -200 "The quick brown fox jumps over the lazy dog" [[Science]] [[]] [1, 2, 3] [[1, 2],[3, 4]] { a: 1, b: 2 } date(2021-07-14) dur(2 days 4 hours) ``` -------------------------------- ### Group Books by Genre and Sort by Rating Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-examples.md This snippet demonstrates how to group pages tagged with '#book' by their 'genre' property. It then renders a table for each genre, displaying the book's name, time read, and rating, sorted in descending order by rating. It utilizes the Dataview rendering API. ```js for (let group of dv.pages("#book").groupBy(p => p.genre)) { dv.header(3, group.key); dv.table(["Name", "Time Read", "Rating"], group.rows .sort(k => k.rating, 'desc') .map(k => [k.file.link, k["time-read"], k.rating])) } ``` -------------------------------- ### Markdown Inline Fields Example Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/README.md Demonstrates how to use Dataview's inline field syntax within a Markdown document, including fields on the same line and hiding keys. ```markdown # Markdown Page Basic Field:: Value **Bold Field**:: Nice! You can also write [field:: inline fields]; multiple [field2:: on the same line]. If you want to hide the (field3:: key), you can do that too. ``` -------------------------------- ### Styling Dataview Tables with CSS Snippets Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/resources/faq.md Provides examples of using CSS snippets to style Dataview tables. It covers applying styles based on a `cssclasses` property and using a tag-based selector for more targeted styling. ```css .myTable dataview.table { background-color: green } ``` ```css [href="#myId"] { display: none; /* Hides the tag from the table view */ } table:has([href="#myId"]) { /* Style your table as you like */ background-color: #262626; & tr:nth-child(even) td:first-child{ background-color: #3f3f3f; } } ``` -------------------------------- ### Find All Directly and Indirectly Linked Pages Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-examples.md This JavaScript code implements a depth-first search algorithm to find all pages that are directly or indirectly linked to the current page or a specified page. It uses a Set to keep track of visited pages and a stack for the traversal. The result is an array of metadata for all linked pages. ```js let page = dv.current().file.path; let pages = new Set(); let stack = [page]; while (stack.length > 0) { let elem = stack.pop(); let meta = dv.page(elem); if (!meta) continue; for (let inlink of meta.file.inlinks.concat(meta.file.outlinks).array()) { console.log(inlink); if (pages.has(inlink.path)) continue; pages.add(inlink.path); stack.push(inlink.path); } } // Data is now the file metadata for every page that directly OR indirectly links to the current page. let data = dv.array(Array.from(pages)).map(p => dv.page(p)); ``` -------------------------------- ### List Examples (Inline Fields) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/annotation/types-of-metadata.md Shows how to define lists using comma-separated values in inline fields, emphasizing the need for quotes around text values. ```markdown Example1:: 1, 2, 3 Example2:: "yes", "or", "no" ``` -------------------------------- ### Get Specific Page Object by Path Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Retrieves a specific page object by its path or link. Handles automatic link resolution and extension detection. ```javascript dv.page("Index") ``` ```javascript dv.page("books/The Raisin.md") ``` -------------------------------- ### Dataview Date Access and Formatting Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/test-vault/blog/2020-08-08-an-earlier-post.md This snippet demonstrates accessing date properties from the frontmatter of an Obsidian note using Dataview. It also shows how to use the `localTime` function to display dates in the user's local time zone. ```dataview = this.start_date = this.end_date = this.another_date = localTime(this.fourth_date) ``` -------------------------------- ### Dataview Task Query Example Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/test-vault/tasks/Sorted Tasks.md This Dataview query retrieves tasks, filters them based on a property 'p', and sorts the results in ascending order of 'p'. It demonstrates basic Dataview query syntax for task management within Obsidian. ```dataview task where p sort p asc ``` -------------------------------- ### Sorted Tasks Dataview Query Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/test-vault/tasks/example tasks.md Displays tasks sorted by a specific field, such as due date or priority. This example sorts by due date in ascending order. ```dataview LIST FROM #task SORT dueDate ASC ``` -------------------------------- ### Dataview API Introduction Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/index.md Provides an entry point to the Dataview API, allowing users to run arbitrary JavaScript against their indexed data for custom utilities and advanced data manipulation. ```APIDOC Dataview API Description: The Dataview API allows you to interact with your indexed data using JavaScript. You can query data, manipulate it, and display it within your Obsidian notes. Usage: To use the Dataview API, you typically write JavaScript code within a Dataview code block in your Obsidian notes. Example: ```javascript // Query for all pages tagged with 'books' and display their titles const books = dv.pages('#books'); dv.list(books.file.name); ``` Key Features: - Access to indexed data (frontmatter, inline fields, implicit fields). - Functions for querying, filtering, sorting, and grouping data. - Ability to render various data types (lists, tables, tasks). - Integration with Obsidian's file system. Refer to the official Dataview documentation for a comprehensive list of API functions and their usage. ``` -------------------------------- ### Dataview Text Field Example Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/annotation/types-of-metadata.md A basic example of a Text field in Dataview, where any string that does not match a more specific type is treated as plain text. ```markdown Example:: This is some normal text. ``` -------------------------------- ### Inline Dataview JS Example Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/dql-js-inline.md Demonstrates how to create an inline JavaScript query in Dataview to display the modification time of the current file. This query uses the `dv` object, which is available in all DataviewJS contexts. ```javascript `$= dv.current().file.mtime` ``` -------------------------------- ### Dataview Date Field Examples (ISO8601) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/annotation/types-of-metadata.md Provides examples of Date fields using ISO8601 notation, showcasing different levels of detail from year-month to full date-time with timezone offset. Dataview automatically parses these into Date objects. ```markdown Example:: 2021-04 Example:: 2021-04-18 Example:: 2021-04-18T04:19:35.000 Example:: 2021-04-18T04:19:35.000+06:30 ``` -------------------------------- ### String Starts With Function Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Checks if a string begins with a specified prefix. ```dataview startswith(string, prefix) Example: startswith("yes", "ye") = true startswith("path/to/something", "path/") = true startswith("yes", "no") = false ``` -------------------------------- ### Dataview Query from Folder Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/sources.md Displays the creation time and status of files within the 'projects/brainstorming' folder and its subfolders. Demonstrates folder-based sourcing. ```dataview TABLE file.ctime, status FROM "projects/brainstorming" ``` -------------------------------- ### Duration Literals (Years) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/literals.md Shows examples of duration literals in years using 'yr', 'yrs', and 'year'. ```dataview dur(1 yr) dur(3 yrs) dur(1 year) dur(3 years) ``` -------------------------------- ### Create a List of Files Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/test-vault/example lists.md This Dataview query generates a list of all files located in the 'recipes' folder. It's a fundamental way to display collections of notes. ```dataview list from "recipes" ``` -------------------------------- ### Dataview Boolean Field Examples Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/annotation/types-of-metadata.md Demonstrates the usage of Boolean fields in Dataview, which can only hold the values 'true' or 'false'. ```markdown Example:: true Example:: false ``` -------------------------------- ### Date and Duration Calculations Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/annotation/types-of-metadata.md Shows how to perform calculations by adding durations to dates and subtracting dates to get durations. ```dataview departure:: 2022-10-07T15:15 length of travel:: 1 day, 3 hours **Arrival**: `= this.departure + this.length-of-travel` ``` ```dataview release-date:: 2023-02-14T12:00 `= this.release-date - date(now)` until release!! ``` -------------------------------- ### Pull Request Preparation Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/README.md Commands to run before creating a pull request, including development build, code formatting checks, and running tests. The formatting step is conditional on the check reporting issues. ```console foo@bar:~$ npm run dev foo@bar:~$ npm run check-format foo@bar:~$ npm run format foo@bar:~$ npm run test ``` -------------------------------- ### Task Formatting and Metadata Extraction Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/test-vault/tasks/checklist.md Demonstrates various ways to format tasks in Obsidian notes and how Dataview can extract metadata like completion dates, due dates, priorities, and annotations. It also shows how tags are inherited from pages and tasks. ```markdown - [x] Normal task, tags inherited from page [completion:: 2021-10-23] * [ ] Task with a #tag, adds to inherited page tags * [ ] Task that inherits tag from above and page tags * [x] Completed task โœ… 2021-08-06 ๐Ÿ“… 2021-08-07 * [x] Completed task [completion::2021-08-06] [due::2021-08-07] * [ ] task with [annotation::arbitrary] [completion:: 2021-10-23] * [ ] Scheduled task ๐Ÿ“… 2021-08-07 * [ ] Task that overrides creation date of file โž• 2021-08-06 * [ ] Repeating task ๐Ÿ”Mondays * [ ] #tell @person some important thing [p::1] * [x] a less important thing [p::2] * [ ] another important thing [p::1] #page-tag ## Section - [ ] additional task with a block id ^block-id - [ ] additional task, should link to header ``` -------------------------------- ### Array Slice Function Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Returns a shallow copy of a portion of an array. Elements are selected from a start index to an end index (exclusive). ```dataview slice(array, [start, [end]]) Example: slice([1, 2, 3, 4, 5], 3) = [4, 5] slice(["ant", "bison", "camel", "duck", "elephant"], 0, 2) = ["ant", "bison"] slice([1, 2, 3, 4, 5], -2) = [4, 5] slice(someArray) => a copy of someArray ``` -------------------------------- ### String Substring Extraction Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Extracts a portion of a string based on start and end indices. If the end index is omitted, it extracts to the end of the string. ```js substring(string, start, [end]) // Example: substring("hello", 0, 2) = "he" substring("hello", 2, 4) = "ll" substring("hello", 2) = "llo" substring("hello", 0) = "hello" ``` -------------------------------- ### Get Page Paths by Source Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Returns a data array containing only the paths of pages that match the provided source query. ```javascript dv.pagePaths("#books") ``` -------------------------------- ### Dataview Query from Links (Incoming) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/sources.md Lists files that link to the current file. Uses the special `[[]]` syntax to reference incoming links. ```dataview LIST FROM [[]] ``` -------------------------------- ### Date Literal in Comparison Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/literals.md Example of using a date literal (`date(yesterday)`) in a WHERE clause to filter tasks that are not completed and are due yesterday. ```dataview TASK WHERE !completed AND file.day = date(yesterday) ``` -------------------------------- ### Dataview Number Field Examples Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/annotation/types-of-metadata.md Illustrates how Dataview recognizes integers, floating-point numbers, and negative numbers. These are stored and can be used in numerical operations. ```markdown Example:: 6 Example:: 2.4 Example:: -80 ``` -------------------------------- ### Duration Literals (Hours) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/literals.md Provides examples of duration literals in hours using abbreviations like 'h', 'hr', and full words 'hour'. ```dataview dur(1 h) dur(3 h) dur(1 hr) dur(3 hrs) dur(1 hour) dur(3 hours) ``` -------------------------------- ### Dataview Query from Specific File Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/sources.md Lists items from a specific file located at '30 Hobbies/Games/Dashboard'. Shows how to reference a single file as a source. ```dataview LIST WITHOUT ID next-in-line FROM "30 Hobbies/Games/Dashboard" ``` -------------------------------- ### Reusable Javascript Queries with dv.view Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/resources/faq.md Illustrates how to create reusable Javascript Queries using the `dv.view` function, which is useful for saving calculations or complex logic within Dataview. ```javascript dv.view("../api/code-reference.md#dvviewpath-input") ``` -------------------------------- ### Dataview Arithmetic Operations Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/expressions.md Shows how to use arithmetic operators (+, -, *, /) to compute values from fields in Dataview queries. Includes examples of calculating differences and ratios. ```dataview TABLE start, end, (end - start) - dur(8 h) AS "Overtime" FROM #work ``` ```dataview TABLE hrs / 24 AS "days" FROM "30 Projects" ``` -------------------------------- ### Table Query with FROM and Aliases Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/structure.md Displays a table of recipe types and portions from pages tagged with '#recipes'. It uses the FROM command and column aliasing. ```dataview TABLE recipe-type AS "type", portions, length FROM #recipes ``` -------------------------------- ### Dataview Query for Frontmatter Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/annotation/add-metadata.md An example Dataview query to filter notes based on metadata defined in the Frontmatter, specifically targeting the nested 'thoughts.rating' field. ```dataview ```dataview LIST WHERE thoughts.rating = 8 ``` ``` -------------------------------- ### Query Pages with Complex Sources Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Demonstrates querying pages using complex source logic, including tag inclusion/exclusion and folder/tag combinations. ```javascript dv.pages("#yes or -#no") ``` ```javascript dv.pages('"folder" or #tag') ``` -------------------------------- ### Get Current Page Information Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Retrieves information for the page where the script is currently executing using `dv.current()`. This is equivalent to calling `dv.page()` on the current page. ```javascript dv.current() ``` -------------------------------- ### Sort by Creation Time and Limit Results Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/structure.md Lists the 10 most recently created pages tagged with '#status/open'. This showcases the FROM, SORT, and LIMIT commands. ```dataview LIST FROM #status/open SORT file.ctime DESC LIMIT 10 ``` -------------------------------- ### Display Cuisine and Stove Needs Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/test-vault/example tables.md This Dataview query displays 'cuisine' and 'needsStove' (aliased as 'Needs Stove') for files in the 'recipes' folder. It's useful for organizing and viewing recipe-related metadata. ```dataview table cuisine as Cuisine, needsStove as "Needs Stove" from "recipes" ``` -------------------------------- ### Dataview Comparison Operations Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/expressions.md Illustrates the use of comparison operators (<, >, <=, >=, =, !=) in Dataview queries to filter data based on conditions. Includes examples for dates and status checks. ```dataview LIST FROM "Games" WHERE price > 10 ``` ```dataview TASK WHERE due <= date(today) ``` ```dataview LIST FROM #homework WHERE status != "done" ``` ```dataview TASK WHERE typeof(due) = "date" AND due <= date(today) ``` -------------------------------- ### Table Query with Folder FROM, WHERE, and SORT Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/structure.md Lists file creation times, appointment types, times, and follow-ups from a specific folder, filtering by the presence of 'follow-ups' and sorting by appointment time. ```dataview TABLE file.ctime, appointment.type, appointment.time, follow-ups FROM "30 Protocols/32 Management" WHERE follow-ups SORT appointment.time ``` -------------------------------- ### Duration Literal in Comparison Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/literals.md Demonstrates using a duration literal (`dur(2 days)`) in a WHERE clause to compare time differences between file start and end dates. ```dataview LIST WHERE end - start > dur(2 days) ``` -------------------------------- ### Inline Fields - Basic Syntax Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/annotation/add-metadata.md Shows the basic syntax for inline fields in Markdown, using `Key:: Value` on its own line or with bolded keys. This allows for natural annotation within the text. ```markdown # Markdown Page Basic Field:: Some random Value **Bold Field**:: Nice! ``` -------------------------------- ### Using Dataview Types in Plugins Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/README.md Information on how to integrate Dataview's TypeScript typings into your own Obsidian plugins. The typings are published on NPM under the blacksmithgu/obsidian-dataview package. ```typescript // Install Dataview typings npm install blacksmithgu/obsidian-dataview // Example usage in your plugin (conceptual) import DataviewAPI from 'obsidian-dataview'; // Assuming you have access to the Dataview API instance // const dataview = this.app.plugins.getPlugin('dataview')?.api; // if (dataview) { // // Use Dataview API methods // } ``` -------------------------------- ### Duration Literals (Minutes) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/literals.md Illustrates defining duration literals in minutes using keywords like 'm', 'min', and 'minute'. ```dataview dur(1 m) dur(3 m) dur(1 min) dur(3 mins) dur(1 minute) dur(3 minutes) ``` -------------------------------- ### Lambda Expressions for Data Transformation Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/expressions.md Shows examples of lambda expressions used with Dataview's `map` and `reduce` operators for advanced data transformations, such as checking task completion status. ```dataview CALENDAR file.day FLATTEN all(map(file.tasks, (x) => x.completed)) AS "allCompleted" WHERE !allCompleted ``` -------------------------------- ### Basic DQL Query Structure Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/structure.md Illustrates the general format of a Dataview Query Language (DQL) query, including the mandatory Query Type and optional FROM and other data commands. ```dataview ```dataview FROM ... ``` ```