bkmrq 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/bkmrq +5 -0
- data/lib/app.rb +5 -0
- data/lib/bkmrq.rb +82 -0
- data/lib/browser_config.rb +23 -0
- data/lib/cli.rb +39 -0
- data/lib/docs_template.rb +31 -0
- data/lib/manual.rb +64 -0
- metadata +52 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 74e53ea64f34ff615830f694cb0ee20c81bdff858f231675a427bf10e17edb47
|
4
|
+
data.tar.gz: f0e3fe29ddd97c9a4623c924112dc26c10d2513179fad931b2c88398206f52e5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 51a26495b2828cd4a578ed3053644c722485f07231dd6fafef99f0b3055b7907c579e911e2ea101ecd7116cd986c8857e606c784156419448deaf212b584f741
|
7
|
+
data.tar.gz: 69f84df5c8c0e32e227e51cbe0e03fa5f869ec8c49994535006af0a1b9a388593a9e523c60b735a5058c7f17ebf170fbec14031d556a280a876fb97358d37d28
|
data/bin/bkmrq
ADDED
data/lib/app.rb
ADDED
data/lib/bkmrq.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require_relative 'docs_template'
|
5
|
+
require_relative 'browser_config'
|
6
|
+
|
7
|
+
module Bkmrq
|
8
|
+
# Bookmarks Document Generator
|
9
|
+
class App
|
10
|
+
BLOCKLIST = ENV.fetch('BKMRQ_BLOCKLIST', '(pdf|google|file:)').split(',').map(&:strip)
|
11
|
+
|
12
|
+
def initialize(browser: :brave, bookmarks_input: nil)
|
13
|
+
@bookmarks_input = bookmarks_input || Bkmrq::BROWSER_CONFIG.dig(browser, :bookmark_file_path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def export!
|
17
|
+
write_template
|
18
|
+
export(bookmarks['bookmark_bar'])
|
19
|
+
export(bookmarks['other'])
|
20
|
+
export(bookmarks['synced'])
|
21
|
+
output_file.close
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def output_file
|
27
|
+
@output_file ||= ::File.open(
|
28
|
+
"bkmrq_export_#{String(Integer(Time.now))[0..-2]}.md",
|
29
|
+
'w+'
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
def bookmarks
|
34
|
+
@bookmarks ||= ::File.open(@bookmarks_input, 'r') do |file|
|
35
|
+
JSON.parse(file.read)['roots']
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def write_template
|
40
|
+
%i[title subtitle header_image description]
|
41
|
+
.map(&Bkmrq::DocsTemplate.method(:public_send))
|
42
|
+
.map(&output_file.method(:write))
|
43
|
+
end
|
44
|
+
|
45
|
+
def export(marqs = bookmarks, level = 1)
|
46
|
+
return if skip_export?(marqs)
|
47
|
+
|
48
|
+
output_file.write(generate_formatted_entity(marqs, level))
|
49
|
+
marqs.fetch('children', []).empty? ||
|
50
|
+
marqs['children'].map { |child| export(child, level + 1) }
|
51
|
+
end
|
52
|
+
|
53
|
+
def skip_export?(bookmark_section)
|
54
|
+
[bookmark_section['name'], bookmark_section['name']].any? do |meta|
|
55
|
+
BLOCKLIST.any? { |pattern| !meta&.match(pattern).nil? }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def generate_formatted_entity(bookmark, level)
|
60
|
+
if bookmark['url'].nil?
|
61
|
+
generate_bookmark_title(bookmark, level)
|
62
|
+
else
|
63
|
+
generate_bookmark_link(bookmark, level)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def generate_bookmark_title(bookmark, level)
|
68
|
+
[
|
69
|
+
' ' * level,
|
70
|
+
'#' * level,
|
71
|
+
"#{bookmark['name']}\n"
|
72
|
+
].join(' ')
|
73
|
+
end
|
74
|
+
|
75
|
+
def generate_bookmark_link(bookmark, level)
|
76
|
+
[
|
77
|
+
' ' * level,
|
78
|
+
"[#{bookmark['name']}](#{bookmark['url']}) \n"
|
79
|
+
].join(' ')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Bkmrq
|
4
|
+
module Bkmrq
|
5
|
+
USER_HOME = ENV.fetch('HOME', ::File.join('home', ENV['USER']))
|
6
|
+
|
7
|
+
BRAVE_BROWSER_CONFIG = {
|
8
|
+
bookmark_file_path: File.join(
|
9
|
+
USER_HOME, '.config', 'BraveSoftware', 'Brave-Browser', 'Default', 'Bookmarks'
|
10
|
+
),
|
11
|
+
root: 'roots'
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
CHROME_BROWSER_CONFIG = {
|
15
|
+
bookmark_file_path: File.join(USER_HOME, '.config', 'chromium', 'Default', 'Bookmarks'),
|
16
|
+
root: 'roots'
|
17
|
+
}.freeze
|
18
|
+
|
19
|
+
BROWSER_CONFIG = {
|
20
|
+
brave: BRAVE_BROWSER_CONFIG,
|
21
|
+
chrome: CHROME_BROWSER_CONFIG
|
22
|
+
}.freeze
|
23
|
+
end
|
data/lib/cli.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require 'optparse'
|
6
|
+
require 'pry'
|
7
|
+
|
8
|
+
require_relative 'bkmrq'
|
9
|
+
require_relative 'manual'
|
10
|
+
|
11
|
+
module Bkmrq
|
12
|
+
# Cli
|
13
|
+
class Cli
|
14
|
+
def initialize(args)
|
15
|
+
@opts = {}
|
16
|
+
option_parser.parse!(sanitize_args(args), into: @opts)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def option_parser
|
22
|
+
@option_parser ||= OptionParser.new do |args|
|
23
|
+
# Option Parsing
|
24
|
+
Bkmrq::Manual.options_specs.map do |option_spec|
|
25
|
+
option_key = option_spec.pop
|
26
|
+
args.on(*option_spec) { |input| @opts.send(:[]=, option_key, input) }
|
27
|
+
end
|
28
|
+
|
29
|
+
# Manual Printing
|
30
|
+
args.banner = Bkmrq::Manual::BANNER
|
31
|
+
args.on_tail('-H', '--help', 'Bkmrq Manual') { puts args }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def sanitize_args(args)
|
36
|
+
args.reject(&:empty?).map(&:scrub).map(&:split).flatten
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bkmrq
|
4
|
+
# document output template
|
5
|
+
class DocsTemplate
|
6
|
+
FORMAT = {
|
7
|
+
title: "#{ENV['USER']}'s Web Browser Bookmarks",
|
8
|
+
subtitle: 'Bookmarks Exported Using Bkmrq',
|
9
|
+
header_image: 'https://user-images.githubusercontent.com/36154121/137836028-8dfe3001-4626-47a0-880f-d3dc7b719e27.jpeg',
|
10
|
+
description: <<-MD
|
11
|
+
This file was auto generated using the [bkmrq](https://github.com/sreedevk/bkmrq) gem.
|
12
|
+
MD
|
13
|
+
}.freeze
|
14
|
+
|
15
|
+
def self.title
|
16
|
+
"# #{FORMAT[:title]} \n"
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.subtitle
|
20
|
+
"## #{FORMAT[:subtitle]} \n"
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.header_image
|
24
|
+
"![](#{FORMAT[:header_image]}) \n"
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.description
|
28
|
+
FORMAT[:description]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/manual.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Bookmarks Manual
|
4
|
+
module Bkmrq
|
5
|
+
# Package Manual
|
6
|
+
class Manual
|
7
|
+
BANNER = <<-MAN
|
8
|
+
Bkmrq - Export your bookmarks to markdown
|
9
|
+
|
10
|
+
# Supported Browsers
|
11
|
+
- brave
|
12
|
+
- chromium
|
13
|
+
MAN
|
14
|
+
|
15
|
+
def self.options_specs
|
16
|
+
[
|
17
|
+
browser_opt_specs,
|
18
|
+
input_file_opt_specs,
|
19
|
+
output_file_opt_specs,
|
20
|
+
edit_opt_specs
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.browser_opt_specs
|
25
|
+
[
|
26
|
+
'-B BROWSER',
|
27
|
+
'--browser BROWSER',
|
28
|
+
String,
|
29
|
+
'Browser (Loads Default Configs)', :browser
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.input_file_opt_specs
|
34
|
+
[
|
35
|
+
'-F FILE',
|
36
|
+
'--input-file FILE',
|
37
|
+
String,
|
38
|
+
'Bookmarks file generated by your browser. (JSON FORMAT ONLY)',
|
39
|
+
:'input-file'
|
40
|
+
]
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.output_file_opt_specs
|
44
|
+
[
|
45
|
+
'-O FILE',
|
46
|
+
'--output-file FILE',
|
47
|
+
String,
|
48
|
+
'Filepath for markdown generated by Bkmrq',
|
49
|
+
:'output-file'
|
50
|
+
]
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.edit_opt_specs
|
54
|
+
[
|
55
|
+
'-E',
|
56
|
+
'--edit',
|
57
|
+
'Load Generated Markdown in $EDITOR (will not persist generated output)',
|
58
|
+
:edit
|
59
|
+
]
|
60
|
+
end
|
61
|
+
|
62
|
+
private_class_method :browser_opt_specs, :input_file_opt_specs, :output_file_opt_specs, :edit_opt_specs
|
63
|
+
end
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bkmrq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sreedev Kodichath
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-11-04 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Bkmrq Converts Bookmarks stored by your browser in JSON format to a readable
|
14
|
+
markdown format
|
15
|
+
email: sreedevpadmakumar@gmail.com
|
16
|
+
executables:
|
17
|
+
- bkmrq
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- bin/bkmrq
|
22
|
+
- lib/app.rb
|
23
|
+
- lib/bkmrq.rb
|
24
|
+
- lib/browser_config.rb
|
25
|
+
- lib/cli.rb
|
26
|
+
- lib/docs_template.rb
|
27
|
+
- lib/manual.rb
|
28
|
+
homepage: https://rubygems.org/gems/bkmrq
|
29
|
+
licenses:
|
30
|
+
- MIT
|
31
|
+
metadata:
|
32
|
+
source_code_uri: https://github.com/sreedevk/bkmrq
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubygems_version: 3.2.22
|
49
|
+
signing_key:
|
50
|
+
specification_version: 4
|
51
|
+
summary: Export your browser bookmarks to markdown!
|
52
|
+
test_files: []
|