postwave 0.1.0 → 0.1.2

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: 3659ecd8d7d5b7d1fdfaddb0b8538b86414e34687febec04f29c3352dff8d6c2
4
- data.tar.gz: f877ba937e8361518ca4a0c16f5d3ae77dfb101ac94becd0e2f2c3ae5f01abf4
3
+ metadata.gz: b4511f2e9288a14247515ff919efbcdfaf4aef9f7e6ae5d7de5c207795307d73
4
+ data.tar.gz: 6997bdd3f519948e40fbf701d792bc761e0d563f23bd171b47cf35b6ba652fb8
5
5
  SHA512:
6
- metadata.gz: a866429e4ad00e427b8302527e4eafcd488d16b938b51d12f370104d9a8dc0abdec1f5b868f62c0afb7b10ac162a120bbe2494d6b4347f521c9c6f35cf9c00cd
7
- data.tar.gz: 89575f81e742ca2bcd40d14c6e54ed3618daf4ad8434720ed65b6cdd4350e2189ba0721265351d62d565c49c9ac8c9a4686e96e93eabc358e29984a66999f3c1
6
+ metadata.gz: 3248a5fdd235809dee5026f53ecf5dd637c96a3e69e6acff19d91617a6632ae61e49989a79dd16f91258b21de14d54ed748b31af5dbb2974d3e0c97d6f65accf
7
+ data.tar.gz: 74bd0b0f980cb534b63c06a3374e4d1e807c68113cf18cc56f1bf6aa601adb4b4c2ae0c5bb55103ed2d2a496064b1b730435933dda937eb2aa446a92bf3279fc
data/README.md CHANGED
@@ -121,6 +121,10 @@ post = postwave_client.post("my-great-post")
121
121
 
122
122
  puts post.title
123
123
  # "My Great Post"
124
+ puts post.body
125
+ # "bla bla bla..."
126
+ puts post.body_html # uses Redcarpt to convert body Markdown to HTML
127
+ # "<p>bla bla bla...</p>"
124
128
  ```
125
129
 
126
130
  ### Get a Collection of Posts
@@ -175,12 +179,54 @@ tag = postwave_clinet.tag("tag1")
175
179
 
176
180
  ### Get Text For An RSS Feed
177
181
 
182
+ This will give you the text for an Atom feed of your blog.
183
+
178
184
  ```ruby
179
185
  rss = postwave_client.rss
180
186
 
181
187
  # "<?xml version="1.0" encoding="utf-8"?>..."
182
188
  ```
183
189
 
190
+ ### Get Pagination Information
191
+
192
+ This will give you a `Postwave::Pagination` object that you can use to build pagination in your Postwave powered site.
193
+
194
+ ```ruby
195
+ pagination = postwave_client.pagination(current_page: 3, per_page: 10)
196
+
197
+ # <Postwave::Pagination current_page=3, prev_page=2, next_page=4, total_pages=20>
198
+ ```
199
+
200
+ ### Get An Archive of Posts
201
+
202
+ This returns a Hash with year as the key and an ordered array of PostStubs
203
+
204
+ ```ruby
205
+ archive = postwave_client.archive
206
+
207
+ # {
208
+ # 2025 =>
209
+ # [<Postwave::PostStub title="My Great Post"...>, <PostwaveStub...>, ...],
210
+ # 2024 =>
211
+ # [<PostwaveStub...>, <PostwaveStub...>]
212
+ # }
213
+ ```
214
+
215
+ You can pass in a `by: "month"` parameter to further subdivide the archive by month.
216
+
217
+ ```ruby
218
+ archive = postwave_client.archive(by: "month")
219
+
220
+ # {
221
+ # 2025 =>
222
+ # 1 => [<PostwaveStub...>, <PostwaveStub...>],
223
+ # 2 => [<PostwaveStub...>, <PostwaveStub...>]
224
+ # 2024 =>
225
+ # 11 => [<PostwaveStub...>, <PostwaveStub...>],
226
+ # 12 => [<PostwaveStub...>, <PostwaveStub...>]
227
+ # }
228
+ ```
229
+
184
230
  ## Run Tests
185
231
 
186
232
  ```
@@ -8,6 +8,7 @@ require "yaml"
8
8
 
9
9
  Postwave::PostStub = Struct.new(:date, :title, :slug)
10
10
  Postwave::Tag = Struct.new(:name, :count, :post_slugs)
11
+ Postwave::Pagination = Struct.new(:current_page, :prev_page, :next_page, :total_pages)
11
12
 
12
13
  module Postwave
13
14
  class Client
@@ -29,6 +30,18 @@ module Postwave
29
30
  working_index[offset, count]
30
31
  end
31
32
 
33
+ def archive(by: "year")
34
+ working_index = @full_index || get_full_index
35
+ post_hash = posts.group_by { |post| post.date.year }.transform_values { |posts| posts.sort_by(&:date) }
36
+ if by == "month"
37
+ post_hash.each do |key, value|
38
+ post_hash[key] = value.group_by { |post| post.date.month }
39
+ end
40
+ end
41
+
42
+ post_hash
43
+ end
44
+
32
45
  # returns: a post - Postwave::Post
33
46
  def post(slug)
34
47
  post_file_path = Dir["#{File.join(@blog_root, POSTS_DIR)}/*#{slug}.md"].first
@@ -69,6 +82,16 @@ module Postwave
69
82
  rss.read
70
83
  end
71
84
 
85
+ # reuturns: a Pagination Struct - <struct Pagination current_page=3, prev_page=2, next_page=4, total_pages=20>
86
+ def pagination(current_page: 1, per_page: 10)
87
+ summary = @blog_summary || get_summary
88
+ total_pages = (summary[:post_count].to_f / per_page).ceil
89
+ in_bound_current = current_page.clamp(1, total_pages)
90
+ prev_page = in_bound_current > 1 ? in_bound_current - 1 : nil
91
+ next_page = in_bound_current < total_pages ? in_bound_current + 1 : nil
92
+ Postwave::Pagination.new(in_bound_current, prev_page, next_page, total_pages)
93
+ end
94
+
72
95
  private
73
96
 
74
97
  def is_valid_config?(config_path)
@@ -1,3 +1,3 @@
1
1
  module Postwave
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postwave
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Schwantes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-17 00:00:00.000000000 Z
11
+ date: 2025-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet