contemble 0.1.4 → 0.1.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 +49 -0
- data/lib/contemble/resources.rb +23 -17
- data/lib/contemble/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: a7e43e5e52bb7623cf2f0f5caccaa49c4ee477fd6aa8084fb22f69c2ef1c85df
|
|
4
|
+
data.tar.gz: b99068ed77740799c1b7f523358bae21721d50524fd91e77dec9675c05a0c7e0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a8ad1c2765315049eee9d9e8ba2b07c8a9027302ae5508de1cf9507a0b99c2664fa66a39f92698f144c22cca505781d2e3ed22a1f238cd698df58512e417c358
|
|
7
|
+
data.tar.gz: d29318b90501772eb58a3eb799bc9a71e4095f2790a5c9a9fe4446e9414b70e413c2f24ee0bd70eccc505f424450ff53c6d3ce43e85cf031fcfb24fc26a47328
|
data/README.md
CHANGED
|
@@ -37,6 +37,13 @@ posts = client.collections.posts
|
|
|
37
37
|
# Get posts from specific collection
|
|
38
38
|
posts = client.collections.posts(collection_name: "blog")
|
|
39
39
|
|
|
40
|
+
# Get posts with pagination
|
|
41
|
+
result = client.collections.posts(collection_name: "blog", page: 2, per_page: 50)
|
|
42
|
+
result["data"] # Array of posts
|
|
43
|
+
result["meta"]["pagination"]["page"] # Current page
|
|
44
|
+
result["meta"]["pagination"]["pageCount"] # Total pages
|
|
45
|
+
result["meta"]["pagination"]["total"] # Total posts
|
|
46
|
+
|
|
40
47
|
# Get individual post
|
|
41
48
|
post = client.posts.show(slug: "post-slug")
|
|
42
49
|
|
|
@@ -68,6 +75,48 @@ article_schema = client.schema.article(slug: "post-slug")
|
|
|
68
75
|
|
|
69
76
|
Each post includes a `url` field for easy linking based on your configured `post_path`.
|
|
70
77
|
|
|
78
|
+
### Pagination
|
|
79
|
+
|
|
80
|
+
By default, `posts()` returns the first 20 posts. Pagination metadata is included in the response body.
|
|
81
|
+
|
|
82
|
+
```ruby
|
|
83
|
+
# Get page 2 with 50 posts per page
|
|
84
|
+
result = client.collections.posts(collection_name: "blog", page: 2, per_page: 50)
|
|
85
|
+
|
|
86
|
+
# Access posts
|
|
87
|
+
result["data"]
|
|
88
|
+
|
|
89
|
+
# Access pagination metadata
|
|
90
|
+
result["meta"]["pagination"]["page"] # Current page (2)
|
|
91
|
+
result["meta"]["pagination"]["pageSize"] # Posts per page (50)
|
|
92
|
+
result["meta"]["pagination"]["pageCount"] # Total pages available
|
|
93
|
+
result["meta"]["pagination"]["total"] # Total number of posts
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Response format:
|
|
97
|
+
|
|
98
|
+
```json
|
|
99
|
+
{
|
|
100
|
+
"data": [
|
|
101
|
+
{
|
|
102
|
+
"slug": "post-slug",
|
|
103
|
+
"title": "Post Title",
|
|
104
|
+
...
|
|
105
|
+
}
|
|
106
|
+
],
|
|
107
|
+
"meta": {
|
|
108
|
+
"pagination": {
|
|
109
|
+
"page": 2,
|
|
110
|
+
"pageSize": 50,
|
|
111
|
+
"pageCount": 10,
|
|
112
|
+
"total": 500
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Maximum posts per page is 100. Defaults: `page: 1`, `per_page: 20`.
|
|
119
|
+
|
|
71
120
|
**Sitemap XML** returns ready-to-use XML that can be saved to a file, proxied through your server, or included in your sitemap index.
|
|
72
121
|
|
|
73
122
|
### Sitemap Usage
|
data/lib/contemble/resources.rb
CHANGED
|
@@ -11,25 +11,30 @@ module Contemble
|
|
|
11
11
|
@client.get("/collections")
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
def posts(collection_name: nil)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
else
|
|
18
|
-
collections = list
|
|
19
|
-
all_posts = []
|
|
14
|
+
def posts(collection_name: nil, page: 1, per_page: 20)
|
|
15
|
+
if collection_name
|
|
16
|
+
response = @client.get("/collections/#{collection_name}?page=#{page}&per_page=#{per_page}")
|
|
20
17
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
end
|
|
18
|
+
posts_data = response["data"].map do |post|
|
|
19
|
+
post.merge("url" => "#{Contemble.post_path}/#{post["slug"]}")
|
|
20
|
+
end
|
|
25
21
|
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
{
|
|
23
|
+
"data" => posts_data,
|
|
24
|
+
"meta" => response["meta"]
|
|
25
|
+
}
|
|
26
|
+
else
|
|
27
|
+
collections = list
|
|
28
|
+
all_posts = []
|
|
29
|
+
|
|
30
|
+
collections.each do |collection|
|
|
31
|
+
response = @client.get("/collections/#{collection["name"]}?page=#{page}&per_page=#{per_page}")
|
|
32
|
+
all_posts.concat(response["data"])
|
|
33
|
+
end
|
|
28
34
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
)
|
|
35
|
+
all_posts.map do |post|
|
|
36
|
+
post.merge("url" => "#{Contemble.post_path}/#{post["slug"]}")
|
|
37
|
+
end
|
|
33
38
|
end
|
|
34
39
|
end
|
|
35
40
|
end
|
|
@@ -40,7 +45,8 @@ module Contemble
|
|
|
40
45
|
end
|
|
41
46
|
|
|
42
47
|
def show(slug:)
|
|
43
|
-
@client.get("/posts/#{slug}")
|
|
48
|
+
response = @client.get("/posts/#{slug}")
|
|
49
|
+
response["data"]
|
|
44
50
|
end
|
|
45
51
|
end
|
|
46
52
|
|
data/lib/contemble/version.rb
CHANGED