Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
MatMoore committed May 26, 2024
1 parent 8cf133e commit 72aa05f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ PATH
obsidian-parser (0.7.0)
marcel (~> 0.3.1)
markly (~> 0.7.0)
tilt (~> 2.0, >= 2.0.8)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -77,6 +78,7 @@ GEM
standard-performance (1.1.1)
lint_roller (~> 1.1)
rubocop-performance (~> 1.18.0)
tilt (2.3.0)
unicode-display_width (2.4.2)

PLATFORMS
Expand Down
36 changes: 25 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Obsidian::Parser

A (work in progress) gem to parse notes created with the Obsidian note-taking tool.
A gem to parse notes created with the Obsidian note-taking tool.

## Installation

Expand All @@ -13,24 +13,38 @@ If bundler is not being used to manage dependencies, install the gem by executin
$ gem install obsidian-parser

## Usage
WARNING: This API is not yet finalized.

Parse the vault with:

```ruby
require 'obsidian/parser'
parser = Obsidian::Parser.new(Pathname.new("/path/to/vault"))
```

The return object allows you to iterate over all pages in the vault.

A page is any note or directory within the vault.

If a directory contains an `index.md`, that will be used as the directory content. Otherwise, the directory will have no content.

puts parser.index.notes
# -> [ Note(title: "README", slug: "README") ]
```ruby
puts parser.pages
# -> [ Page(title: "", slug: ""), Page(title: "Foo", slug: "Foo"), Page(title: "Bar", slug: "Foo/Bar") ]
```

You can fetch pages by their slug (the relative path, without a leading slash):

puts parser.index.directories
# -> [ Index(title: "Drafts", slug: "Drafts"),
# Index(title: "Projects", slug: "Projects") ]
```ruby
page = parser.index.find_in_tree("foo/bar")
```

### Generating HTML
Page objects have titles, slugs, and a callable to fetch their content:

```ruby
title = note.title
content = note.content
content.generate_html
page = parser.pages[-1]
title = page.title
markdown = page.content.call
html = page.generate_html
```

## Development
Expand Down
3 changes: 3 additions & 0 deletions lib/obsidian/parser/page.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# frozen_string_literal: true

# TODO: remove this dependency
require "tilt/erb"

module Obsidian
# A page in the vault corresponding to either a markdown document,
# or a directory containing other documents.
Expand Down
1 change: 1 addition & 0 deletions obsidian-parser.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Gem::Specification.new do |spec|

spec.add_dependency "markly", "~> 0.7.0"
spec.add_dependency "marcel", "~> 0.3.1"
spec.add_dependency "tilt", "~> 2.0", ">= 2.0.8"

# For more information and examples about making a new gem, check out our
# guide at: https://bundler.io/guides/creating_gem.html
Expand Down

0 comments on commit 72aa05f

Please sign in to comment.