Skip to content

Commit

Permalink
Fix handling of index.md at the root level
Browse files Browse the repository at this point in the history
  • Loading branch information
MatMoore committed Jul 30, 2023
1 parent c3d5903 commit 75a80f2
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## [Unreleased]

## [0.5.1] - 2023-07-30
- Fix handling of `index.md` at the root level.

## [0.5.0] - 2023-07-30
- Fix ordering of `Page#children` so that index pages come first.
- Fix handling of `index.md` documents so that the slug reflects the directory path.
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
obsidian-parser (0.5.0)
obsidian-parser (0.5.1)
kramdown (~> 2.4)
kramdown-parser-gfm (~> 1.1)

Expand Down
6 changes: 5 additions & 1 deletion lib/obsidian/parser/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ def hash
# are added before their descendents.
def add_page(slug, last_modified: nil, content: nil)
path_components = slug.split("/")
raise ArgumentError, "Expecting non-empty slug" if path_components.empty?

if path_components.empty?
update_content(content: content, last_modified: last_modified)
return
end

title = path_components.pop

Expand Down
2 changes: 1 addition & 1 deletion lib/obsidian/parser/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Obsidian
class Parser
VERSION = "0.5.0"
VERSION = "0.5.1"
end
end
1 change: 1 addition & 0 deletions spec/example_vault/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Blahhhh
6 changes: 6 additions & 0 deletions spec/obsidian/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,10 @@
expect(animals.children.map(&:title)).not_to include("index")
expect(animals.content&.generate_html).to eq("<p>Animals page</p>\n")
end

it "adds index.md content to the root" do
content = parser.index.content

expect(content&.generate_html).to eq("<p>Blahhhh</p>\n")
end
end

0 comments on commit 75a80f2

Please sign in to comment.