joplin 1.0.1 → 1.1.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/Gemfile +2 -0
- data/Gemfile.lock +2 -0
- data/Makefile +3 -0
- data/bin/joplin +34 -8
- data/lib/joplin/version.rb +1 -1
- data/lib/joplin.rb +44 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 894bad22eddabf7759d835d3a2c2f94ef60bf0c0e7767bb902d8bfb107e70a19
|
4
|
+
data.tar.gz: 1a29dc5fe553d92a7e84c5e9292d542247111de8b1098bf01b98a54270b05608
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74047ff08fb61576bc9689dea85829cc58920436d410d3604a93e769c6314d2000adc244abfdbb6dea40ac38d0ad97ec0f82a8ccf5ae392aa12532dfe1c2b5f4
|
7
|
+
data.tar.gz: e390de0be3ff25e34d59dde77a84068bb62f7179aecd192c8afe2e0f00ec2df9dd681e4e0d44d8ba1414419f8738998b4e4aecafd0f5a6d02344c24d9e416db4
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -29,6 +29,7 @@ GEM
|
|
29
29
|
llhttp-ffi (0.4.0)
|
30
30
|
ffi-compiler (~> 1.0)
|
31
31
|
rake (~> 13.0)
|
32
|
+
pandoc_binary (3.1.1)
|
32
33
|
public_suffix (5.0.1)
|
33
34
|
rake (13.0.6)
|
34
35
|
rspec (3.12.0)
|
@@ -56,6 +57,7 @@ PLATFORMS
|
|
56
57
|
DEPENDENCIES
|
57
58
|
bundler (~> 2.0)
|
58
59
|
joplin!
|
60
|
+
pandoc_binary (~> 3.1)
|
59
61
|
rake (~> 13.0)
|
60
62
|
rspec (~> 3.12.0)
|
61
63
|
|
data/Makefile
CHANGED
data/bin/joplin
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
# REF: https://joplinapp.org/help/api/references/rest_api/
|
4
|
+
|
3
5
|
$:.unshift File.expand_path('../lib', __dir__)
|
4
6
|
|
5
7
|
require 'joplin'
|
@@ -49,6 +51,23 @@ class MyCLI < Thor
|
|
49
51
|
note.write
|
50
52
|
end
|
51
53
|
|
54
|
+
desc :stats, 'statistics on joplin data'
|
55
|
+
long_desc 'Get some statistics on the joplin instance, the number of notebooks, notes'
|
56
|
+
option :token
|
57
|
+
def stats
|
58
|
+
notes_total = 0
|
59
|
+
notebooks = Joplin::Notebook.all
|
60
|
+
notebooks.each do |notebook|
|
61
|
+
notes_count = notebook.notes.size # Get the count of notes in the notebook
|
62
|
+
notes_total += notebook.notes.size
|
63
|
+
end
|
64
|
+
puts <<~HEREDOC
|
65
|
+
Token: #{token}
|
66
|
+
Notebooks: #{notebooks.size}
|
67
|
+
Notes: #{notes_total}
|
68
|
+
HEREDOC
|
69
|
+
end
|
70
|
+
|
52
71
|
desc :nb2n, 'concate all notes in a notebook to one note. Possible PDF export'
|
53
72
|
long_desc 'The idea is to make a big note from all the notes in a notebook. PDF export or whatever export can happen from that. The notes are concatenated with a separator.'
|
54
73
|
option :token
|
@@ -88,7 +107,6 @@ class MyCLI < Thor
|
|
88
107
|
DESC
|
89
108
|
|
90
109
|
def epub(id)
|
91
|
-
abort 'You need to install pandoc and have it in your path' unless has_exec? 'pandoc'
|
92
110
|
build_note = Joplin::Note.new(id:)
|
93
111
|
note = build(id)
|
94
112
|
note.write
|
@@ -97,7 +115,7 @@ class MyCLI < Thor
|
|
97
115
|
`pandoc '#{note.title}.md' -o '../#{note.title}.epub' -t epub3 -f markdown+smart --title '#{note.title}' --toc --toc-depth=3 --metadata title='#{note.title}'`
|
98
116
|
note.delete!
|
99
117
|
FileUtils.cd '..'
|
100
|
-
FileUtils.rm_rf note.title
|
118
|
+
# FileUtils.rm_rf note.title
|
101
119
|
abort 'Omg. pandoc failed!' if $?.exitstatus != 0
|
102
120
|
puts "OK. Done. Your book is #{note.title}.epub"
|
103
121
|
end
|
@@ -126,7 +144,7 @@ class MyCLI < Thor
|
|
126
144
|
end
|
127
145
|
yml = extract_yaml_header_for_epub(note)
|
128
146
|
new_note = Joplin::Note.new parent_id: note.parent_id
|
129
|
-
new_note.title = yml ? yml
|
147
|
+
new_note.title = yml ? title_from_yml(yml) : "built: #{note.title}"
|
130
148
|
new_note.body = "#{Psych.dump yml}...\n" if yml
|
131
149
|
new_note.body += notes.map { |n| "\# #{n.title}\n\n#{n.body}" }.join
|
132
150
|
new_note.save!
|
@@ -135,6 +153,18 @@ class MyCLI < Thor
|
|
135
153
|
|
136
154
|
private
|
137
155
|
|
156
|
+
# if using subtitle with pandoc it has a different format
|
157
|
+
# https://pandoc.org/MANUAL.html#epubs
|
158
|
+
def title_from_yml(yml)
|
159
|
+
if yml['title'].is_a? Array
|
160
|
+
yml['title'].each do |title|
|
161
|
+
return title['text'] if title['type'] == 'main'
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
yml['title']
|
166
|
+
end
|
167
|
+
|
138
168
|
def extract_yaml_header_for_epub(note)
|
139
169
|
yml = Psych.load note.body
|
140
170
|
return nil unless yml.is_a? Hash
|
@@ -142,13 +172,9 @@ class MyCLI < Thor
|
|
142
172
|
yml
|
143
173
|
end
|
144
174
|
|
145
|
-
def has_exec?(command)
|
146
|
-
!`which #{command}`.empty?
|
147
|
-
end
|
148
|
-
|
149
175
|
def token
|
150
176
|
Joplin.token = Joplin.get_token || options[:token]
|
151
|
-
return if Joplin.token
|
177
|
+
return Joplin.token if Joplin.token
|
152
178
|
|
153
179
|
raise "Couldn't find token in local database and it wasn't passed as an option. You better check yourself!"
|
154
180
|
end
|
data/lib/joplin/version.rb
CHANGED
data/lib/joplin.rb
CHANGED
@@ -205,10 +205,50 @@ module Joplin
|
|
205
205
|
end
|
206
206
|
|
207
207
|
def notes
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
208
|
+
notes = []
|
209
|
+
page = 1
|
210
|
+
|
211
|
+
loop do
|
212
|
+
url = "#{Joplin.uri}/folders/#{@id}/notes?token=#{Joplin.token}&page=#{page}"
|
213
|
+
response = HTTP.get(url)
|
214
|
+
|
215
|
+
raise Error, "Failed to fetch notes: #{response}" if response.status != 200
|
216
|
+
|
217
|
+
data = JSON.parse(response.body)
|
218
|
+
|
219
|
+
items = data['items']
|
220
|
+
items.each { |note_data| notes << Joplin::Note.new(id: note_data['id']) }
|
221
|
+
|
222
|
+
break unless data['has_more']
|
223
|
+
|
224
|
+
page += 1
|
225
|
+
end
|
226
|
+
|
227
|
+
notes
|
228
|
+
end
|
229
|
+
|
230
|
+
def self.all
|
231
|
+
notebooks = []
|
232
|
+
page = 1
|
233
|
+
|
234
|
+
loop do
|
235
|
+
url = "#{Joplin.uri}/folders?token=#{Joplin.token}&page=#{page}"
|
236
|
+
response = HTTP.get(url)
|
237
|
+
|
238
|
+
raise Error, "Failed to fetch notebooks: #{response}" if response.status != 200
|
239
|
+
|
240
|
+
data = JSON.parse(response.body)
|
241
|
+
items = data['items']
|
242
|
+
|
243
|
+
break if items.empty?
|
244
|
+
|
245
|
+
# Collect Notebook instances
|
246
|
+
items.each { |notebook_data| notebooks << Notebook.new(notebook_data['id']) }
|
247
|
+
|
248
|
+
page += 1
|
249
|
+
end
|
250
|
+
|
251
|
+
notebooks
|
212
252
|
end
|
213
253
|
end
|
214
254
|
end
|
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.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Bretoi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
139
|
- !ruby/object:Gem::Version
|
140
140
|
version: '0'
|
141
141
|
requirements: []
|
142
|
-
rubygems_version: 3.
|
142
|
+
rubygems_version: 3.5.11
|
143
143
|
signing_key:
|
144
144
|
specification_version: 4
|
145
145
|
summary: joplin API
|