joplin 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +3 -1
- data/Makefile +3 -0
- data/bin/joplin +38 -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: '09242aa0b4f46f7d69424cb3267766eff3178e5a1ab3bc229c2e47b496427db3'
|
4
|
+
data.tar.gz: bea1752fa435abab2cb0477bc4565795343cdd50f962128439dee822ac5c29a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72044c7c29a87bb27257c2cfcb4b04e5f9c06ed6679475b0e305bdba635176535fefcbdf3f27151c3d1498f7762700f0e8e9a3a1263731868963db1879047721
|
7
|
+
data.tar.gz: e127bfaf4d7ffc2fb5c20a2d085a5d9eb21921f678976a853f9fcdb3e408696c3f4f29c0cc4db3427720d1d1f5b79d8fdb6be6667db4338fb150c12344d30c90
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
joplin (0.
|
4
|
+
joplin (1.0.1)
|
5
5
|
http (~> 5.1.1)
|
6
6
|
sqlite3 (~> 1.6.3)
|
7
7
|
thor (~> 1.2.2)
|
@@ -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
@@ -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,33 @@ 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
|
+
build_note = Joplin::Note.new(id:)
|
74
92
|
note = build(id)
|
75
|
-
|
93
|
+
note.write
|
94
|
+
build_note.write note.title
|
76
95
|
FileUtils.cd note.title
|
77
96
|
`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
97
|
note.delete!
|
79
98
|
FileUtils.cd '..'
|
80
99
|
FileUtils.rm_rf note.title
|
100
|
+
abort 'Omg. pandoc failed!' if $?.exitstatus != 0
|
81
101
|
puts "OK. Done. Your book is #{note.title}.epub"
|
82
102
|
end
|
83
103
|
|
@@ -92,25 +112,35 @@ class MyCLI < Thor
|
|
92
112
|
token
|
93
113
|
note = Joplin::Note.new(id:)
|
94
114
|
notes = []
|
95
|
-
title = nil
|
96
115
|
note.body.each_line do |line|
|
97
|
-
|
98
|
-
|
116
|
+
match = line.match %r{!?\[(.*)?\]\(:/(\w+)\)}
|
117
|
+
next unless match
|
118
|
+
next if match[0][0] == '!'
|
119
|
+
|
99
120
|
begin
|
100
|
-
notes.push Joplin::Note.new id:
|
121
|
+
notes.push Joplin::Note.new id: match[2]
|
101
122
|
rescue Joplin::Note::NotFound
|
102
|
-
puts "Couldn't find note with id #{id} so we skip it"
|
123
|
+
puts "Couldn't find note with id #{id} so we skip it. Maybe an image"
|
103
124
|
end
|
104
125
|
end
|
126
|
+
yml = extract_yaml_header_for_epub(note)
|
105
127
|
new_note = Joplin::Note.new parent_id: note.parent_id
|
106
|
-
new_note.title = title
|
107
|
-
new_note.body =
|
128
|
+
new_note.title = yml ? yml['title'] : "built: #{note.title}"
|
129
|
+
new_note.body = "#{Psych.dump yml}...\n" if yml
|
130
|
+
new_note.body += notes.map { |n| "\# #{n.title}\n\n#{n.body}" }.join
|
108
131
|
new_note.save!
|
109
132
|
new_note
|
110
133
|
end
|
111
134
|
|
112
135
|
private
|
113
136
|
|
137
|
+
def extract_yaml_header_for_epub(note)
|
138
|
+
yml = Psych.load note.body
|
139
|
+
return nil unless yml.is_a? Hash
|
140
|
+
|
141
|
+
yml
|
142
|
+
end
|
143
|
+
|
114
144
|
def token
|
115
145
|
Joplin.token = Joplin.get_token || options[:token]
|
116
146
|
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.2
|
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-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|