jekyll-notion 0.0.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 28969fe017d3182ae86953154bef64b2faf3fea5477eea3b315af7b0c6e99def
4
+ data.tar.gz: 4fe4fdeb77eaaafcadd5adce283e2a77e17ea9bfa57c32464e0c45d467038827
5
+ SHA512:
6
+ metadata.gz: 30a409cbf940624c5d60556f50c70f19edcdd6d936b969faf375f410cf5ecfaea940eb0441de1ff527717bfdef5f0580a35d7619e41f3e6ff2d75f0851776a55
7
+ data.tar.gz: dd5ae8d678bc6f6ebeef2703e2722161a36cecef145a275146818bea6fb0abccdb3cb9427bf1020cdd33271912e1c10c75c395eea86d51d371b6fc2fd548fe49
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # jekyll-notion
2
+ Import pages from notion.
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllNotion
4
+ class DocumentWithoutAFile < Jekyll::Document
5
+ def read_content(new_content, **opts)
6
+ if content =~ YAML_FRONT_MATTER_REGEXP
7
+ self.content = $POSTMATCH
8
+ data_file = SafeYAML.load(Regexp.last_match(1))
9
+ merge_data!(data_file, :source => "YAML front matter") if data_file
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/inflector'
4
+ require 'notion'
5
+ require 'notion_to_md'
6
+ require_relative './notion_database'
7
+
8
+ module JekyllNotion
9
+ class Generator < Jekyll::Generator
10
+ attr_reader :current_page
11
+
12
+ def initialize(plugin)
13
+ super(plugin)
14
+ end
15
+
16
+ def generate(site)
17
+ @site = site
18
+ @db = NotionDatabase.new(config: config)
19
+ @db.pages do |page|
20
+ @current_page = page
21
+ site.posts.docs << make_page
22
+ Jekyll.logger.info("New page from notion", site.posts.docs.last.path)
23
+ end
24
+ end
25
+
26
+ def make_page
27
+ new_post = DocumentWithoutAFile.new(
28
+ "#{Dir.pwd}/_#{config['collection']}/#{make_filename}",
29
+ { site: @site, collection: collection }
30
+ )
31
+ new_post.content = "#{make_frontmatter}\n\n#{make_md}"
32
+ new_post.read
33
+ new_post
34
+ end
35
+
36
+ def make_md
37
+ NotionToMd::Converter.new(page_id: current_page.id).convert
38
+ end
39
+
40
+ def make_frontmatter
41
+ <<-CONTENT
42
+ #{config['frontmatter'].to_yaml}
43
+ id: #{current_page.id}
44
+ layout: #{current_page.layout}
45
+ title: #{current_page.title}
46
+ date: #{current_page.created_datetime.to_s}
47
+ cover: #{current_page.cover}
48
+ ---
49
+ CONTENT
50
+ end
51
+
52
+ def make_filename
53
+ "#{current_page.created_date.to_s}-#{current_page.title.downcase.parameterize}.md"
54
+ end
55
+
56
+ def collection
57
+ @site.send(config['collection'].to_sym)
58
+ end
59
+
60
+ def config
61
+ @config ||= @site.config["notion"] || {}
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,38 @@
1
+ require_relative './notion_page'
2
+
3
+ module JekyllNotion
4
+ class NotionDatabase
5
+ def initialize(config:)
6
+ @notion = Notion::Client.new
7
+ @config = config
8
+ end
9
+
10
+ def pages
11
+ @pages ||= @notion.database_query(query)[:results].map do |page|
12
+ NotionPage.new(page: page, layout: @config['layout'])
13
+ end
14
+
15
+ return @pages unless block_given?
16
+
17
+ @pages.each { |page| yield page }
18
+ end
19
+
20
+ private
21
+
22
+ def filter
23
+ @config.dig('database', 'filter')
24
+ end
25
+
26
+ def sort
27
+ @config.dig('database', 'sort')
28
+ end
29
+
30
+ def id
31
+ @config.dig('database', 'id')
32
+ end
33
+
34
+ def query
35
+ { id: id, filter: filter, sort: sort }
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,48 @@
1
+ module JekyllNotion
2
+ class NotionPage
3
+ attr_reader :page, :layout
4
+
5
+ def initialize(page:, layout:)
6
+ @page = page
7
+ @layout = layout
8
+ end
9
+
10
+ def title
11
+ page.dig(:properties, :Name, :title).inject('') do |acc, slug|
12
+ acc + slug[:plain_text]
13
+ end
14
+ end
15
+
16
+ def cover
17
+ page.dig(:cover, :external, :url)
18
+ end
19
+
20
+ def icon
21
+ page.dig(:icon, :emoji)
22
+ end
23
+
24
+ def id
25
+ page[:id]
26
+ end
27
+
28
+ def created_date
29
+ created_datetime.to_date
30
+ end
31
+
32
+ def created_datetime
33
+ DateTime.parse(page["created_time"])
34
+ end
35
+
36
+ def updated_date
37
+ updated_datetime.to_date
38
+ end
39
+
40
+ def updated_datetime
41
+ DateTime.parse(page["last_edited_time"])
42
+ end
43
+
44
+ def url
45
+ page[:url]
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ module JekyllNotion
2
+ VERSION = '0.0.0.alpha'
3
+ end
@@ -0,0 +1,10 @@
1
+ require 'jekyll'
2
+ require 'notion'
3
+ require 'notion_to_md/logger'
4
+ require 'logger'
5
+
6
+ NotionToMd::Logger.level = Logger::ERROR
7
+
8
+ Notion.configure do |config|
9
+ config.token = ENV['NOTION_TOKEN']
10
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-notion
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0.alpha
5
+ platform: ruby
6
+ authors:
7
+ - Enrique Arias
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-01-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: jekyll
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '3.7'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '5.0'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '3.7'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '5.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: notion_to_md
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
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: notion-ruby-client
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :runtime
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: bundler
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '2'
89
+ description:
90
+ email:
91
+ - emoriarty81@gmail.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files:
95
+ - README.md
96
+ files:
97
+ - README.md
98
+ - lib/jekyll-notion.rb
99
+ - lib/jekyll-notion/document_without_a_file.rb
100
+ - lib/jekyll-notion/generator.rb
101
+ - lib/jekyll-notion/notion_database.rb
102
+ - lib/jekyll-notion/notion_page.rb
103
+ - lib/jekyll-notion/version.rb
104
+ homepage: https://github.com/emoriarty/jekyll-notion
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: 2.5.0
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">"
120
+ - !ruby/object:Gem::Version
121
+ version: 1.3.1
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.7.3
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: A Jekyll plugin to generate pages from Notion
128
+ test_files: []