joplin 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/joplin +34 -3
- 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/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
|
@@ -96,7 +115,7 @@ class MyCLI < Thor
|
|
96
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}'`
|
97
116
|
note.delete!
|
98
117
|
FileUtils.cd '..'
|
99
|
-
FileUtils.rm_rf note.title
|
118
|
+
# FileUtils.rm_rf note.title
|
100
119
|
abort 'Omg. pandoc failed!' if $?.exitstatus != 0
|
101
120
|
puts "OK. Done. Your book is #{note.title}.epub"
|
102
121
|
end
|
@@ -125,7 +144,7 @@ class MyCLI < Thor
|
|
125
144
|
end
|
126
145
|
yml = extract_yaml_header_for_epub(note)
|
127
146
|
new_note = Joplin::Note.new parent_id: note.parent_id
|
128
|
-
new_note.title = yml ? yml
|
147
|
+
new_note.title = yml ? title_from_yml(yml) : "built: #{note.title}"
|
129
148
|
new_note.body = "#{Psych.dump yml}...\n" if yml
|
130
149
|
new_note.body += notes.map { |n| "\# #{n.title}\n\n#{n.body}" }.join
|
131
150
|
new_note.save!
|
@@ -134,6 +153,18 @@ class MyCLI < Thor
|
|
134
153
|
|
135
154
|
private
|
136
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
|
+
|
137
168
|
def extract_yaml_header_for_epub(note)
|
138
169
|
yml = Psych.load note.body
|
139
170
|
return nil unless yml.is_a? Hash
|
@@ -143,7 +174,7 @@ class MyCLI < Thor
|
|
143
174
|
|
144
175
|
def token
|
145
176
|
Joplin.token = Joplin.get_token || options[:token]
|
146
|
-
return if Joplin.token
|
177
|
+
return Joplin.token if Joplin.token
|
147
178
|
|
148
179
|
raise "Couldn't find token in local database and it wasn't passed as an option. You better check yourself!"
|
149
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
|