jekyll-notion-import 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/lib/jekyll/commands/notion_import.rb +28 -0
- data/lib/jekyll-notion-import/database.rb +67 -0
- data/lib/jekyll-notion-import/import.rb +49 -0
- data/lib/jekyll-notion-import/post.rb +67 -0
- data/lib/jekyll-notion-import/version.rb +7 -0
- data/lib/jekyll-notion-import.rb +19 -0
- metadata +167 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 12baae0fb76a11d3e3be5c043d2ff12f565f790036179d49bba106a7191f2766
|
4
|
+
data.tar.gz: 78c2c572cfbda808a0686ae994742c8d0ebe79a42815aeab8e31b8781dc38141
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 87de63514836198f82870a4037b3499687847a94011fefa34674cd8a12687f97d755a1102683433781829498e4ce9f92bb9e44ef789a47a6c7bda9a27f0f9d3d
|
7
|
+
data.tar.gz: 47fb0188ef5340c05c88ab93f654ac73d813ece0671000b5f33c6d5899416a9a3ddbdf40f4c8e05bf6d2e8c01126ff8eb74f61393be7cd384cb835db3165f420
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Commands
|
5
|
+
class NotionImportCommand < Command
|
6
|
+
def self.init_with_program(prog)
|
7
|
+
prog.command(:notion_import) do |c|
|
8
|
+
c.syntax "notion_import"
|
9
|
+
c.description "Imports posts from notion"
|
10
|
+
|
11
|
+
options.each { |opt| c.option(*opt) }
|
12
|
+
|
13
|
+
c.action { |args, options| process(args, options) }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.options
|
18
|
+
[]
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.process(args = [], options = {})
|
22
|
+
config = Jekyll.configuration(options)
|
23
|
+
|
24
|
+
Jekyll::NotionImport::Import.perform(config:)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module NotionImport
|
5
|
+
class Database
|
6
|
+
def initialize(config: {})
|
7
|
+
@notion = Notion::Client.new
|
8
|
+
@config = config
|
9
|
+
end
|
10
|
+
|
11
|
+
def id
|
12
|
+
config["id"]
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns an empty array or a NotionToMd:Page array
|
16
|
+
def fetch
|
17
|
+
return [] unless id?
|
18
|
+
|
19
|
+
@fetch ||= notion.database_query(query)[:results].map do |page|
|
20
|
+
page = NotionToMd::Page.new(:page => page, :blocks => build_blocks(page.id))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def filter
|
25
|
+
config["filter"]
|
26
|
+
end
|
27
|
+
|
28
|
+
def sorts
|
29
|
+
if config["sort"]
|
30
|
+
Jekyll.logger.warn("Jekyll Notion:", "sort property is deprecated, use sorts instead")
|
31
|
+
end
|
32
|
+
config["sorts"]
|
33
|
+
end
|
34
|
+
|
35
|
+
def collection_name
|
36
|
+
config["collection"] || "posts"
|
37
|
+
end
|
38
|
+
|
39
|
+
def data_name
|
40
|
+
config["data"]
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
attr_reader :config, :notion
|
46
|
+
|
47
|
+
def query
|
48
|
+
{ :database_id => id, :filter => filter, :sorts => sorts }.compact
|
49
|
+
end
|
50
|
+
|
51
|
+
def id?
|
52
|
+
if id.nil? || id.empty?
|
53
|
+
Jekyll.logger.warn("Jekyll Notion:",
|
54
|
+
"Database or page id is not provided. Cannot read from Notion.")
|
55
|
+
return false
|
56
|
+
end
|
57
|
+
true
|
58
|
+
end
|
59
|
+
|
60
|
+
def build_blocks(block_id)
|
61
|
+
NotionToMd::Blocks.build(block_id: block_id) do |nested_id|
|
62
|
+
@notion.block_children({ :block_id => nested_id })
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module NotionImport
|
5
|
+
class Import
|
6
|
+
def self.perform(...)
|
7
|
+
new(...).tap(&:perform)
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(config:)
|
11
|
+
@config = config["notion"] || {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def perform
|
15
|
+
return unless notion_token? && config?
|
16
|
+
|
17
|
+
config["databases"].each do |database_config|
|
18
|
+
database = Database.new(config: database_config)
|
19
|
+
|
20
|
+
database.fetch.each do |page|
|
21
|
+
Post.new(
|
22
|
+
collection_name: database.collection_name,
|
23
|
+
page:
|
24
|
+
).import
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
attr_reader :config
|
32
|
+
|
33
|
+
def notion_token?
|
34
|
+
return true unless ENV["NOTION_TOKEN"].blank?
|
35
|
+
|
36
|
+
Jekyll.logger.warn("Jekyll Notion Import:",
|
37
|
+
"NOTION_TOKEN not provided. Cannot read from Notion.")
|
38
|
+
false
|
39
|
+
end
|
40
|
+
|
41
|
+
def config?
|
42
|
+
return true unless config.empty?
|
43
|
+
|
44
|
+
Jekyll.logger.warn("Jekyll Notion:", "No config provided.")
|
45
|
+
false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module NotionImport
|
5
|
+
class Post
|
6
|
+
def initialize(collection_name:, page:)
|
7
|
+
@page = page
|
8
|
+
@collection_name = collection_name
|
9
|
+
end
|
10
|
+
|
11
|
+
def import
|
12
|
+
unless Dir.exist?(collection_directory)
|
13
|
+
Jekyll.logger.info("Jekyll Notion Import:", "Create #{collection_directory}")
|
14
|
+
FileUtils.mkdir_p(collection_directory)
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
if file_exists?
|
19
|
+
file_last_updated = DateTime.parse(YAML.load(File.read(path))["last_edited_time"])
|
20
|
+
|
21
|
+
return if file_last_updated >= page.last_edited_time
|
22
|
+
end
|
23
|
+
|
24
|
+
Jekyll.logger.info("Jekyll Notion Import:", "Import #{file_name}")
|
25
|
+
|
26
|
+
write_file
|
27
|
+
end
|
28
|
+
|
29
|
+
def write_file
|
30
|
+
File.open(path, "w") do |f|
|
31
|
+
f.puts(front_matter)
|
32
|
+
f.puts(page.body)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def file_exists?
|
37
|
+
File.exists?(path)
|
38
|
+
end
|
39
|
+
|
40
|
+
def file_name
|
41
|
+
@filename ||= "#{publish_date.strftime("%Y-%m-%d")}-#{Jekyll::Utils.slugify(page.title)}.md"
|
42
|
+
end
|
43
|
+
|
44
|
+
def publish_date
|
45
|
+
@publish_date ||= Date.parse(page.props["published"])
|
46
|
+
end
|
47
|
+
|
48
|
+
def path
|
49
|
+
@path ||= File.join(collection_directory, file_name)
|
50
|
+
end
|
51
|
+
|
52
|
+
def collection_directory
|
53
|
+
@collection_directory ||= "_#{collection_name}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def front_matter
|
57
|
+
@front_matter ||= YAML.dump(
|
58
|
+
page.props.transform_values {|v| v.is_a?(DateTime) ? v.iso8601 : v}
|
59
|
+
) + "---\n\n"
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
attr_reader :page, :collection_name
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "notion"
|
4
|
+
require "notion_to_md"
|
5
|
+
|
6
|
+
require "jekyll-notion-import/version"
|
7
|
+
require "jekyll-notion-import/database"
|
8
|
+
require "jekyll-notion-import/post"
|
9
|
+
require "jekyll-notion-import/import"
|
10
|
+
require "jekyll/commands/notion_import.rb"
|
11
|
+
|
12
|
+
Notion.configure do |config|
|
13
|
+
config.token = ENV["NOTION_TOKEN"]
|
14
|
+
end
|
15
|
+
|
16
|
+
module Jekyll
|
17
|
+
module NotionImport
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-notion-import
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Hall
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-11-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jekyll
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.7'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.7'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: notion_to_md
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: byebug
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rake
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '12.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '12.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rspec
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '3.0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '3.0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: rubocop-jekyll
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0.5'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0.5'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: webmock
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: 3.18.1
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 3.18.1
|
131
|
+
description: Import posts from notion
|
132
|
+
email:
|
133
|
+
- matt@codebeef.com
|
134
|
+
executables: []
|
135
|
+
extensions: []
|
136
|
+
extra_rdoc_files: []
|
137
|
+
files:
|
138
|
+
- lib/jekyll-notion-import.rb
|
139
|
+
- lib/jekyll-notion-import/database.rb
|
140
|
+
- lib/jekyll-notion-import/import.rb
|
141
|
+
- lib/jekyll-notion-import/post.rb
|
142
|
+
- lib/jekyll-notion-import/version.rb
|
143
|
+
- lib/jekyll/commands/notion_import.rb
|
144
|
+
homepage: https://github.com/codebeef/jekyll-notion-import
|
145
|
+
licenses:
|
146
|
+
- MIT
|
147
|
+
metadata: {}
|
148
|
+
post_install_message:
|
149
|
+
rdoc_options: []
|
150
|
+
require_paths:
|
151
|
+
- lib
|
152
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: 2.4.0
|
157
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
requirements: []
|
163
|
+
rubygems_version: 3.0.3.1
|
164
|
+
signing_key:
|
165
|
+
specification_version: 4
|
166
|
+
summary: Import posts from notion
|
167
|
+
test_files: []
|