obsidian-parser 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +7 -0
- data/lib/obsidian/parser/markdown_converter.rb +4 -0
- data/lib/obsidian/parser/version.rb +1 -1
- data/lib/obsidian/parser.rb +25 -6
- metadata +2 -3
- data/obsidian-parser.gemspec +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54b2b8b2c841d2c15bf739cc6e2c20a6dea2e29261719104ad1903adbd1a3337
|
4
|
+
data.tar.gz: c51dd21ba256fd8c5f03eb646aee741d45167f0cad79eb7ba715c4c776335205
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 633e3ccd369bc760f316d977aedf485cef4d76bbe28af3f29079a92d5bcb2b92a6a2d529ea0dcf60c09a85bac2c598838ea70ff51b50b60e372ae33652523cae
|
7
|
+
data.tar.gz: 8cac449aa204d036b5e72444afa1235e9dab3cb6b46cd1992d104d6a165775a70171f921c3b3a4064752c5daf08075c20d415a800bc1b6ca6f9c9fcd7c6037b1
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -26,6 +26,13 @@ puts parser.index.directories
|
|
26
26
|
# Index(title: "Projects", slug: "Projects") ]
|
27
27
|
```
|
28
28
|
|
29
|
+
### Generating HTML
|
30
|
+
```ruby
|
31
|
+
title = note.title
|
32
|
+
content = note.content
|
33
|
+
content.generate_html
|
34
|
+
```
|
35
|
+
|
29
36
|
## Development
|
30
37
|
|
31
38
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/obsidian/parser.rb
CHANGED
@@ -11,12 +11,24 @@ module Obsidian
|
|
11
11
|
(parent_slug == "") ? title : "#{parent_slug}/#{title}"
|
12
12
|
end
|
13
13
|
|
14
|
+
class MarkdownContent
|
15
|
+
def initialize(path)
|
16
|
+
@path = path
|
17
|
+
end
|
18
|
+
|
19
|
+
def generate_html
|
20
|
+
markdown = @path.read
|
21
|
+
Obsidian::ObsidianFlavoredMarkdown.parse(markdown).to_html
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
14
25
|
class Note
|
15
|
-
def initialize(title, slug, last_modified)
|
26
|
+
def initialize(title, slug, last_modified, content: nil)
|
16
27
|
# TODO: check frontmatter for titles as well
|
17
28
|
@title = title
|
18
29
|
@slug = slug
|
19
30
|
@last_modified = last_modified
|
31
|
+
@content = content
|
20
32
|
end
|
21
33
|
|
22
34
|
def inspect
|
@@ -26,14 +38,16 @@ module Obsidian
|
|
26
38
|
attr_reader :title
|
27
39
|
attr_reader :slug
|
28
40
|
attr_reader :last_modified
|
41
|
+
attr_reader :content
|
29
42
|
end
|
30
43
|
|
31
44
|
class Index
|
32
|
-
def initialize(title = "", slug = "")
|
45
|
+
def initialize(title = "", slug = "", content: nil)
|
33
46
|
@title = title
|
34
47
|
@slug = slug
|
35
48
|
@notes = []
|
36
49
|
@directories = {}
|
50
|
+
@content = content
|
37
51
|
end
|
38
52
|
|
39
53
|
def add_directory(title)
|
@@ -41,10 +55,10 @@ module Obsidian
|
|
41
55
|
@directories[title] ||= Index.new(title, new_slug)
|
42
56
|
end
|
43
57
|
|
44
|
-
def add_note(title, parent_slug, last_modified)
|
58
|
+
def add_note(title, parent_slug, last_modified, content: nil)
|
45
59
|
slug = Obsidian.build_slug(title, parent_slug)
|
46
60
|
directory = nested_directory(parent_slug.split("/"))
|
47
|
-
note = Note.new(title, slug, last_modified)
|
61
|
+
note = Note.new(title, slug, last_modified, content: content)
|
48
62
|
|
49
63
|
directory.notes << note
|
50
64
|
end
|
@@ -60,6 +74,7 @@ module Obsidian
|
|
60
74
|
attr_reader :notes
|
61
75
|
attr_reader :title
|
62
76
|
attr_reader :slug
|
77
|
+
attr_reader :content
|
63
78
|
|
64
79
|
private
|
65
80
|
|
@@ -77,10 +92,14 @@ module Obsidian
|
|
77
92
|
vault_directory.glob("**/*.md").each do |path|
|
78
93
|
dirname, basename = path.relative_path_from(vault_directory).split
|
79
94
|
|
80
|
-
if basename
|
95
|
+
next if basename == "."
|
96
|
+
|
97
|
+
# TODO: handle index.md files
|
98
|
+
if basename != "index.md"
|
81
99
|
title = basename.to_s.gsub(/\.md\z/, "")
|
82
100
|
parent_slug = dirname.to_s.gsub(/\A\.\/?/, "")
|
83
|
-
|
101
|
+
content = MarkdownContent.new(path)
|
102
|
+
@index.add_note(title, parent_slug, path.mtime, content: content)
|
84
103
|
end
|
85
104
|
end
|
86
105
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: obsidian-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mat Moore
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|
@@ -59,7 +59,6 @@ files:
|
|
59
59
|
- lib/obsidian/parser/markdown_converter.rb
|
60
60
|
- lib/obsidian/parser/obsidian_flavored_markdown.rb
|
61
61
|
- lib/obsidian/parser/version.rb
|
62
|
-
- obsidian-parser.gemspec
|
63
62
|
- sig/obsidian/parser.rbs
|
64
63
|
homepage:
|
65
64
|
licenses:
|
data/obsidian-parser.gemspec
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "lib/obsidian/parser/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "obsidian-parser"
|
7
|
-
spec.version = Obsidian::Parser::VERSION
|
8
|
-
spec.authors = ["Mat Moore"]
|
9
|
-
spec.email = ["matmoore@users.noreply.github.com"]
|
10
|
-
|
11
|
-
spec.summary = "Parse notes created with the Obsidian note-taking tool."
|
12
|
-
# spec.description = "TODO: Write a longer description or delete this line."
|
13
|
-
|
14
|
-
spec.license = "MIT"
|
15
|
-
spec.required_ruby_version = ">= 2.6.0"
|
16
|
-
|
17
|
-
# spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
18
|
-
|
19
|
-
spec.metadata["source_code_uri"] = "https://github.com/matmoore/obsidian-parser"
|
20
|
-
spec.metadata["changelog_uri"] = "https://github.com/matmoore/obsidian-parser/tree/main/CHANGELOG.md"
|
21
|
-
|
22
|
-
# Specify which files should be added to the gem when it is released.
|
23
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
-
spec.files = Dir.chdir(__dir__) do
|
25
|
-
`git ls-files -z`.split("\x0").reject do |f|
|
26
|
-
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
|
27
|
-
end
|
28
|
-
end
|
29
|
-
spec.bindir = "exe"
|
30
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
|
-
spec.require_paths = ["lib"]
|
32
|
-
|
33
|
-
# Uncomment to register a new dependency of your gem
|
34
|
-
spec.add_dependency "kramdown", "~> 2.4"
|
35
|
-
spec.add_dependency "kramdown-parser-gfm", "~> 1.1"
|
36
|
-
|
37
|
-
# For more information and examples about making a new gem, check out our
|
38
|
-
# guide at: https://bundler.io/guides/creating_gem.html
|
39
|
-
end
|