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

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc64ea093044b7a8b5f0f1059e175d439b8b70fc1b4b08a30ea39438b4dc6d46
4
- data.tar.gz: 608c37287a98f0ce89184616c27392048c9fdc725ab77f327e0cffb35fa4020b
3
+ metadata.gz: 1a2d58cc88c6a7012d3efc3eb431e9030f6287feec5b1307d731fb2b8a78a6e5
4
+ data.tar.gz: 939b5e04a4b019fd7a295dfba5c765e4f5fb5bf0f41e1b3527b01d84bf02a2cf
5
5
  SHA512:
6
- metadata.gz: 6c1b27117aee99b01dd988d243d1419b054447aa5afb02e5cffc5ed9120a8acd2e3a0b11759cccf6bd28a8657bc65e147307be501b2140421e961d48920c0f4d
7
- data.tar.gz: cb1fbc6a9edb4069fd8019e5a29837bdf80a551c119a9371d7678f48ca10a32e58c5a5da2edbe4c4bff0c41d6d560041db0fbf9a26fdeb0bcf9101cd88d3cabd
6
+ metadata.gz: bf6461f39325a08b18dfdd18ac9413e50991bc7c18032c30e59bba013ae00f77cab5b79ddcbf44100d4248cc957b98ccfd0538ddf323e3881f408e7ff5c46762
7
+ data.tar.gz: d451dfcbe921c165c232fa7a6195471f7da133ab6ddb46feadcc2705771cbc6092462e8ec29fa128b7d1c14db816b77ce84d07c05d2287eb53e93e4da9e7c06c
data/README.md CHANGED
@@ -39,21 +39,43 @@ notion:
39
39
  database:
40
40
  id: b91d5...
41
41
  collection: posts
42
- layout: post
43
42
  filter: { "property": "Published", "checkbox": { "equals": true } }
44
43
  sort: { "propery": "Last ordered", "direction": "ascending" }
45
44
  frontmatter:
46
- prop_1: blabla
47
- prop_2: albalb
45
+ layout: post
48
46
  ```
49
47
 
50
48
  The other properties are:
51
49
  * `collection`: what collection each page belongs to,
52
- * `layout`: the collection layout,
53
50
  * `filter`: the database query filter,
54
51
  * `sort`: the database query sort,
55
- * `frontmatter`: additonal frontmatter to append to each page in the collection.
52
+ * `frontmatter`: additional frontmatter to append to each page in the collection.
56
53
 
57
54
  Note: Only one database is available.
58
55
 
59
56
  And that's all. Each page in the notion database will be included in the selected collection.
57
+
58
+ ## Notion properties
59
+
60
+ Below, page notion default properties are set in each page frontmatter.
61
+
62
+ ```
63
+ ---
64
+ id: id
65
+ title: properties > Name > title > plain_text
66
+ cover: cover > external > url
67
+ date: created_time
68
+ ---
69
+ ```
70
+
71
+ ## Page filename
72
+
73
+ There are two kinds of collections: posts and others.
74
+
75
+ When the collection is posts, the filename format contains the `created_time` property plus the page title as specified in [jekyll docs](https://jekyllrb.com/docs/posts/#creating-posts).
76
+
77
+ ```
78
+ YEAR-MONTH-DAY-title.MARKUP
79
+ ```
80
+
81
+ Any other collection, the filename is the page title.
@@ -2,11 +2,11 @@
2
2
 
3
3
  module JekyllNotion
4
4
  class DocumentWithoutAFile < Jekyll::Document
5
- def read_content(new_content, **opts)
5
+ def read_content(_new_content, **_opts)
6
6
  if content =~ YAML_FRONT_MATTER_REGEXP
7
- self.content = $POSTMATCH
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
@@ -4,10 +4,6 @@ module JekyllNotion
4
4
  class Generator < Jekyll::Generator
5
5
  attr_reader :current_page
6
6
 
7
- def initialize(plugin)
8
- super(plugin)
9
- end
10
-
11
7
  def generate(site)
12
8
  @site = site
13
9
 
@@ -28,7 +24,7 @@ module JekyllNotion
28
24
 
29
25
  def make_page
30
26
  new_post = DocumentWithoutAFile.new(
31
- "#{Dir.pwd}/_#{config.dig('database', 'collection')}/#{make_filename}",
27
+ "#{Dir.pwd}/_#{collection_name}/#{make_filename}",
32
28
  { site: @site, collection: collection }
33
29
  )
34
30
  new_post.content = "#{make_frontmatter}\n\n#{make_md}"
@@ -41,27 +37,34 @@ module JekyllNotion
41
37
  end
42
38
 
43
39
  def make_frontmatter
44
- <<-CONTENT
45
- #{config.dig('database', 'frontmatter').to_yaml}
46
- id: #{current_page.id}
47
- layout: #{current_page.layout}
48
- title: #{current_page.title}
49
- date: #{current_page.created_datetime.to_s}
50
- cover: #{current_page.cover}
51
- ---
40
+ <<~CONTENT
41
+ #{config.dig('database', 'frontmatter').to_yaml}
42
+ id: #{current_page.id}
43
+ title: #{current_page.title}
44
+ date: #{current_page.created_datetime}
45
+ cover: #{current_page.cover}
46
+ ---
52
47
  CONTENT
53
48
  end
54
49
 
55
50
  def make_filename
56
- "#{current_page.created_date.to_s}-#{current_page.title.downcase.parameterize}.md"
51
+ if collection_name == 'posts'
52
+ "#{current_page.created_date}-#{current_page.title.downcase.parameterize}.md"
53
+ else
54
+ "#{current_page.title.downcase.parameterize}.md"
55
+ end
56
+ end
57
+
58
+ def collection_name
59
+ config.dig('database', 'collection')
57
60
  end
58
61
 
59
62
  def collection
60
- @site.send(config.dig('database', 'collection').to_sym)
63
+ @site.send(collection_name.to_sym)
61
64
  end
62
65
 
63
66
  def config
64
- @config ||= @site.config["notion"] || {}
67
+ @config ||= @site.config['notion'] || {}
65
68
  end
66
69
 
67
70
  def notion_token?
@@ -7,14 +7,14 @@ module JekyllNotion
7
7
  @config = config
8
8
  end
9
9
 
10
- def pages
10
+ def pages(&block)
11
11
  @pages ||= @notion.database_query(query)[:results].map do |page|
12
12
  NotionPage.new(page: page, layout: config['layout'])
13
13
  end
14
-
14
+
15
15
  return @pages unless block_given?
16
16
 
17
- @pages.each { |page| yield page }
17
+ @pages.each(&block)
18
18
  end
19
19
 
20
20
  private
@@ -35,7 +35,7 @@ module JekyllNotion
35
35
  @config.dig('database', 'id')
36
36
  end
37
37
 
38
- def query
38
+ def query
39
39
  { id: id, filter: filter, sort: sort }
40
40
  end
41
41
  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'
4
+ VERSION = '0.0.0.beta.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-notion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0.beta
4
+ version: 0.0.0.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Enrique Arias
@@ -45,7 +45,7 @@ dependencies:
45
45
  - !ruby/object:Gem::Version
46
46
  version: '5.0'
47
47
  - !ruby/object:Gem::Dependency
48
- name: notion_to_md
48
+ name: notion-ruby-client
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
@@ -59,7 +59,7 @@ dependencies:
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  - !ruby/object:Gem::Dependency
62
- name: notion-ruby-client
62
+ name: notion_to_md
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - "~>"