hugo-notion 0.1.0.pre.alpha.4 → 0.1.0.pre.alpha.5
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 +5 -10
- data/bin/huno +30 -19
- data/lib/hugo_notion/synchronizer.rb +2 -15
- data/lib/hugo_notion/version.rb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd3187060a3da73b91950b528a29eba70a35d397a9855dd0eeddd581ba67981c
|
4
|
+
data.tar.gz: 80a7ef596ed857945e49c82514e30b5455add7e9b970387a0ecc1dd81b294af2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f935964859cefced056b4fa473f4a42824a73c8d79acc7456998f00cc3b3597a600390b8033ee87f84359df0801a310b186836315d630a99b4284e69f198112c
|
7
|
+
data.tar.gz: a16abdcaed50acb78625723ed45f4ea64f75a021b7ac5473ee51918c1e28c9f8a0a9e53e9562129898965b5ad4a3eb839ecaec7a0be515119306aaf4af04a4bb
|
data/README.md
CHANGED
@@ -24,24 +24,19 @@ NOTION_TOKEN=your_notion_secret huno your_notion_page_url
|
|
24
24
|
|
25
25
|
If you're yet to move your Hugo pages to Notion, you can use my "blog_content" Notion page as a template https://www.notion.so/blog_content-0f1b55769779411a95df1ee9b4b070c9
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
If you'd like `huno` to sync Notion pages to a different directory, you can do that too
|
30
|
-
|
31
|
-
```
|
32
|
-
NOTION_TOKEN=your_notion_secret huno your_notion_page_url site_content/
|
33
|
-
```
|
34
|
-
|
35
|
-
To avoid having to provide the `NOTION_TOKEN` env var again and again, you can create a `.env` file
|
27
|
+
To avoid having to provide the notion token and notion page url again and again, create an .env file
|
36
28
|
|
37
29
|
```
|
38
30
|
echo 'NOTION_TOKEN=your_notion_secret' > .env
|
31
|
+
echo 'CONTENT_NOTION_URL=your_notion_page_url >> .env'
|
39
32
|
```
|
40
33
|
|
34
|
+
## Tips
|
35
|
+
|
41
36
|
To run `huno` say, every 15 seconds, use the `watch` command
|
42
37
|
|
43
38
|
```
|
44
|
-
watch -n15 huno
|
39
|
+
watch -n15 huno
|
45
40
|
```
|
46
41
|
|
47
42
|
If you're on MacOS and don't have the `watch` command installed, you can use Homebrew to install it
|
data/bin/huno
CHANGED
@@ -1,32 +1,43 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
env_file_path = File.join(Dir.pwd, '.env')
|
4
|
+
if File.exist?(env_file_path)
|
5
|
+
require 'dotenv'
|
6
|
+
Dotenv.load(env_file_path)
|
7
|
+
end
|
8
|
+
notion_token = ENV['NOTION_TOKEN']
|
9
|
+
unless notion_token
|
10
|
+
throw "Please create a Notion integration, generate a secret and provide it in the 'NOTION_TOKEN' environment variable"
|
8
11
|
end
|
9
|
-
Signal.trap("TERM") { do_exit }
|
10
|
-
Signal.trap("INT") { do_exit }
|
11
12
|
|
12
|
-
if
|
13
|
-
|
13
|
+
content_notion_url = if ARGV[0]
|
14
|
+
ARGV[0]
|
15
|
+
else
|
16
|
+
ENV.fetch('CONTENT_NOTION_URL')
|
14
17
|
end
|
15
|
-
|
16
|
-
|
18
|
+
unless content_notion_url
|
19
|
+
throw "Please provide the URL of the Notion page you'd like to sync in the `CONTENT_NOTION_URL` environment variable or as the first argument"
|
20
|
+
end
|
21
|
+
notion_page_id = URI(content_notion_url).path.match(/-(?<page_id>.*)\z/)['page_id']
|
17
22
|
|
18
|
-
|
23
|
+
content_dir = File.join(Dir.pwd, 'content')
|
19
24
|
if ARGV[1]
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
destination_dir = File.join(Dir.pwd, ARGV[1])
|
24
|
-
end
|
25
|
+
content_dir = ARGV[1]
|
26
|
+
elsif ENV.fetch('CONTENT_DIR')
|
27
|
+
content_dir = ENV.fetch('CONTENT_DIR')
|
25
28
|
end
|
29
|
+
content_dir = File.expand_path(content_dir, Dir.pwd)
|
26
30
|
|
27
|
-
|
31
|
+
require_relative '../lib/hugo_notion/synchronizer'
|
32
|
+
def do_exit
|
33
|
+
puts 'Exiting...'
|
34
|
+
exit
|
35
|
+
end
|
36
|
+
Signal.trap("TERM") { do_exit }
|
37
|
+
Signal.trap("INT") { do_exit }
|
38
|
+
puts "Syncing content from Notion..."
|
28
39
|
Synchronizer.run(
|
29
40
|
notion_page_id: notion_page_id,
|
30
|
-
destination_dir:
|
41
|
+
destination_dir: content_dir
|
31
42
|
)
|
32
43
|
puts "Done."
|
@@ -1,20 +1,7 @@
|
|
1
|
-
env_file_path = File.join(Dir.pwd, '.env')
|
2
|
-
if File.exist?(env_file_path)
|
3
|
-
require 'dotenv'
|
4
|
-
Dotenv.load(env_file_path)
|
5
|
-
end
|
6
|
-
notion_token = ENV['NOTION_TOKEN']
|
7
|
-
unless notion_token
|
8
|
-
throw "Please create a Notion integration, generate a secret and provide it in the 'NOTION_TOKEN' environment variable"
|
9
|
-
end
|
10
|
-
|
11
|
-
NOTION_TOKEN = ENV['NOTION_TOKEN']
|
12
|
-
|
13
1
|
require 'httparty'
|
14
2
|
require 'notion-ruby-client'
|
15
3
|
require 'notion_to_md'
|
16
4
|
require 'yaml'
|
17
|
-
require 'pry'
|
18
5
|
|
19
6
|
class NotionApi
|
20
7
|
BASE_URL = "https://api.notion.com/v1"
|
@@ -51,7 +38,7 @@ class Synchronizer
|
|
51
38
|
destination_dir = options[:destination_dir]
|
52
39
|
Dir.mkdir(destination_dir) unless Dir.exist?(destination_dir)
|
53
40
|
|
54
|
-
notion = NotionApi.new(NOTION_TOKEN)
|
41
|
+
notion = NotionApi.new(ENV.fetch('NOTION_TOKEN'))
|
55
42
|
response = if notion_database_id
|
56
43
|
notion.post("/databases/#{notion_database_id}/query")
|
57
44
|
elsif notion_page_id
|
@@ -107,7 +94,7 @@ class Synchronizer
|
|
107
94
|
end
|
108
95
|
|
109
96
|
page_front_matter_yaml = page_front_matter.to_yaml.chomp
|
110
|
-
page_markdown = NotionToMd.convert(page_id: notion_block_id, token: NOTION_TOKEN)
|
97
|
+
page_markdown = NotionToMd.convert(page_id: notion_block_id, token: ENV.fetch('NOTION_TOKEN'))
|
111
98
|
page_content = <<-page_CONTENT
|
112
99
|
#{page_front_matter_yaml}
|
113
100
|
---
|
data/lib/hugo_notion/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hugo-notion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.pre.alpha.
|
4
|
+
version: 0.1.0.pre.alpha.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nisanth Chunduru
|
@@ -10,6 +10,20 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2024-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dotenv
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: httparty
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|