diff --git a/.npmignore b/.npmignore deleted file mode 100644 index fdd33cc..0000000 --- a/.npmignore +++ /dev/null @@ -1 +0,0 @@ -**_test \ No newline at end of file diff --git a/README.md b/README.md index f085fd0..fd083df 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,27 @@ 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 lcoation +- Canvas support +- `.obsidian` folder support +- Improved file slug/id handling +- Plugin API + ## API -### `new Vault(vaultRootPath [, options])` +### `new Vault(vaultRootPath)` Create a new `Vault` object. Searches for markdown files in the given directory, loads, and parses frontmatter for each document. -#### Options - -| Option | Description | Default | -| ---------------- | ---------------------------------------------------------- | ------- | -| `ignorePatterns` | An optional array of globs to ignore when discovering docs | `[]` | - ### `vault.process(fn)` Process all documents in the vault. Each document is passed to the provided function. diff --git a/package.json b/package.json index b4ab6d5..dbd2020 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "@endeavorance/hammerstone", - "version": "0.1.3", + "name": "@foundry/hammerstone", + "version": "0.2.0", "description": "Load and manipulate Obsidian vault data", "type": "module", "exports": "./bin/hammerstone.js", diff --git a/src/_test/document.test.ts b/src/_test/document.test.ts index 9d15b57..da9954f 100644 --- a/src/_test/document.test.ts +++ b/src/_test/document.test.ts @@ -80,13 +80,13 @@ Testing! test("checking for tags", () => { const doc = getTestDocument(); - const taggedDoc = doc.vault.index["directory-subdirectory-i-have-tags"]!; + const taggedDoc = doc.vault.index["i-have-tags"]!; assert.equal(taggedDoc.hasTag("tags"), true); assert.equal(doc.hasTag("tags"), false); }); test("checking for taxonomy", () => { const doc = getTestDocument(); - const taggedDoc = doc.vault.index["directory-subdirectory-i-have-tags"]!; + const taggedDoc = doc.vault.index["i-have-tags"]!; assert.equal(taggedDoc.hasTaxonomy(["Directory", "Subdirectory"]), true); assert.equal(doc.hasTaxonomy(["Directory", "Subdirectory"]), false); }); diff --git a/src/_test/vault.test.ts b/src/_test/vault.test.ts index 635d600..043f451 100644 --- a/src/_test/vault.test.ts +++ b/src/_test/vault.test.ts @@ -4,7 +4,6 @@ import Vault from "../vault.js"; import path from "node:path"; const DOCS_IN_TEST_VAULT = 5; -const EXCLUDED_DOCS = 1; describe("Vault", () => { test("load a vault", () => { @@ -25,20 +24,9 @@ describe("Vault", () => { ); }); - test("ignored paths are not loaded into the vault", () => { - const vault = new Vault("./bin/_test/test-vault", { - ignorePatterns: ["**/Ignoreme/**"], - }); - assert.equal( - vault.size, - DOCS_IN_TEST_VAULT - EXCLUDED_DOCS, - "Unexpected number of documents in vault", - ); - }); - test("document tags are properly parsed", () => { const vault = new Vault("./bin/_test/test-vault"); - const taggedFile = vault.index["directory-subdirectory-i-have-tags"]; + const taggedFile = vault.index["i-have-tags"]; if (taggedFile === undefined) { assert.fail("Expected file with tags"); diff --git a/src/vault.ts b/src/vault.ts index 85bb2ac..babbeb3 100644 --- a/src/vault.ts +++ b/src/vault.ts @@ -8,13 +8,8 @@ import MarkdownDocument from "./document.js"; * @param ignorePatterns A glob pattern to ignore files for * @returns A promise which resolves as an array of laoded Documents */ -function loadVaultDocuments( - vault: Vault, - ignorePatterns: string[] = [], -): MarkdownDocument[] { - const discoveredMarkdownDocuments = globSync(`${vault.vaultPath}/**/*.md`, { - ignore: ignorePatterns, - }); +function loadVaultDocuments(vault: Vault): MarkdownDocument[] { + const discoveredMarkdownDocuments = globSync(`${vault.vaultPath}/**/*.md`); const markdownDocuments: MarkdownDocument[] = []; @@ -91,10 +86,6 @@ class VaultView { } } -interface VaultOptions { - ignorePatterns?: string[]; -} - export default class Vault { /** An array of all discovered Markdown documents */ documents: MarkdownDocument[] = []; @@ -111,14 +102,10 @@ export default class Vault { /** The number of documents in this vault */ readonly size: number = 0; - /** File patterns to ignore when discovering vault files */ - private ignorePatterns: string[] = []; - - constructor(vaultRootPath: string, options?: VaultOptions) { + constructor(vaultRootPath: string) { this.vaultPath = path.resolve(vaultRootPath); - this.ignorePatterns = options?.ignorePatterns ?? []; - const allFiles = loadVaultDocuments(this, this.ignorePatterns); + const allFiles = loadVaultDocuments(this); const allSlugs = allFiles.map((doc) => doc.slug); this.documents = allFiles;