jekyll-notion 0.0.0.beta.1 → 0.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a2d58cc88c6a7012d3efc3eb431e9030f6287feec5b1307d731fb2b8a78a6e5
4
- data.tar.gz: 939b5e04a4b019fd7a295dfba5c765e4f5fb5bf0f41e1b3527b01d84bf02a2cf
3
+ metadata.gz: b6adb6c98a4e57b71ac16f6e2266c71b6063beedfd960ba022d74783c0c2e6e3
4
+ data.tar.gz: 3db8e7873189c0fcd1644d051f0e099f0498eca922158c1bac9f34bbb2a84b9d
5
5
  SHA512:
6
- metadata.gz: bf6461f39325a08b18dfdd18ac9413e50991bc7c18032c30e59bba013ae00f77cab5b79ddcbf44100d4248cc957b98ccfd0538ddf323e3881f408e7ff5c46762
7
- data.tar.gz: d451dfcbe921c165c232fa7a6195471f7da133ab6ddb46feadcc2705771cbc6092462e8ec29fa128b7d1c14db816b77ce84d07c05d2287eb53e93e4da9e7c06c
6
+ metadata.gz: f9352dfc312103e5c846fe58b4053fa99cf93fedda66af3f037d21f6ccaba794b4589ec78b2b318a619d139d2025e0bedef0d03e364f0244a23d7ad835ae0d11
7
+ data.tar.gz: c88d36f84bbca91e46f892b64371fcf87baf2d06fa77ce41101841a7741ae90b5af79d8a756eb24c102b5843ad5fe00ed2638cdd7d0f843ee745b3172c06babb
data/README.md CHANGED
@@ -46,7 +46,7 @@ notion:
46
46
  ```
47
47
 
48
48
  The other properties are:
49
- * `collection`: what collection each page belongs to,
49
+ * `collection`: the collection each page belongs to (posts by default),
50
50
  * `filter`: the database query filter,
51
51
  * `sort`: the database query sort,
52
52
  * `frontmatter`: additional frontmatter to append to each page in the collection.
@@ -6,7 +6,7 @@ module JekyllNotion
6
6
  if content =~ YAML_FRONT_MATTER_REGEXP
7
7
  self.content = Regexp.last_match.post_match
8
8
  data_file = SafeYAML.load(Regexp.last_match(1))
9
- merge_data!(data_file, source: 'YAML front matter') if data_file
9
+ merge_data!(data_file, :source => "YAML front matter") if data_file
10
10
  end
11
11
  end
12
12
  end
@@ -7,25 +7,24 @@ module JekyllNotion
7
7
  def generate(site)
8
8
  @site = site
9
9
 
10
- return unless notion_token?
11
- return unless config?
10
+ return unless notion_token? && config?
12
11
 
13
12
  read_notion_database
14
13
  end
15
14
 
16
15
  def read_notion_database
17
- @db = NotionDatabase.new(config: config)
18
- @db.pages do |page|
16
+ @db = NotionDatabase.new(:config => config)
17
+ @db.pages.each do |page|
19
18
  @current_page = page
20
19
  collection.docs << make_page
21
- Jekyll.logger.info('Jekyll Notion:', "New notion page at #{collection.docs.last.path}")
20
+ Jekyll.logger.info("Jekyll Notion:", "New notion page at #{collection.docs.last.path}")
22
21
  end
23
22
  end
24
23
 
25
24
  def make_page
26
25
  new_post = DocumentWithoutAFile.new(
27
26
  "#{Dir.pwd}/_#{collection_name}/#{make_filename}",
28
- { site: @site, collection: collection }
27
+ { :site => @site, :collection => collection }
29
28
  )
30
29
  new_post.content = "#{make_frontmatter}\n\n#{make_md}"
31
30
  new_post.read
@@ -33,22 +32,27 @@ module JekyllNotion
33
32
  end
34
33
 
35
34
  def make_md
36
- NotionToMd::Converter.new(page_id: current_page.id).convert
35
+ NotionToMd::Converter.new(:page_id => current_page.id).convert
37
36
  end
38
37
 
39
38
  def make_frontmatter
40
39
  <<~CONTENT
41
- #{config.dig('database', 'frontmatter').to_yaml}
40
+ ---
42
41
  id: #{current_page.id}
43
42
  title: #{current_page.title}
44
43
  date: #{current_page.created_datetime}
45
44
  cover: #{current_page.cover}
45
+ #{frontmatter}
46
46
  ---
47
47
  CONTENT
48
48
  end
49
49
 
50
+ def frontmatter
51
+ config.dig("database", "frontmatter").to_a.map { |k, v| "#{k}: #{v}" }.join('\n')
52
+ end
53
+
50
54
  def make_filename
51
- if collection_name == 'posts'
55
+ if collection_name == "posts"
52
56
  "#{current_page.created_date}-#{current_page.title.downcase.parameterize}.md"
53
57
  else
54
58
  "#{current_page.title.downcase.parameterize}.md"
@@ -56,20 +60,20 @@ module JekyllNotion
56
60
  end
57
61
 
58
62
  def collection_name
59
- config.dig('database', 'collection')
63
+ config.dig("database", "collection") || "posts"
60
64
  end
61
65
 
62
66
  def collection
63
- @site.send(collection_name.to_sym)
67
+ @collection ||= @site.collections[collection_name]
64
68
  end
65
69
 
66
70
  def config
67
- @config ||= @site.config['notion'] || {}
71
+ @config ||= @site.config["notion"] || {}
68
72
  end
69
73
 
70
74
  def notion_token?
71
- if ENV['NOTION_TOKEN'].nil? || ENV['NOTION_TOKEN'].empty?
72
- Jekyll.logger.error('Jekyll Notion:', 'NOTION_TOKEN not provided. Cannot read from Notion.')
75
+ if ENV["NOTION_TOKEN"].nil? || ENV["NOTION_TOKEN"].empty?
76
+ Jekyll.logger.warn("Jekyll Notion:", "NOTION_TOKEN not provided. Cannot read from Notion.")
73
77
  return false
74
78
  end
75
79
  true
@@ -77,7 +81,7 @@ module JekyllNotion
77
81
 
78
82
  def config?
79
83
  if config.empty?
80
- Jekyll.logger.error('Jekyll Notion:', 'No config provided.')
84
+ Jekyll.logger.warn("Jekyll Notion:", "No config provided.")
81
85
  return false
82
86
  end
83
87
  true
@@ -7,36 +7,43 @@ module JekyllNotion
7
7
  @config = config
8
8
  end
9
9
 
10
- def pages(&block)
10
+ def pages
11
+ return [] unless id?
12
+
11
13
  @pages ||= @notion.database_query(query)[:results].map do |page|
12
- NotionPage.new(page: page, layout: config['layout'])
14
+ NotionPage.new(:page => page, :layout => config["layout"])
13
15
  end
14
-
15
- return @pages unless block_given?
16
-
17
- @pages.each(&block)
18
16
  end
19
17
 
20
18
  private
21
19
 
22
20
  def config
23
- @config['database']
21
+ @config["database"]
24
22
  end
25
23
 
26
24
  def filter
27
- @config.dig('database', 'filter')
25
+ @config.dig("database", "filter")
28
26
  end
29
27
 
30
28
  def sort
31
- @config.dig('database', 'sort')
29
+ @config.dig("database", "sort")
32
30
  end
33
31
 
34
32
  def id
35
- @config.dig('database', 'id')
33
+ @config.dig("database", "id")
34
+ end
35
+
36
+ def id?
37
+ if id.nil? || id.empty?
38
+ Jekyll.logger.warn("Jekyll Notion:",
39
+ "database id is not provided. Cannot read from Notion.")
40
+ return false
41
+ end
42
+ true
36
43
  end
37
44
 
38
45
  def query
39
- { id: id, filter: filter, sort: sort }
46
+ { :id => id, :filter => filter, :sort => sort }
40
47
  end
41
48
  end
42
49
  end
@@ -10,7 +10,7 @@ module JekyllNotion
10
10
  end
11
11
 
12
12
  def title
13
- page.dig(:properties, :Name, :title).inject('') do |acc, slug|
13
+ page.dig(:properties, :Name, :title).inject("") do |acc, slug|
14
14
  acc + slug[:plain_text]
15
15
  end
16
16
  end
@@ -32,7 +32,7 @@ module JekyllNotion
32
32
  end
33
33
 
34
34
  def created_datetime
35
- DateTime.parse(page['created_time'])
35
+ DateTime.parse(page["created_time"])
36
36
  end
37
37
 
38
38
  def updated_date
@@ -40,7 +40,7 @@ module JekyllNotion
40
40
  end
41
41
 
42
42
  def updated_datetime
43
- DateTime.parse(page['last_edited_time'])
43
+ DateTime.parse(page["last_edited_time"])
44
44
  end
45
45
 
46
46
  def url
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllNotion
4
- VERSION = '0.0.0.beta.1'
4
+ VERSION = "0.0.0.pre"
5
5
  end
data/lib/jekyll-notion.rb CHANGED
@@ -1,20 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'jekyll'
4
- require 'notion'
5
- require 'notion_to_md'
6
- require 'logger'
7
- require 'active_support/inflector'
8
- require 'jekyll-notion/generator'
3
+ require "jekyll"
4
+ require "notion"
5
+ require "notion_to_md"
6
+ require "logger"
7
+ require "active_support/inflector"
8
+ require "jekyll-notion/generator"
9
9
 
10
10
  NotionToMd::Logger.level = Logger::ERROR
11
11
 
12
12
  Notion.configure do |config|
13
- config.token = ENV['NOTION_TOKEN']
13
+ config.token = ENV["NOTION_TOKEN"]
14
14
  end
15
15
 
16
16
  module JekyllNotion
17
- autoload :DocumentWithoutAFile, 'jekyll-notion/document_without_a_file'
18
- autoload :NotionDatabase, 'jekyll-notion/notion_database'
19
- autoload :NotionPage, 'jekyll-notion/notion_page'
17
+ autoload :DocumentWithoutAFile, "jekyll-notion/document_without_a_file"
18
+ autoload :NotionDatabase, "jekyll-notion/notion_database"
19
+ autoload :NotionPage, "jekyll-notion/notion_page"
20
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-notion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0.beta.1
4
+ version: 0.0.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Enrique Arias
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-15 00:00:00.000000000 Z
11
+ date: 2022-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -86,6 +86,34 @@ dependencies:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
88
  version: '2'
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.12.0
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 0.12.0
89
117
  description:
90
118
  email:
91
119
  - emoriarty81@gmail.com