contemble 0.1.3 → 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 +70 -0
- data/lib/contemble/client.rb +4 -0
- data/lib/contemble/resources.rb +33 -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,11 +37,21 @@ 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
|
|
|
43
50
|
# Get sitemap XML
|
|
44
51
|
sitemap_xml = client.sitemap.xml
|
|
52
|
+
|
|
53
|
+
# Get article schema
|
|
54
|
+
article_schema = client.schema.article(slug: "post-slug")
|
|
45
55
|
```
|
|
46
56
|
|
|
47
57
|
### Available Data
|
|
@@ -65,6 +75,48 @@ sitemap_xml = client.sitemap.xml
|
|
|
65
75
|
|
|
66
76
|
Each post includes a `url` field for easy linking based on your configured `post_path`.
|
|
67
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
|
+
|
|
68
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.
|
|
69
121
|
|
|
70
122
|
### Sitemap Usage
|
|
@@ -87,6 +139,24 @@ end
|
|
|
87
139
|
|
|
88
140
|
The sitemap URLs will use your configured base URL from your Contemble team settings. For large teams with many posts, this will automatically return a sitemap index that references multiple sitemap files.
|
|
89
141
|
|
|
142
|
+
### Schema Usage
|
|
143
|
+
|
|
144
|
+
```ruby
|
|
145
|
+
client = Contemble::Client.new(api_key: "your_api_key")
|
|
146
|
+
|
|
147
|
+
# Get JSON-LD schema for a specific article
|
|
148
|
+
schema = client.schema.article(slug: "my-post")
|
|
149
|
+
|
|
150
|
+
# Use in your Rails template
|
|
151
|
+
content_for :head do
|
|
152
|
+
content_tag :script, type: "application/ld+json" do
|
|
153
|
+
raw schema.to_json
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**Article Schema** returns JSON-LD structured data including headline, description, dates, images, and publisher information for SEO rich snippets.
|
|
159
|
+
|
|
90
160
|
## License
|
|
91
161
|
|
|
92
162
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/contemble/client.rb
CHANGED
|
@@ -25,6 +25,10 @@ module Contemble
|
|
|
25
25
|
@sitemap ||= Resources::Sitemap.new(self)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
def schema
|
|
29
|
+
@schema ||= Resources::Schema.new(self)
|
|
30
|
+
end
|
|
31
|
+
|
|
28
32
|
def get(path, params = {})
|
|
29
33
|
uri = URI("#{@base_url}#{path}")
|
|
30
34
|
uri.query = URI.encode_www_form(params) unless params.empty?
|
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 = []
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
|
34
|
+
|
|
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
|
|
|
@@ -53,5 +59,15 @@ module Contemble
|
|
|
53
59
|
@client.get_xml("/sitemap.xml")
|
|
54
60
|
end
|
|
55
61
|
end
|
|
62
|
+
|
|
63
|
+
class Schema
|
|
64
|
+
def initialize(client)
|
|
65
|
+
@client = client
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def article(slug:)
|
|
69
|
+
@client.get("/posts/#{slug}/schema")
|
|
70
|
+
end
|
|
71
|
+
end
|
|
56
72
|
end
|
|
57
73
|
end
|
data/lib/contemble/version.rb
CHANGED