Skip to content

Commit 72aa05f

Browse files
committedMay 26, 2024
Update readme
1 parent 8cf133e commit 72aa05f

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed
 

‎Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ PATH
44
obsidian-parser (0.7.0)
55
marcel (~> 0.3.1)
66
markly (~> 0.7.0)
7+
tilt (~> 2.0, >= 2.0.8)
78

89
GEM
910
remote: https://rubygems.org/
@@ -77,6 +78,7 @@ GEM
7778
standard-performance (1.1.1)
7879
lint_roller (~> 1.1)
7980
rubocop-performance (~> 1.18.0)
81+
tilt (2.3.0)
8082
unicode-display_width (2.4.2)
8183

8284
PLATFORMS

‎README.md

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Obsidian::Parser
22

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

55
## Installation
66

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

1515
## Usage
16-
WARNING: This API is not yet finalized.
16+
17+
Parse the vault with:
1718

1819
```ruby
20+
require 'obsidian/parser'
1921
parser = Obsidian::Parser.new(Pathname.new("/path/to/vault"))
22+
```
23+
24+
The return object allows you to iterate over all pages in the vault.
25+
26+
A page is any note or directory within the vault.
27+
28+
If a directory contains an `index.md`, that will be used as the directory content. Otherwise, the directory will have no content.
2029

21-
puts parser.index.notes
22-
# -> [ Note(title: "README", slug: "README") ]
30+
```ruby
31+
puts parser.pages
32+
# -> [ Page(title: "", slug: ""), Page(title: "Foo", slug: "Foo"), Page(title: "Bar", slug: "Foo/Bar") ]
33+
```
34+
35+
You can fetch pages by their slug (the relative path, without a leading slash):
2336

24-
puts parser.index.directories
25-
# -> [ Index(title: "Drafts", slug: "Drafts"),
26-
# Index(title: "Projects", slug: "Projects") ]
37+
```ruby
38+
page = parser.index.find_in_tree("foo/bar")
2739
```
2840

29-
### Generating HTML
41+
Page objects have titles, slugs, and a callable to fetch their content:
42+
3043
```ruby
31-
title = note.title
32-
content = note.content
33-
content.generate_html
44+
page = parser.pages[-1]
45+
title = page.title
46+
markdown = page.content.call
47+
html = page.generate_html
3448
```
3549

3650
## Development

‎lib/obsidian/parser/page.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# frozen_string_literal: true
22

3+
# TODO: remove this dependency
4+
require "tilt/erb"
5+
36
module Obsidian
47
# A page in the vault corresponding to either a markdown document,
58
# or a directory containing other documents.

‎obsidian-parser.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
3232

3333
spec.add_dependency "markly", "~> 0.7.0"
3434
spec.add_dependency "marcel", "~> 0.3.1"
35+
spec.add_dependency "tilt", "~> 2.0", ">= 2.0.8"
3536

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

0 commit comments

Comments
 (0)