# Hammerstone Load and manipulate Obsidian vault data ## Early Release This project is in early development. It is not yet fully featured. ### Roadmap Features that have yet to be implemented but are planned: - Create / Delete documents - Custom write location - Canvas support - `.obsidian` folder support - Improved file slug/id handling - Plugin API ## Example Usage ```javascript import { Vault } from "@foundry/hammerstone"; const vault = new Vault("./my-vault"); vault.process((document) => { document.setFrontmatter({ "Last Processed": Date.now() }); }); vault.write(); ``` ## API ### `new Vault(vaultRootPath)` Create a new `Vault` object. Searches for markdown files in the given directory, loads, and parses frontmatter for each document. ### `vault.process(fn)` Process all documents in the vault. Each document is passed to the provided function. Returns a reference to the vault to allow for chaining of document processing flows. ### `vault.scope(fn)` Returns a `VaultView` containing only the documents which the provided function returns a truthy value for (similar to `Array.filter()`). A `VaultView` has the `.process()` function just as a `Vault` does. You can also call `.unscope()` on a `VaultView` which returns a reference to the original vault, allowing you to chain processing flows which dive in and out of different filtered scopes. ### `vault.write()` Write all vault documents back to disk. ### `vault.documents` (Property) An array of all documents in this vault ### `vault.index` (Property) A map of document slugs to the document itself ### `new MarkdownDocument(filePath, vault)` A `MarkdownDocument` object represents a single document in the `Vault`. Generally, the `Vault` itself handles creating these objects, which can be accessed via the `.documents` or `.index` properties on the `Vault`. ### `markdownDocument.setMarkdown(markdownContent)` Set the markdown content of this document (separately from the YAML frontmatter) ### `markdownDocument.setFrontmatter(frontmatterShape)` Set the frontmatter content of this document (separately from the markdown) ### `markdownDocument.setContent(newContent)` Set the full text content of this document (raw YAML frontmatter and markdown) ### `markdownDocument.hasTag(tag)` Check if this document is tagged with the given tag ### `markdownDocument.hasTaxonomy(dirs)` Check if this document exists in the given directory structure as an array of directory names ### `markdownDocument.revert()` Revert any changes to this document back to its original loaded content ### `markdownDocument.write()` Write this file back to disk ### `markdownDocument.markdown` (Property) The markdown contents of this document ### `markdownDocument.frontmatter` (Property) The frontmatter contents of this document ### `markdownDocument.content` (Property) The full content of this document