hatenikki 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c5084c3d1f9fb52f9698f0a9d23302dfb3bb76875aa1a500a8642ca2731c380
4
- data.tar.gz: ff343865f78a9214986afe47ba652f39b7e42d04e075e2b73b272ed979842cf1
3
+ metadata.gz: bbf08a23ddaf07118a72899ce748dd39f98bf053ceabee43180ac08c3569bf82
4
+ data.tar.gz: 6cad9f81f2af8cbd3b6686baf212ccb8ec63f92479958ff9a7c48b86d012ee51
5
5
  SHA512:
6
- metadata.gz: b52fa7463ef86a7bdfac2b8201c9af90c39c606f6f7d81214453809086540c215b69e62721d5926a1c645b031b1cd2e2e00a71dc70f39f72b43903090bc2dd11
7
- data.tar.gz: 6de70cdadff3baf435a227dad9d013d2467c8d21166474e7d99ddfd50d4fab29aea2788bea583b86ca900a4313f8328001a5d45e3f50ca719e84f3c9ec5a8ec4
6
+ metadata.gz: 663dab3d0d8f2153b43a6a53dc128e8f1ca25adf32613cd29d21949c5a24ff855ada9ddf572e81ab780901a0ebcd2ec400265aaf4d5e5b08a488a32eccb4b364
7
+ data.tar.gz: 76274c3f7f810b27dad12f20220d7de18fb0693e5ef3ad253ae08a7e9b0e75f79f08f93d22e776aaa4d1c611d851ad567941742d75aef92017ecc9b57903fcac
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hatenikki (0.1.1)
4
+ hatenikki (0.2.0)
5
5
  hatenablog
6
6
 
7
7
  GEM
@@ -11,7 +11,7 @@ GEM
11
11
  nokogiri
12
12
  oauth
13
13
  mini_portile2 (2.4.0)
14
- nokogiri (1.10.7)
14
+ nokogiri (1.10.9)
15
15
  mini_portile2 (~> 2.4.0)
16
16
  oauth (0.5.4)
17
17
  rake (12.3.3)
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Hatenikki
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/hatenikki`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Write diary every day with Hatena blog.
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,7 +20,19 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ ```
24
+ # Print the today's article to STDOUT
25
+ $ hatenikki load
26
+
27
+ # Save the today's article from STDIN
28
+ $ hatenikki save
29
+
30
+ # Publish draft articles except today's one
31
+ $ hatenikki publish
32
+ ```
33
+
34
+ * For more information (in Japanese): https://pocke.hatenablog.com/entry/2020/01/18/191652
35
+ * Related project: https://github.com/pocke/hatenikki.vim
26
36
 
27
37
  ## Development
28
38
 
@@ -19,6 +19,9 @@ module Hatenikki
19
19
  # Load today's diary.
20
20
  private def load
21
21
  if entry = todays_entry
22
+ if match = entry.title.match(/ - (?<subtitle>.+)/)
23
+ puts "title: #{match[:subtitle]}"
24
+ end
22
25
  puts entry.content
23
26
  end
24
27
  end
@@ -28,17 +31,19 @@ module Hatenikki
28
31
  content = STDIN.read
29
32
  categories = []
30
33
 
34
+ title, content = title_and_content(content)
35
+
31
36
  if entry = todays_entry
32
37
  client.update_entry(
33
38
  entry.id,
34
- today,
39
+ title,
35
40
  content,
36
41
  categories,
37
42
  entry.draft,
38
43
  )
39
44
  else
40
45
  client.post_entry(
41
- today,
46
+ title,
42
47
  content,
43
48
  categories,
44
49
  'yes', # draft
@@ -46,6 +51,14 @@ module Hatenikki
46
51
  end
47
52
  end
48
53
 
54
+ private def title_and_content(content)
55
+ if match = content.match(/\Atitle: (?<subtitle>.+)/)
56
+ ["#{today} - #{match[:subtitle]}", content.sub(/.+\n/, '')]
57
+ else
58
+ [today, content]
59
+ end
60
+ end
61
+
49
62
  # Publish drafts except today's
50
63
  private def publish
51
64
  client.entries.each do |e|
@@ -66,8 +79,12 @@ module Hatenikki
66
79
  @argv[0]
67
80
  end
68
81
 
82
+ private def todays_entry?(entry)
83
+ entry.title.match?(/\A#{Regexp.escape(today)}\b/)
84
+ end
85
+
69
86
  private def todays_entry
70
- client.entries.find{|entry| entry.title == today }
87
+ client.entries.find{|entry| todays_entry?(entry) }
71
88
  end
72
89
 
73
90
  private def today
@@ -1,3 +1,3 @@
1
1
  module Hatenikki
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hatenikki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masataka Pocke Kuwabara
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-18 00:00:00.000000000 Z
11
+ date: 2020-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hatenablog
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
68
  requirements: []
69
- rubygems_version: 3.1.2
69
+ rubygems_version: 3.2.0.pre1
70
70
  signing_key:
71
71
  specification_version: 4
72
72
  summary: Write nikki every day!