joplin 1.0.0 → 1.0.1
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/Gemfile.lock +1 -1
- data/bin/joplin +43 -8
- data/lib/joplin/version.rb +1 -1
- data/lib/joplin.rb +5 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 709555c1917e195e956c526a75979ea74deb8f3da829afe0f6d34ab7d074fad5
|
4
|
+
data.tar.gz: a09ac659f62def224a04adf7766d90231d8034335190dc99402d7b3715a763f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a53a2aae8f8a7c073cbef92668097171a5038357ad8c16c045e01b4336b16b4369abef498ecb0961dfa14b8592be1b34c0998a4da37e3470e602e314d7f01f91
|
7
|
+
data.tar.gz: 50f3207ad27c7eaa968fa031b4bd3b052c8d58014701f2d64166b8594a753fa9422e03e7ecedb758bdce9f9e11a188e19e8a2046ee493ec0f57e08ee79618bc3
|
data/Gemfile.lock
CHANGED
data/bin/joplin
CHANGED
@@ -4,6 +4,7 @@ $:.unshift File.expand_path('../lib', __dir__)
|
|
4
4
|
|
5
5
|
require 'joplin'
|
6
6
|
require 'thor'
|
7
|
+
require 'yaml'
|
7
8
|
|
8
9
|
DIVIDER = %(
|
9
10
|
|
@@ -70,14 +71,34 @@ class MyCLI < Thor
|
|
70
71
|
desc :epub,
|
71
72
|
'build a note from a note (help build), write the note, and create an epub from the result. needs pandoc installed'
|
72
73
|
|
74
|
+
long_desc <<-DESC
|
75
|
+
If the building note has a yaml descriptor https://pandoc.org/MANUAL.html#epubs
|
76
|
+
then the epub will end up having the meta data.
|
77
|
+
|
78
|
+
Below is an example note. The for the referenced note are a result from using Joplin's webclipper on https://fiachetti.gitlab.io/mastering-roda/
|
79
|
+
|
80
|
+
---\n
|
81
|
+
title: Mastering Roda\n
|
82
|
+
author: Federico Iachetti\n
|
83
|
+
rights: Creative Commons Attribution 4.0 International License\n
|
84
|
+
language: en-US\n
|
85
|
+
...
|
86
|
+
|
87
|
+
[Mastering Roda](:/ca267a317fa544f99f559040696f1cae)
|
88
|
+
DESC
|
89
|
+
|
73
90
|
def epub(id)
|
91
|
+
abort 'You need to install pandoc and have it in your path' unless has_exec? 'pandoc'
|
92
|
+
build_note = Joplin::Note.new(id:)
|
74
93
|
note = build(id)
|
75
|
-
|
94
|
+
note.write
|
95
|
+
build_note.write note.title
|
76
96
|
FileUtils.cd note.title
|
77
97
|
`pandoc '#{note.title}.md' -o '../#{note.title}.epub' -t epub3 -f markdown+smart --title '#{note.title}' --toc --toc-depth=3 --metadata title='#{note.title}'`
|
78
98
|
note.delete!
|
79
99
|
FileUtils.cd '..'
|
80
100
|
FileUtils.rm_rf note.title
|
101
|
+
abort 'Omg. pandoc failed!' if $?.exitstatus != 0
|
81
102
|
puts "OK. Done. Your book is #{note.title}.epub"
|
82
103
|
end
|
83
104
|
|
@@ -92,25 +113,39 @@ class MyCLI < Thor
|
|
92
113
|
token
|
93
114
|
note = Joplin::Note.new(id:)
|
94
115
|
notes = []
|
95
|
-
title = nil
|
96
116
|
note.body.each_line do |line|
|
97
|
-
|
98
|
-
|
117
|
+
match = line.match %r{!?\[(.*)?\]\(:/(\w+)\)}
|
118
|
+
next unless match
|
119
|
+
next if match[0][0] == '!'
|
120
|
+
|
99
121
|
begin
|
100
|
-
notes.push Joplin::Note.new id:
|
122
|
+
notes.push Joplin::Note.new id: match[2]
|
101
123
|
rescue Joplin::Note::NotFound
|
102
|
-
puts "Couldn't find note with id #{id} so we skip it"
|
124
|
+
puts "Couldn't find note with id #{id} so we skip it. Maybe an image"
|
103
125
|
end
|
104
126
|
end
|
127
|
+
yml = extract_yaml_header_for_epub(note)
|
105
128
|
new_note = Joplin::Note.new parent_id: note.parent_id
|
106
|
-
new_note.title = title
|
107
|
-
new_note.body =
|
129
|
+
new_note.title = yml ? yml['title'] : "built: #{note.title}"
|
130
|
+
new_note.body = "#{Psych.dump yml}...\n" if yml
|
131
|
+
new_note.body += notes.map { |n| "\# #{n.title}\n\n#{n.body}" }.join
|
108
132
|
new_note.save!
|
109
133
|
new_note
|
110
134
|
end
|
111
135
|
|
112
136
|
private
|
113
137
|
|
138
|
+
def extract_yaml_header_for_epub(note)
|
139
|
+
yml = Psych.load note.body
|
140
|
+
return nil unless yml.is_a? Hash
|
141
|
+
|
142
|
+
yml
|
143
|
+
end
|
144
|
+
|
145
|
+
def has_exec?(command)
|
146
|
+
!`which #{command}`.empty?
|
147
|
+
end
|
148
|
+
|
114
149
|
def token
|
115
150
|
Joplin.token = Joplin.get_token || options[:token]
|
116
151
|
return if Joplin.token
|
data/lib/joplin/version.rb
CHANGED
data/lib/joplin.rb
CHANGED
@@ -129,15 +129,15 @@ module Joplin
|
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
|
-
def write
|
133
|
-
|
134
|
-
|
132
|
+
def write(path = nil)
|
133
|
+
dir = path || title
|
134
|
+
FileUtils.mkdir_p "#{dir}/resources"
|
135
135
|
body_to_write = String(body) # make a copy
|
136
136
|
resources.each do |resource|
|
137
|
-
resource.write "#{
|
137
|
+
resource.write "#{dir}/resources/#{resource.id}"
|
138
138
|
body_to_write.gsub!(%r{:/#{resource.id}}, "./resources/#{resource.id}")
|
139
139
|
end
|
140
|
-
IO.write "#{
|
140
|
+
IO.write "#{dir}/#{title}.md", body_to_write
|
141
141
|
end
|
142
142
|
|
143
143
|
def to_json(*_args)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: joplin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Bretoi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|