notion_to_html 1.1.6 → 1.2.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 +27 -46
- data/lib/notion_to_html/base_block.rb +19 -11
- data/lib/notion_to_html/renderers.rb +1 -1
- data/lib/notion_to_html/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66912fd27c7e40e627cb0a8ea32502c5acb6e7aac15da32b1e56116da618c920
|
4
|
+
data.tar.gz: ef9eeadf60a1020d43c221acf31befb23bceebaf19ccd69f954c8f6a21aa0ae6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23fa1ee940dc6ea3ffa0c5fe4eac56a259f958edb3fb78d6a9a4e0af044f2fc2e9207db09505dcedde6058059f5bf4893a129ec633ad52adadaf7aaf0a70198f
|
7
|
+
data.tar.gz: 3fa52d199dabbb0b7719d478f9017270f2c3d9cc03c1bba1ccc7df38f1b97cc185e85e115eef18aad34616d4b946aea2b44ca55668e9fc288430f799a45506be
|
data/README.md
CHANGED
@@ -12,10 +12,6 @@ Now you can use Notion to publish your pages directly to your Ruby web page with
|
|
12
12
|
- [Installation](#installation)
|
13
13
|
- [Dependencies](#dependencies)
|
14
14
|
- [Setup](#setup)
|
15
|
-
- [Notion Integration](#notion-integration)
|
16
|
-
- [Create your integration in Notion](#create-your-integration-in-notion)
|
17
|
-
- [Get your API secret](#get-your-api-secret)
|
18
|
-
- [Give your integration page permissions](#give-your-integration-page-permissions)
|
19
15
|
- [Configuration](#configuration)
|
20
16
|
- [Usage](#usage)
|
21
17
|
- [Rendering](#rendering)
|
@@ -23,6 +19,7 @@ Now you can use Notion to publish your pages directly to your Ruby web page with
|
|
23
19
|
- [Specific Page](#specific-page)
|
24
20
|
- [Customizing styles](#customizing-styles)
|
25
21
|
- [Overriding default styles](#overriding-default-styles)
|
22
|
+
- [Adding data options](#adding-data-options)
|
26
23
|
- [Querying](#querying)
|
27
24
|
- [Filtering](#filtering)
|
28
25
|
- [Sorting](#sorting)
|
@@ -65,46 +62,16 @@ By default the database should have the following structure:
|
|
65
62
|
|
66
63
|
Once you have the database created you will have to setup a Notion Integration, so the Notion API can communicate with your database. For this you will have to follow the [Create Your Integration In Notion](https://developers.notion.com/docs/create-a-notion-integration#create-your-integration-in-notion) tutorial.
|
67
64
|
|
68
|
-
If you wish to just quickly set it up, you can follow the
|
69
|
-
|
70
|
-
|
71
|
-
#### Create your integration in Notion
|
72
|
-
The first step to building any integration (internal or public) is to create a new integration in Notion’s integrations dashboard: <https://www.notion.com/my-integrations>.
|
73
|
-
1. Click `+ New Integration`.
|
74
|
-

|
75
|
-
2. Enter the integration name and select the associated workspace for the new integration.
|
76
|
-

|
77
|
-
|
78
|
-
#### Get your API secret
|
79
|
-
API requests require an API secret to be successfully authenticated.
|
80
|
-
1. Visit the Configuration tab to get your integration’s API secret (or “Internal Integration Secret”).
|
81
|
-

|
82
|
-
**Remember to keep your API secret a secret!**
|
83
|
-
Any value used to authenticate API requests should always be kept secret. Use environment variables and avoid committing sensitive data to your version control history.
|
84
|
-
If you do accidentally expose it, remember to “refresh” your secret.
|
85
|
-
|
86
|
-
#### Give your integration page permissions
|
87
|
-
The database that we’re about to create will be added to a parent Notion page in your workspace. For your integration to interact with the page, it needs explicit permission to read/write to that specific Notion page.
|
88
|
-
|
89
|
-
To give the integration permission, you will need to:
|
90
|
-
1. Go to the page with the database you created above.
|
91
|
-
2. Click on the ... More menu in the top-right corner of the page.
|
92
|
-
3. Scroll down to + Add Connections.
|
93
|
-
4. Search for your integration and select it.
|
94
|
-
5. Confirm the integration can access the page and all of its child pages.
|
95
|
-

|
96
|
-
6. You can then limit the integrations permission to just `Read Contents`:
|
97
|
-

|
98
|
-
|
99
|
-
Now you're finally ready to config the gem!
|
100
|
-
|
101
|
-
### Configuration
|
65
|
+
If you wish to just quickly set it up, you can follow the [notion integration docs](/docs/notion_setup.md), which are taken from that tutorial.
|
66
|
+
|
67
|
+
## Configuration
|
102
68
|
To configure NotionToHtml, you need to set up your Notion API token and database ID.
|
103
69
|
If you're using Rails add an initializer file in your Rails application, such as `config/initializers/notion_to_html.rb`, and include the following configuration block:
|
104
70
|
```ruby
|
105
71
|
NotionToHtml.configure do |config|
|
106
72
|
config.notion_api_token = 'NOTION_API_TOKEN'
|
107
73
|
config.notion_database_id = 'NOTION_DATABASE_ID'
|
74
|
+
config.cache_store = Rails.cache
|
108
75
|
end
|
109
76
|
```
|
110
77
|
|
@@ -120,6 +87,8 @@ To get these values:
|
|
120
87
|
|
121
88
|
Now you should be all setup!
|
122
89
|
|
90
|
+
For the full list of configuration settings, see [the configuration module](./lib/notion_to_html.rb).
|
91
|
+
|
123
92
|
## Usage
|
124
93
|
### Rendering
|
125
94
|
#### Pages
|
@@ -151,11 +120,11 @@ NotionToHtml::Service.get_page(page_id)
|
|
151
120
|
You can also specify classes for each type of supported block like this:
|
152
121
|
```ruby
|
153
122
|
NotionToHtml::Service.get_page(page_id).formatted_blocks(
|
154
|
-
paragraph: 'text-lg',
|
155
|
-
heading_1: 'text-3xl md:text-4xl font-bold',
|
156
|
-
heading_2: 'text-white',
|
157
|
-
heading_3: 'font-bold',
|
158
|
-
quote: 'italic',
|
123
|
+
paragraph: { class: 'text-lg' },
|
124
|
+
heading_1: { class: 'text-3xl md:text-4xl font-bold' },
|
125
|
+
heading_2: { class: 'text-white' },
|
126
|
+
heading_3: { class: 'font-bold' },
|
127
|
+
quote: { class: 'italic' },
|
159
128
|
)
|
160
129
|
```
|
161
130
|
#### Overriding default styles
|
@@ -169,17 +138,29 @@ It also works for `formatted_blocks`:
|
|
169
138
|
NotionToHtml::Service.get_page(page_id)
|
170
139
|
.formatted_blocks(
|
171
140
|
paragraph: { class: 'text-lg', override_class: true },
|
172
|
-
quote: 'italic'
|
141
|
+
quote: { class: 'italic' }
|
142
|
+
)
|
143
|
+
```
|
144
|
+
#### Adding data options
|
145
|
+
If you want to integrate stimulus you can add data properties by specifying the `data:` option when calling the formatter:
|
146
|
+
```ruby
|
147
|
+
NotionToHtml::Service.get_page(page_id).formatted_blocks(
|
148
|
+
paragraph: { class: 'text-lg', data: { controller: 'test' } } },
|
149
|
+
heading_1: { class: 'text-3xl md:text-4xl font-bold' },
|
150
|
+
heading_2: { class: 'text-white', data: { controller: 'click' } },
|
151
|
+
heading_3: { class: 'font-bold' },
|
152
|
+
quote: { class: 'italic' },
|
173
153
|
)
|
174
154
|
```
|
175
155
|
### Querying
|
176
156
|
By default the `NotionToHtml::Service` is setup to follow the database structure sepcified above. This way it will only return pages that have been marked as `public`.
|
177
157
|
|
178
158
|
#### Filtering
|
179
|
-
You can filter the results by specifying a tag and/or a specific slug:
|
159
|
+
You can filter the results by specifying a name, description, tag and/or a specific slug:
|
180
160
|
```ruby
|
181
|
-
NotionToHtml::Service.get_pages(tag: 'web', slug: 'test-slug')
|
161
|
+
NotionToHtml::Service.get_pages(name: 'Ruby', description: 'ruby on rails', tag: 'web', slug: 'test-slug')
|
182
162
|
```
|
163
|
+
This will return all the pages that have at least one of those specified attributes.
|
183
164
|
#### Sorting
|
184
165
|
The default sorting is by the `published` Date column in the database
|
185
166
|
|
@@ -68,35 +68,43 @@ module NotionToHtml
|
|
68
68
|
@properties = data[@type]
|
69
69
|
end
|
70
70
|
|
71
|
+
BLOCK_TYPES.each do |block|
|
72
|
+
define_method("class_for_#{block}") { |options| options.dig(block, :class) }
|
73
|
+
define_method("data_for_#{block}") { |options| options.dig(block, :data) }
|
74
|
+
end
|
75
|
+
|
71
76
|
# Renders the block based on its type.
|
72
77
|
# @param options [Hash] Additional options for rendering the block.
|
73
78
|
# @return [String] The rendered block as HTML.
|
74
79
|
def render(options = {})
|
75
80
|
case @type
|
76
81
|
when 'paragraph'
|
77
|
-
render_paragraph(rich_text, class: options
|
82
|
+
render_paragraph(rich_text, class: class_for_paragraph(options), data: data_for_paragraph(options))
|
78
83
|
when 'heading_1'
|
79
|
-
render_heading_1(rich_text, class: options
|
84
|
+
render_heading_1(rich_text, class: class_for_heading_1(options), data: data_for_heading_1(options))
|
80
85
|
when 'heading_2'
|
81
|
-
render_heading_2(rich_text, class: options
|
86
|
+
render_heading_2(rich_text, class: class_for_heading_2(options), data: data_for_heading_2(options))
|
82
87
|
when 'heading_3'
|
83
|
-
render_heading_3(rich_text, class: options
|
88
|
+
render_heading_3(rich_text, class: class_for_heading_3(options), data: data_for_heading_3(options))
|
84
89
|
when 'table_of_contents'
|
85
90
|
render_table_of_contents
|
86
91
|
when 'bulleted_list_item'
|
87
|
-
render_bulleted_list_item(rich_text, @siblings, @children, 0, class: options
|
92
|
+
render_bulleted_list_item(rich_text, @siblings, @children, 0, class: class_for_bulleted_list_item(options),
|
93
|
+
data: data_for_bulleted_list_item(options))
|
88
94
|
when 'numbered_list_item'
|
89
|
-
render_numbered_list_item(rich_text, @siblings, @children, 0, class: options
|
95
|
+
render_numbered_list_item(rich_text, @siblings, @children, 0, class: class_for_numbered_list_item(options),
|
96
|
+
data: data_for_numbered_list_item(options))
|
90
97
|
when 'quote'
|
91
|
-
render_quote(rich_text, class: options
|
98
|
+
render_quote(rich_text, class: class_for_quote(options), data: data_for_quote(options))
|
92
99
|
when 'callout'
|
93
|
-
render_callout(rich_text, icon, class: options
|
100
|
+
render_callout(rich_text, icon, class: class_for_callout(options), data: data_for_callout(options))
|
94
101
|
when 'code'
|
95
|
-
render_code(rich_text, class: options
|
102
|
+
render_code(rich_text, class: class_for_code(options), data: data_for_code(options),
|
103
|
+
language: @properties['language'])
|
96
104
|
when 'image', 'embed'
|
97
|
-
render_image(*multi_media, class: options
|
105
|
+
render_image(*multi_media, class: class_for_image(options), data: data_for_image(options))
|
98
106
|
when 'video'
|
99
|
-
render_video(*multi_media, class: options
|
107
|
+
render_video(*multi_media, class: class_for_video(options), data: data_for_video(options))
|
100
108
|
else
|
101
109
|
'Unsupported block'
|
102
110
|
end
|
@@ -127,7 +127,7 @@ module NotionToHtml
|
|
127
127
|
def render_date(date, options = {})
|
128
128
|
# TODO: handle end and time zone
|
129
129
|
# date=end=, start=2023-07-13, time_zone=, id=%5BsvU, type=date
|
130
|
-
tag.p(date.to_date.to_fs(:long), class: css_class_for(:date, options))
|
130
|
+
tag.p(date.to_date.to_fs(:long), **options, class: css_class_for(:date, options))
|
131
131
|
end
|
132
132
|
|
133
133
|
# Renders a heading 1 block.
|