hugo-notion 0.1.0.pre.alpha.3 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 998722740c86d07e77edb0bcfa625cf6cd9c956f90a525cf1146604324ed26bd
4
- data.tar.gz: 596a6adb5d21930ea0a46beb2a4cd7e1a3d309d18f2dd2ade153e9d8414f70e5
3
+ metadata.gz: fd3187060a3da73b91950b528a29eba70a35d397a9855dd0eeddd581ba67981c
4
+ data.tar.gz: 80a7ef596ed857945e49c82514e30b5455add7e9b970387a0ecc1dd81b294af2
5
5
  SHA512:
6
- metadata.gz: d44e9c969c40cdcbabcfd0442aa7577b54c31865910dc4cf51a268545f8fd1c76e705c64540e6e678284e48782227cf17dd048ccffd7793d17171b5222ea9f84
7
- data.tar.gz: 6269bf536477e430f23912f0cc23e1b5a4a4eeb184e64afb38a918efbd602eb678b0d5776dbb383e960cd42f8d607f11caf703a76be26e62ea253c0fb323d423
6
+ metadata.gz: f935964859cefced056b4fa473f4a42824a73c8d79acc7456998f00cc3b3597a600390b8033ee87f84359df0801a310b186836315d630a99b4284e69f198112c
7
+ data.tar.gz: a16abdcaed50acb78625723ed45f4ea64f75a021b7ac5473ee51918c1e28c9f8a0a9e53e9562129898965b5ad4a3eb839ecaec7a0be515119306aaf4af04a4bb
data/README.md CHANGED
@@ -1,3 +1,50 @@
1
1
  # hugo-notion
2
2
 
3
3
  Write in Notion. Publish with Hugo.
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ gem install hugo-notion --prerelease
9
+ ```
10
+
11
+ Installing the `hugo-notion` ruby gem will install the `huno` command.
12
+
13
+ ## Usage
14
+
15
+ First, create a Notion integration, generate a secret and connect that integration to the Notion page https://developers.notion.com/docs/create-a-notion-integration#getting-started
16
+
17
+ Go to your Hugo site directory and run
18
+
19
+ ```
20
+ NOTION_TOKEN=your_notion_secret huno your_notion_page_url
21
+ ```
22
+
23
+ `huno` will sync your Notion page and its children pages to the `content` directory.
24
+
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
+
27
+ To avoid having to provide the notion token and notion page url again and again, create an .env file
28
+
29
+ ```
30
+ echo 'NOTION_TOKEN=your_notion_secret' > .env
31
+ echo 'CONTENT_NOTION_URL=your_notion_page_url >> .env'
32
+ ```
33
+
34
+ ## Tips
35
+
36
+ To run `huno` say, every 15 seconds, use the `watch` command
37
+
38
+ ```
39
+ watch -n15 huno
40
+ ```
41
+
42
+ If you're on MacOS and don't have the `watch` command installed, you can use Homebrew to install it
43
+
44
+ ```
45
+ brew install watch
46
+ ```
47
+
48
+ ## Bug Reports
49
+
50
+ If you'd like to report a bug (if there are any, please do), please create a GitHub issue
data/bin/huno CHANGED
@@ -1,32 +1,43 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require_relative '../lib/hugo_notion/synchronizer'
4
-
5
- def do_exit
6
- puts 'Exiting...'
7
- exit
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 !ARGV[0]
13
- puts "Please provide the URL of the Notion page you'd like to sync as the first argument"
13
+ content_notion_url = if ARGV[0]
14
+ ARGV[0]
15
+ else
16
+ ENV.fetch('CONTENT_NOTION_URL')
14
17
  end
15
- notion_page_url = ARGV[0]
16
- notion_page_id = URI(notion_page_url).path.match(/-(?<page_id>.*)\z/)['page_id']
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
- destination_dir = File.join(Dir.pwd, 'content')
23
+ content_dir = File.join(Dir.pwd, 'content')
19
24
  if ARGV[1]
20
- if Pathname.new(ARGV[1]).absolute?
21
- destination_dir = ARGV[1]
22
- else
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
- puts "Syncing posts from Notion..."
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: 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
  ---
@@ -1,3 +1,3 @@
1
1
  class HugoNotion
2
- VERSION = '0.1.0-alpha.3'
2
+ VERSION = '0.1.0-alpha.5'
3
3
  end
metadata CHANGED
@@ -1,15 +1,29 @@
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.3
4
+ version: 0.1.0.pre.alpha.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nisanth Chunduru
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-16 00:00:00.000000000 Z
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
@@ -66,7 +80,7 @@ dependencies:
66
80
  - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
- description: Write in Notion. Publish with Hugo.
83
+ description: Use Notion as a CMS (Content Management System) for your Hugo site
70
84
  email:
71
85
  - nisanth074@gmail.com
72
86
  executables:
@@ -79,7 +93,8 @@ files:
79
93
  - lib/hugo_notion/synchronizer.rb
80
94
  - lib/hugo_notion/version.rb
81
95
  homepage: https://github.com/nisanthchunduru/hugo-notion
82
- licenses: []
96
+ licenses:
97
+ - MIT
83
98
  metadata: {}
84
99
  post_install_message:
85
100
  rdoc_options: []