jekyll-notion 0.0.0.alpha.2 → 0.0.0
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 +4 -4
- data/README.md +80 -1
- data/lib/jekyll-notion/document_without_a_file.rb +2 -2
- data/lib/jekyll-notion/generator.rb +52 -21
- data/lib/jekyll-notion/notion_database.rb +21 -10
- data/lib/jekyll-notion/notion_page.rb +1 -1
- data/lib/jekyll-notion/version.rb +1 -1
- data/lib/jekyll-notion.rb +10 -10
- metadata +34 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72643f8e9760b1f45a30fd87a8448cf16b1f85a63bcec6c83b4d4b3dea8b4c21
|
4
|
+
data.tar.gz: 95b0c61bdfc5e7c6dc018798474dcd40e6ec0728c0836d552249b9b7da8213bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: daf22fba12e6385aaa5842103c390ee6f58c093bf5ee1b199700c769a45d7736f04600f71cc0bcdedd77018a547024f8bdaf517a842cd88d58f13af4a77d57c9
|
7
|
+
data.tar.gz: 4d28a3d8319345e1a936ac3112009568a1d693cbd3314783fdea12d4c1cca38da33f701b25d870eb1cebf0fc11347f849979fcfee94a9d98173d33e376e50bec
|
data/README.md
CHANGED
@@ -1,2 +1,81 @@
|
|
1
1
|
# jekyll-notion
|
2
|
-
|
2
|
+
|
3
|
+
Import notion pages to a jekyll collection.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Use gem to install.
|
8
|
+
```bash
|
9
|
+
$ gem install 'jekyll-notion'
|
10
|
+
```
|
11
|
+
|
12
|
+
Or add it to the `Gemfile`.
|
13
|
+
```ruby
|
14
|
+
# Gemfile
|
15
|
+
gem 'jekyll-notion'
|
16
|
+
```
|
17
|
+
|
18
|
+
And update your jekyll plugins property in `_config.yml`.
|
19
|
+
|
20
|
+
```yml
|
21
|
+
plugins:
|
22
|
+
- jekyll-notion
|
23
|
+
```
|
24
|
+
|
25
|
+
## Setup
|
26
|
+
|
27
|
+
Before using the gem create an integration and generate a secret token. Check [notion getting started guide](https://developers.notion.com/docs/getting-started) to learn more.
|
28
|
+
|
29
|
+
Export the notion secret token in an environment variable named `NOTION_TOKEN`.
|
30
|
+
|
31
|
+
```bash
|
32
|
+
$ export NOTION_TOKEN=<secret_...>
|
33
|
+
```
|
34
|
+
|
35
|
+
Once your notion database has been shared, specify the `id` in your `_config.yml` as follows.
|
36
|
+
|
37
|
+
```yml
|
38
|
+
notion:
|
39
|
+
database:
|
40
|
+
id: b91d5...
|
41
|
+
collection: posts
|
42
|
+
filter: { "property": "Published", "checkbox": { "equals": true } }
|
43
|
+
sort: { "propery": "Last ordered", "direction": "ascending" }
|
44
|
+
frontmatter:
|
45
|
+
layout: post
|
46
|
+
```
|
47
|
+
|
48
|
+
The other properties are:
|
49
|
+
* `collection`: the collection each page belongs to (posts by default),
|
50
|
+
* `filter`: the database query filter,
|
51
|
+
* `sort`: the database query sort,
|
52
|
+
* `frontmatter`: additional frontmatter to append to each page in the collection.
|
53
|
+
|
54
|
+
Note: Only one database is available.
|
55
|
+
|
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,9 +2,9 @@
|
|
2
2
|
|
3
3
|
module JekyllNotion
|
4
4
|
class DocumentWithoutAFile < Jekyll::Document
|
5
|
-
def read_content(
|
5
|
+
def read_content(_new_content, **_opts)
|
6
6
|
if content =~ YAML_FRONT_MATTER_REGEXP
|
7
|
-
self.content =
|
7
|
+
self.content = Regexp.last_match.post_match
|
8
8
|
data_file = SafeYAML.load(Regexp.last_match(1))
|
9
9
|
merge_data!(data_file, :source => "YAML front matter") if data_file
|
10
10
|
end
|
@@ -4,24 +4,27 @@ 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
|
-
|
14
|
-
|
9
|
+
|
10
|
+
return unless notion_token? && config?
|
11
|
+
|
12
|
+
read_notion_database
|
13
|
+
end
|
14
|
+
|
15
|
+
def read_notion_database
|
16
|
+
@db = NotionDatabase.new(:config => config)
|
17
|
+
@db.pages.each do |page|
|
15
18
|
@current_page = page
|
16
|
-
|
17
|
-
Jekyll.logger.info("New page
|
19
|
+
collection.docs << make_page
|
20
|
+
Jekyll.logger.info("Jekyll Notion:", "New notion page at #{collection.docs.last.path}")
|
18
21
|
end
|
19
22
|
end
|
20
23
|
|
21
24
|
def make_page
|
22
25
|
new_post = DocumentWithoutAFile.new(
|
23
|
-
"#{Dir.pwd}/_#{
|
24
|
-
{ site
|
26
|
+
"#{Dir.pwd}/_#{collection_name}/#{make_filename}",
|
27
|
+
{ :site => @site, :collection => collection }
|
25
28
|
)
|
26
29
|
new_post.content = "#{make_frontmatter}\n\n#{make_md}"
|
27
30
|
new_post.read
|
@@ -29,31 +32,59 @@ module JekyllNotion
|
|
29
32
|
end
|
30
33
|
|
31
34
|
def make_md
|
32
|
-
NotionToMd::Converter.new(page_id
|
35
|
+
NotionToMd::Converter.new(:page_id => current_page.id).convert
|
33
36
|
end
|
34
37
|
|
35
38
|
def make_frontmatter
|
36
|
-
|
37
|
-
|
38
|
-
id: #{current_page.id}
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
---
|
39
|
+
<<~CONTENT
|
40
|
+
---
|
41
|
+
id: #{current_page.id}
|
42
|
+
title: #{current_page.title}
|
43
|
+
date: #{current_page.created_datetime}
|
44
|
+
cover: #{current_page.cover}
|
45
|
+
#{frontmatter}
|
46
|
+
---
|
44
47
|
CONTENT
|
45
48
|
end
|
46
49
|
|
50
|
+
def frontmatter
|
51
|
+
config.dig("database", "frontmatter").to_a.map { |k, v| "#{k}: #{v}" }.join("\n")
|
52
|
+
end
|
53
|
+
|
47
54
|
def make_filename
|
48
|
-
"
|
55
|
+
if collection_name == "posts"
|
56
|
+
"#{current_page.created_date}-#{current_page.title.downcase.parameterize}.md"
|
57
|
+
else
|
58
|
+
"#{current_page.title.downcase.parameterize}.md"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def collection_name
|
63
|
+
config.dig("database", "collection") || "posts"
|
49
64
|
end
|
50
65
|
|
51
66
|
def collection
|
52
|
-
@site.
|
67
|
+
@collection ||= @site.collections[collection_name]
|
53
68
|
end
|
54
69
|
|
55
70
|
def config
|
56
71
|
@config ||= @site.config["notion"] || {}
|
57
72
|
end
|
73
|
+
|
74
|
+
def notion_token?
|
75
|
+
if ENV["NOTION_TOKEN"].nil? || ENV["NOTION_TOKEN"].empty?
|
76
|
+
Jekyll.logger.warn("Jekyll Notion:", "NOTION_TOKEN not provided. Cannot read from Notion.")
|
77
|
+
return false
|
78
|
+
end
|
79
|
+
true
|
80
|
+
end
|
81
|
+
|
82
|
+
def config?
|
83
|
+
if config.empty?
|
84
|
+
Jekyll.logger.warn("Jekyll Notion:", "No config provided.")
|
85
|
+
return false
|
86
|
+
end
|
87
|
+
true
|
88
|
+
end
|
58
89
|
end
|
59
90
|
end
|
@@ -8,31 +8,42 @@ module JekyllNotion
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def pages
|
11
|
+
return [] unless id?
|
12
|
+
|
11
13
|
@pages ||= @notion.database_query(query)[:results].map do |page|
|
12
|
-
NotionPage.new(page
|
14
|
+
NotionPage.new(:page => page, :layout => config["layout"])
|
13
15
|
end
|
14
|
-
|
15
|
-
return @pages unless block_given?
|
16
|
-
|
17
|
-
@pages.each { |page| yield page }
|
18
16
|
end
|
19
17
|
|
20
18
|
private
|
21
19
|
|
20
|
+
def config
|
21
|
+
@config["database"]
|
22
|
+
end
|
23
|
+
|
22
24
|
def filter
|
23
|
-
@config.dig(
|
25
|
+
@config.dig("database", "filter")
|
24
26
|
end
|
25
27
|
|
26
28
|
def sort
|
27
|
-
@config.dig(
|
29
|
+
@config.dig("database", "sort")
|
28
30
|
end
|
29
31
|
|
30
32
|
def id
|
31
|
-
@config.dig(
|
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
|
32
43
|
end
|
33
44
|
|
34
|
-
def query
|
35
|
-
{ id
|
45
|
+
def query
|
46
|
+
{ :id => id, :filter => filter, :sort => sort }
|
36
47
|
end
|
37
48
|
end
|
38
49
|
end
|
data/lib/jekyll-notion.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
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
|
-
|
13
|
+
config.token = ENV["NOTION_TOKEN"]
|
14
14
|
end
|
15
15
|
|
16
16
|
module JekyllNotion
|
17
|
-
autoload :DocumentWithoutAFile,
|
18
|
-
autoload :NotionDatabase,
|
19
|
-
autoload :NotionPage,
|
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
|
4
|
+
version: 0.0.0
|
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-
|
11
|
+
date: 2022-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -45,7 +45,7 @@ dependencies:
|
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '5.0'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
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:
|
62
|
+
name: notion_to_md
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
65
|
- - "~>"
|
@@ -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
|
@@ -116,9 +144,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
144
|
version: 2.5.0
|
117
145
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
146
|
requirements:
|
119
|
-
- - "
|
147
|
+
- - ">="
|
120
148
|
- !ruby/object:Gem::Version
|
121
|
-
version:
|
149
|
+
version: '0'
|
122
150
|
requirements: []
|
123
151
|
rubyforge_project:
|
124
152
|
rubygems_version: 2.7.3
|