From 61d63fe6ffcf1b6ba41a98915aa19578a6b796aa Mon Sep 17 00:00:00 2001 From: Mat Moore Date: Sun, 14 Jul 2024 21:39:05 +0100 Subject: [PATCH] Further refactoring --- CHANGELOG.md | 15 ++++++++++++--- lib/obsidian/parser/page.rb | 7 +++++-- lib/obsidian/parser/vault.rb | 8 +++----- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 110e110..0921db5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/obsidian/parser/page.rb b/lib/obsidian/parser/page.rb index 4556592..09fe78f 100644 --- a/lib/obsidian/parser/page.rb +++ b/lib/obsidian/parser/page.rb @@ -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, @@ -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? diff --git a/lib/obsidian/parser/vault.rb b/lib/obsidian/parser/vault.rb index 199cc81..257937c 100644 --- a/lib/obsidian/parser/vault.rb +++ b/lib/obsidian/parser/vault.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -# TODO: remove this dependency -require "tilt/erb" require_relative "tree" require_relative "page" @@ -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 @@ -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, @@ -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,