Skip to content

Commit

Permalink
Further refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
MatMoore committed Jul 14, 2024
1 parent 39fe320 commit 61d63fe
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
15 changes: 12 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
## [Unreleased]

### Added

- Added support for wikilinks that embed files. These are rendered as images or links in the HTML content.
- Added method `Page#generate_html` to replace `Page#content.generate_html`, and removed the `MarkdownDocument` class. `Page#content` is now a callable that returns the markdown content.
- Added `Page#mark_referenced` and `Page#referenced?`

### Removed

- Added `Page#prune!` method to page objects, to remove non-referenced pages
- Added `Page#parse` method to expose `ParsedMarkdownDocument` objects
- Added `#frontmatter` to `ParsedMarkdownDocument`
- Added `Vault#mark_referenced`, `Vault#referenced?`, `Vault#prune!`

### Changed

Big refactor of `Page` class. This is now split into `Page`, `ParsedPage`, `Vault`, `Tree`.

`Vault` is now the main interface for adding and fetching pages.

## [0.7.0] - 2023-08-03

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

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

module Obsidian
PageNode = Struct.new(
Page = Struct.new(
:title,
:slug,
:last_modified,
Expand All @@ -10,7 +13,7 @@ module Obsidian
keyword_init: true
) do
# TODO: remove dependency on root and media root
# instead, MarkdownParser should be parsed a reference to the vault
# instead, MarkdownParser should be passed a reference to the vault
def parse(root:, media_root:, markdown_parser: MarkdownParser.new)
return nil if source_path.nil?

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

# TODO: remove this dependency
require "tilt/erb"
require_relative "tree"
require_relative "page"

Expand All @@ -21,7 +19,7 @@ module Obsidian
# encountering wikilink syntax.
class Vault
def self.create_root
node = PageNode.new(title: "", slug: "", last_modified: nil, content_type: nil, source_path: nil)
node = Page.new(title: "", slug: "", last_modified: nil, content_type: nil, source_path: nil)
tree = Tree.new(node, order_by: @ordering)
Vault.new(tree)
end
Expand Down Expand Up @@ -61,7 +59,7 @@ def add_page(slug, last_modified: nil, content_type: nil, media_root: nil, sourc
parent = path_components.reduce(@tree) do |subtree, anscestor_title|
anscestor_slug = Obsidian.build_slug(anscestor_title, subtree.value.slug)

value = PageNode.new(
value = Page.new(
slug: anscestor_slug,
title: anscestor_title.sub(/^\d+ - /, ""),
last_modified: last_modified,
Expand All @@ -73,7 +71,7 @@ def add_page(slug, last_modified: nil, content_type: nil, media_root: nil, sourc
end

# Create the page
value = PageNode.new(
value = Page.new(
slug: slug,
title: title,
last_modified: last_modified,
Expand Down

0 comments on commit 61d63fe

Please sign in to comment.