fyodor 0.3.2 → 0.3.3
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/README.md +31 -25
- data/lib/fyodor/book.rb +1 -1
- data/lib/fyodor/config_getter.rb +25 -39
- data/lib/fyodor/entry.rb +5 -7
- data/lib/fyodor/output_generator.rb +1 -1
- data/lib/fyodor/output_writer.rb +1 -1
- data/lib/fyodor/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fa1b1e78cc0ab15159e69a7f63c51ff94d549a618059395d29401ddc16ff45c
|
4
|
+
data.tar.gz: 325bfb536a54858e628a81094b707f7cd3f0be83d2cf613cf6b8b8de79b33015
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e5f8277ece0aa866131788f2702a1dc137cea14d86795e2c71c74947d9c532482b2bc0a89e34d7500af69a15642a774ce3a815882f835b4ce34cd155ec96af2
|
7
|
+
data.tar.gz: d8a7b83be1154a5385f8870e94f8973de8f8b744ffb09122d55dae9282b074ede788fba4ca1eccb9d1263786ad478c16d6d02a6bd1466e42aab603ed4fe22d53
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Fyodor
|
2
2
|
|
3
|
-
Convert your Amazon Kindle highlights, notes and bookmarks into markdown
|
3
|
+
Convert your Amazon Kindle highlights, notes and bookmarks into markdown (or any format).
|
4
4
|
|
5
5
|
## What is Fyodor
|
6
6
|
|
@@ -17,9 +17,9 @@ To read more about the motivation and what problem it tries to solve, [check thi
|
|
17
17
|
- Orders your entries by location/page on each book (the clippings file is ordered by time).
|
18
18
|
- Easily configurable for your language, allowing you to get all features and beautiful output.
|
19
19
|
- This software goes some length to be locale agnostic: basic parsing should work without configuration for any language. It should also work even if your clippings file has multiple locales.
|
20
|
-
- Bookmarks are printed together and notes are formatted differently, for better visualization.
|
21
20
|
- By default, output in a format that is clean and easy to edit/fiddle around: markdown.
|
22
|
-
-
|
21
|
+
- Bookmarks are placed together and notes are formatted differently, for better visualization.
|
22
|
+
- Entirely customizable output, in the format you prefer, through templates.
|
23
23
|
|
24
24
|
This program is based on the clippings file generated by Kindle 2019, but should work with other models.
|
25
25
|
|
@@ -34,7 +34,7 @@ We are limited by the data Kindle makes available through `My Clippings.txt`. Th
|
|
34
34
|
|
35
35
|
Install Ruby and run:
|
36
36
|
|
37
|
-
```
|
37
|
+
```shell-session
|
38
38
|
$ gem install fyodor
|
39
39
|
```
|
40
40
|
|
@@ -42,29 +42,29 @@ $ gem install fyodor
|
|
42
42
|
|
43
43
|
Run:
|
44
44
|
|
45
|
-
```
|
45
|
+
```shell-session
|
46
46
|
$ gem update fyodor
|
47
47
|
```
|
48
48
|
|
49
49
|
## Configuration
|
50
50
|
|
51
|
-
Fyodor
|
52
|
-
|
53
|
-
### Languages
|
54
|
-
|
55
|
-
If your Kindle is not in English, you should tell Fyodor how some things are called by your `My Clippings.txt` (e.g. highlights, pages, etc). _Fyodor should still work without configuration, but you won't take advantage of many features, resulting in a dirtier output._
|
51
|
+
Fyodor reads an optional configuration file at `~/.config/fyodor/fyodor.toml` or `$XDG_CONFIG_HOME/fyodor/fyodor.toml`. This section describes the available parameters (none is required).
|
56
52
|
|
57
|
-
|
53
|
+
To download the [sample configuration](docs/fyodor.toml.sample):
|
58
54
|
|
59
|
-
```
|
55
|
+
```shell-session
|
60
56
|
$ curl https://raw.githubusercontent.com/rc2dev/fyodor/master/docs/fyodor.toml.sample --create-dirs -o ~/.config/fyodor/fyodor.toml
|
61
57
|
```
|
62
58
|
|
63
|
-
|
59
|
+
### Languages
|
60
|
+
|
61
|
+
If your Kindle device is not set to English (US), you should tell Fyodor how some things are named on your `My Clippings.txt` (highlights, pages, etc). I went through some length to make Fyodor work regardless of this step. However, if you don't set this correctly, you won't take advantage of many features, resulting in a dirtier output.
|
62
|
+
|
63
|
+
Open both `fyodor.toml` and your `My Clippings.txt` in your preferred editor. Change the values in the `[parser]` section to mirror what you get in `My Clippings.txt`.
|
64
64
|
|
65
65
|
For example, this is the configuration for Brazilian Portuguese:
|
66
66
|
|
67
|
-
```
|
67
|
+
```toml
|
68
68
|
[parser]
|
69
69
|
highlight = "Seu destaque"
|
70
70
|
note = "Sua nota"
|
@@ -77,35 +77,41 @@ time = "Adicionado:"
|
|
77
77
|
|
78
78
|
### Showing the time
|
79
79
|
|
80
|
-
|
81
|
-
|
82
|
-
### Templating
|
83
|
-
|
84
|
-
You may change the structure of the files output by Fyodor by providing your own template.
|
80
|
+
You can also set whether to print the time of each entry. Under `[output]`, set `time` to `true` or `false`:
|
85
81
|
|
86
|
-
|
87
|
-
|
88
|
-
|
82
|
+
```toml
|
83
|
+
[output]
|
84
|
+
time = true
|
85
|
+
```
|
89
86
|
|
90
87
|
### Extension
|
91
88
|
|
92
|
-
If you want to change the extension of the output files
|
89
|
+
If you want to change the extension of the output files (typically after changing the template), set `extension` under `[output]`. For example, to change it to HTML:
|
93
90
|
|
94
91
|
```toml
|
95
92
|
[output]
|
96
93
|
extension = "html"
|
97
94
|
```
|
98
95
|
|
96
|
+
## Templating
|
97
|
+
|
98
|
+
You may change the structure of the files output by Fyodor by providing your own template in any format you wish.
|
99
|
+
|
100
|
+
To do that, place a ERB template at `~/.config/fyodor/template.erb` or `$XDG_CONFIG_HOME/fyodor/template.erb` and Fyodor will use it automatically.
|
101
|
+
|
102
|
+
The default template can be found [here](share/template.erb). You can use any method or attribute available [on this class](lib/fyodor/output_generator.rb).
|
103
|
+
|
104
|
+
|
99
105
|
## Usage
|
100
106
|
|
101
|
-
```
|
107
|
+
```shell-session
|
102
108
|
$ fyodor CLIPPINGS_FILE [OUTPUT_DIR]
|
103
109
|
```
|
104
110
|
|
105
111
|
Where:
|
106
112
|
|
107
113
|
- `CLIPPINGS_FILE` is the path for `My Clippings.txt`.
|
108
|
-
- `OUTPUT_DIR` is the directory to write the
|
114
|
+
- `OUTPUT_DIR` is the directory to write the output files. If none is supplied, this will be `fyodor_output` under the current directory.
|
109
115
|
|
110
116
|
## PSA: HTML to markdown
|
111
117
|
|
data/lib/fyodor/book.rb
CHANGED
data/lib/fyodor/config_getter.rb
CHANGED
@@ -4,11 +4,9 @@ require "toml"
|
|
4
4
|
|
5
5
|
module Fyodor
|
6
6
|
class ConfigGetter
|
7
|
-
CONFIG_NAME = "fyodor.toml"
|
8
|
-
TEMPLATE_NAME = "template.erb"
|
9
7
|
DEFAULT_TEMPLATE_PATH = File.dirname(__FILE__) + "/../../share/template.erb"
|
10
8
|
|
11
|
-
|
9
|
+
DEFAULT_CONFIG = {
|
12
10
|
"parser" => {
|
13
11
|
"highlight" => "Your Highlight",
|
14
12
|
"note" => "Your Note",
|
@@ -25,60 +23,48 @@ module Fyodor
|
|
25
23
|
}
|
26
24
|
|
27
25
|
def config
|
28
|
-
@config
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
private
|
26
|
+
return @config if defined?(@config)
|
33
27
|
|
34
|
-
def get_config
|
35
28
|
Hash.include CoreExtensions::Hash::Merging
|
36
|
-
|
37
|
-
@config_path = get_path(CONFIG_NAME)
|
38
|
-
print_config_path
|
39
|
-
user_config = @config_path.nil? ? {} : TOML.load_file(@config_path)
|
40
|
-
|
41
|
-
config = DEFAULTS.deep_merge(user_config)
|
29
|
+
config = DEFAULT_CONFIG.deep_merge(user_config)
|
42
30
|
config["output"]["template"] = template
|
43
31
|
|
44
|
-
config
|
32
|
+
@config = config
|
45
33
|
end
|
46
34
|
|
47
|
-
def get_path(name)
|
48
|
-
possible_dirs.each do |d|
|
49
|
-
path = d + name
|
50
|
-
return path if path.exist?
|
51
|
-
end
|
52
35
|
|
53
|
-
|
36
|
+
private
|
37
|
+
|
38
|
+
def config_dir
|
39
|
+
@config_dir ||= Pathname.new(ENV["XDG_CONFIG_HOME"] || "~/.config").expand_path + "fyodor"
|
54
40
|
end
|
55
41
|
|
56
|
-
def
|
57
|
-
|
42
|
+
def user_config_path
|
43
|
+
config_dir + "fyodor.toml"
|
44
|
+
end
|
58
45
|
|
59
|
-
|
60
|
-
|
61
|
-
@possible_dirs << Pathname.new("~/.config/fyodor").expand_path
|
46
|
+
def user_template_path
|
47
|
+
config_dir + "template.erb"
|
62
48
|
end
|
63
49
|
|
64
|
-
def
|
65
|
-
if
|
66
|
-
puts "
|
67
|
-
|
68
|
-
puts "Using config at #{@config_path}.\n"
|
50
|
+
def user_config
|
51
|
+
if user_config_path.exist?
|
52
|
+
puts "Using config at #{user_config_path}.\n"
|
53
|
+
return TOML.load_file(user_config_path)
|
69
54
|
end
|
55
|
+
|
56
|
+
puts "No config found: using defaults.\n"
|
57
|
+
{}
|
70
58
|
end
|
71
59
|
|
72
60
|
def template
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
puts "No template found: using default.\n\n"
|
77
|
-
else
|
78
|
-
puts "Using template at #{template_path}.\n\n"
|
61
|
+
if user_template_path.exist?
|
62
|
+
puts "Using custom template at #{user_template_path}.\n\n"
|
63
|
+
return File.read(user_template_path)
|
79
64
|
end
|
80
65
|
|
81
|
-
|
66
|
+
puts "No custom template found: using default.\n\n"
|
67
|
+
File.read(DEFAULT_TEMPLATE_PATH)
|
82
68
|
end
|
83
69
|
end
|
84
70
|
end
|
data/lib/fyodor/entry.rb
CHANGED
@@ -48,20 +48,18 @@ module Fyodor
|
|
48
48
|
|
49
49
|
# Override this method to use a SortedSet.
|
50
50
|
def <=>(other)
|
51
|
-
return @page_start <=> other.page_start if @loc_start == 0
|
51
|
+
return (@page_start <=> other.page_start) if @loc_start == 0
|
52
52
|
|
53
53
|
@loc_start <=> other.loc_start
|
54
54
|
end
|
55
55
|
|
56
56
|
# Override the following methods for deduplication.
|
57
57
|
def ==(other)
|
58
|
-
return false if @type != other.type || @text != other.text
|
58
|
+
return false if (@type != other.type || @text != other.text)
|
59
59
|
|
60
|
-
if desc_parsed? && other.desc_parsed?
|
61
|
-
|
62
|
-
|
63
|
-
@desc == other.desc
|
64
|
-
end
|
60
|
+
return (@loc == other.loc && @page == other.page) if desc_parsed? && other.desc_parsed?
|
61
|
+
|
62
|
+
@desc == other.desc
|
65
63
|
end
|
66
64
|
|
67
65
|
alias eql? ==
|
data/lib/fyodor/output_writer.rb
CHANGED
data/lib/fyodor/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fyodor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafael Cavalcanti
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3.0'
|
41
|
-
description: Parse Kindle clippings into markdown
|
41
|
+
description: Parse Kindle clippings into markdown (or any format)
|
42
42
|
email: dev@rafaelc.org
|
43
43
|
executables:
|
44
44
|
- fyodor
|
@@ -78,14 +78,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
78
|
version: '2.5'
|
79
79
|
- - "<"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: '
|
81
|
+
version: '4'
|
82
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
83
|
requirements:
|
84
84
|
- - ">="
|
85
85
|
- !ruby/object:Gem::Version
|
86
86
|
version: '0'
|
87
87
|
requirements: []
|
88
|
-
rubygems_version: 3.
|
88
|
+
rubygems_version: 3.2.3
|
89
89
|
signing_key:
|
90
90
|
specification_version: 4
|
91
91
|
summary: Kindle clippings parser
|