bridgetown-prismic 0.1.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/LICENSE.txt +1 -1
- data/README.md +276 -32
- data/bridgetown-prismic.gemspec +3 -3
- data/bridgetown.automation.rb +8 -1
- data/lib/bridgetown-prismic/api.rb +27 -5
- data/lib/bridgetown-prismic/version.rb +1 -1
- data/lib/bridgetown-prismic.rb +8 -1
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cce35722e8584dd3378fa7ce61c3e6987749f15822b1f9f7bf22fced5f68a65d
|
4
|
+
data.tar.gz: 576383f25bcac3ea627846df09c03a21ce9c7e823d22b7d5b14ad18384d33f83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0088e0c7a0130f3b20f46ac7cdb182c22ac344a05d5af6ad126e760596be54e72bf50c48fb625e7d24a1ea3a11a311386113c280f7a8cb29d1aeecba5c1f7ac7'
|
7
|
+
data.tar.gz: 54cb371211505e21519e6bdcd205fd387fdd45d15276f2e49211fe50e11c9a3432327a713a70a9f0b85813c941515999ffcf2b975efbf0e661ab11cedcc74405
|
data/CHANGELOG.md
CHANGED
@@ -9,6 +9,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
9
9
|
|
10
10
|
...
|
11
11
|
|
12
|
+
## 0.2.2
|
13
|
+
|
14
|
+
- Lock Async dependency to < 2.0 until fiber race condition is resolved
|
15
|
+
|
16
|
+
## 0.2.1
|
17
|
+
|
18
|
+
- Fix issue where link resolvers didn't provide the full document
|
19
|
+
|
20
|
+
## 0.2.0
|
21
|
+
|
22
|
+
- Automatically paginate through results sets
|
23
|
+
|
24
|
+
## 0.1.2
|
25
|
+
|
26
|
+
- Add hash option to `provide_data`
|
27
|
+
|
12
28
|
## 0.1.1
|
13
29
|
|
14
30
|
- Fix bugs and test link resolvers
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,61 +1,305 @@
|
|
1
|
-
#
|
1
|
+
# Bridgetown Prismic CMS Plugin
|
2
2
|
|
3
|
-
|
3
|
+
The [Bridgetown](https://edge.bridgetownrb.com) Prismic plugin allows you to pull content directly out of your [Prismic CMS](https://prismic.io) repository and generate resources you can use in all of your templates and plugins the same as if they were files saved directly in your site's `src` folder. Posts, pages, and any custom collections you want to set up are fully supported.
|
4
4
|
|
5
|
-
|
5
|
+
In addition, this plugin allows you to set up draft previews so you can see how your content will look before it's published and deployed as a static site. This will require you to host a preview site on a platform which supports Ruby Rack-based applications. We recommend [Render](https://render.com), but you can use Heroku or most other platforms which support Ruby (Rails, etc.).
|
6
6
|
|
7
|
-
|
7
|
+
This plugin requires Ruby 3 and the latest alpha version of [Bridgetown 1.0](https://edge.bridgetownrb.com).
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
11
|
-
|
11
|
+
Add the gem to your Gemfile and set up initial configuration by running the automation script:
|
12
12
|
|
13
|
-
```
|
14
|
-
$
|
13
|
+
```sh
|
14
|
+
$ bin/bridgetown apply https://github.com/bridgetownrb/bridgetown-prismic
|
15
15
|
```
|
16
16
|
|
17
|
-
|
17
|
+
This will add a `prismic_repository` setting to your `bridgetown.config.yml` file. Replace that with the subdomain of your Prismic repo.
|
18
|
+
|
19
|
+
It will also set up a `models` folder where you will add the Bridgetown models corresponding to your Prismic custom types. More details on that below.
|
20
|
+
|
21
|
+
### Draft Previews
|
22
|
+
|
23
|
+
To set up previews using your Bridgetown Roda backend, modify your `server/roda_app.rb` file by adding:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require "bridgetown-prismic/roda/previews"
|
27
|
+
```
|
28
|
+
|
29
|
+
to the top of the file, and then adding:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
include BridgetownPrismic::Roda::Previews
|
33
|
+
```
|
34
|
+
|
35
|
+
right underneath `class RodaApp < Bridgetown::Rack::Roda`.
|
36
|
+
|
37
|
+
Also ensure you have the Bridgetown SSR plugin installed (aka `plugin :bridgetown_ssr` is somewhere above your `route do |r|` block).
|
38
|
+
|
39
|
+
Your file should end up looking something like this:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
require "bridgetown-prismic/roda/previews"
|
43
|
+
|
44
|
+
class RodaApp < Bridgetown::Rack::Roda
|
45
|
+
include BridgetownPrismic::Roda::Previews
|
46
|
+
|
47
|
+
plugin :bridgetown_ssr
|
48
|
+
|
49
|
+
route do |r|
|
50
|
+
Bridgetown::Rack::Routes.start! self
|
51
|
+
end
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
Next, create a `server/routes/preview.rb` route file:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
class Routes::Preview < Bridgetown::Rack::Routes
|
59
|
+
route do |r|
|
60
|
+
r.on "preview" do
|
61
|
+
# Route hit by the Prismic preview flow
|
62
|
+
# route: /preview
|
63
|
+
r.is do
|
64
|
+
unless prismic_preview_token
|
65
|
+
response.status = 403
|
66
|
+
next prismic_token_error_msg
|
67
|
+
end
|
68
|
+
|
69
|
+
r.redirect prismic_preview_redirect_url
|
70
|
+
end
|
71
|
+
|
72
|
+
# Rendering pathway to preview a page
|
73
|
+
# route: /preview/:custom_type/:id
|
74
|
+
r.is String, String do |custom_type, id|
|
75
|
+
unless prismic_preview_token
|
76
|
+
response.status = 403
|
77
|
+
next prismic_token_error_msg
|
78
|
+
end
|
79
|
+
|
80
|
+
save_prismic_preview_token
|
81
|
+
|
82
|
+
Bridgetown::Model::Base
|
83
|
+
.find("prismic://#{custom_type}/#{id}")
|
84
|
+
.render_as_resource
|
85
|
+
.output
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
```
|
91
|
+
|
92
|
+
This file handles two routes: `/preview` and `/preview/:custom_type/:id`. Upon clicking the preview icon in the Prismic editing interface, Prismic will hit your `/preview` route first with an access token. That saves a cookie, which is then used after the redirect to the `/preview/:custom_type/:id` route (which in practice will look something like `/page/YYsenhEAACIADwbi`). As long as you've set up your models correctly, Bridgetown will automatically know how to render the resource for the preview.
|
93
|
+
|
94
|
+
## Setting Up Your Content Models
|
95
|
+
|
96
|
+
This is where all the magic happens. ✨
|
97
|
+
|
98
|
+
By creating a content model class for each custom type in Prismic, you establish a 1:1 mapping between a piece of content in Prismic and a piece of content your site will use to build resources. The automation script installed an example of a **Post** content model. Let's take a closer look.
|
99
|
+
|
100
|
+
At the top of the file are a series of configuration options:
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
class << self
|
104
|
+
def collection_name = :posts
|
105
|
+
def prismic_custom_type = :blog_post
|
106
|
+
def prismic_slug(doc) = doc.slug
|
107
|
+
def prismic_url(doc)
|
108
|
+
doc_date = doc["blog_post.optional_publish_datetime"]&.value&.localtime || doc.first_publication_date
|
109
|
+
ymd = "#{doc_date.strftime("%Y")}/#{doc_date.strftime("%m")}/#{doc_date.strftime("%d")}"
|
110
|
+
"/#{ymd}/#{prismic_slug(doc)}/"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
```
|
114
|
+
|
115
|
+
* `collection_name`: this can be a built-in collection such as `posts` or `pages`, or it can be a custom collection you've configured in `bridgetown.config.yml`.
|
116
|
+
* `prismic_custom_type`: this will be the "API ID" of the custom type in Prismic.
|
117
|
+
* `prismic_slug`: this should return the "slug" (aka `my-document-title`) of a Prismic document. In this example the slug Prismic chose is being used verbatim, but you can make alterations as you see fit.
|
118
|
+
* `prismic_url`: this should return the full URL of the final destination for the content. It should match the permalink settings of your collection. This is used by the "link resolver"—aka anywhere in a Prismic document where you've added a link to another Prismic document, the URL for that link is resolved using this return value for the custom type.
|
119
|
+
|
120
|
+
All right, with those options out of the way, on to the main event:
|
18
121
|
|
19
122
|
```ruby
|
20
|
-
|
123
|
+
def self.process_prismic_document(doc)
|
124
|
+
provide_data do
|
125
|
+
# Variable # Prismic Field # Formatting
|
126
|
+
id doc.id
|
127
|
+
slug from: -> { prismic_slug(doc) }
|
128
|
+
type doc.type
|
129
|
+
created_at doc.first_publication_date
|
130
|
+
date doc["blog_post.optional_publish_datetime"]&.value&.localtime || created_at
|
131
|
+
|
132
|
+
layout :post
|
133
|
+
title doc["blog_post.title"] .as_text
|
134
|
+
subtitle doc["blog_post.subtitle"] &.as_text
|
135
|
+
author doc["blog_post.author_name"] &.as_text
|
136
|
+
featured_image doc["blog_post.featured_image"] &.url
|
137
|
+
|
138
|
+
content doc["blog_post.post_body"] &.as_html with_links
|
139
|
+
end
|
140
|
+
end
|
21
141
|
```
|
22
142
|
|
23
|
-
|
143
|
+
This where you create the 1:1 mappings between the Prismic fields and the "front matter" (aka data) + content of your model/resource. Any time you access the resource in templates by writing `resource.data.title` or `resource.content`, it will be pulling those values from these mappings.
|
24
144
|
|
25
|
-
|
145
|
+
Within the `provide_data` block, you use a special Ruby DSL in a spreadsheet-like manner to set up the mappings. On the left-hand "column", you specify the name of the front matter variable, as well as `content` (optional but recommended). In the middle column, you use Prismic's Ruby API to get a field value or metadata. On the right-hand column, you "coerce" the value into the type of data you're looking for. Note that any field which the author hasn't filled in has a `nil` value, so you can see we're using Ruby's safe navigation operator `&` (whimsically known as the "lonely operator") most of the time so nil values won't crash the import process.
|
26
146
|
|
27
|
-
|
147
|
+
You can [read more about Prismic's Ruby Document API here](https://prismic.io/docs/technologies/the-document-object-ruby) for information on when to use `value` or `as_text` or `url`, etc.
|
28
148
|
|
29
|
-
|
149
|
+
A few notes on the Ruby DSL:
|
30
150
|
|
31
|
-
|
151
|
+
* Any time you see `from: -> { ... }`, that's a lambda which is evaluated directly in the model object scope. Essentially it's a way to "escape" the DSL.
|
152
|
+
* You can nest values using a block, for example:
|
153
|
+
```ruby
|
154
|
+
attachment do
|
155
|
+
name doc["bulletin.name"] .value.downcase
|
156
|
+
pdf_url doc["bulletin.pdf_file"] .url
|
157
|
+
end
|
158
|
+
```
|
159
|
+
which would let you access the data like so:
|
160
|
+
```ruby
|
161
|
+
resource.data.attachment.name
|
162
|
+
resource.data.attachment.pdf_url
|
163
|
+
```
|
164
|
+
* You can call `provide_data` from within a `from:` lambda, which is very useful when looping through Prismic slices and generating nested content. For example:
|
165
|
+
```ruby
|
166
|
+
tiles from: -> {
|
167
|
+
doc["homepage.body"].slices.map do |slice|
|
168
|
+
case slice.slice_type
|
169
|
+
when "homepage_tile"
|
170
|
+
slice.repeat.group_documents.map do |tile|
|
171
|
+
provide_data do
|
172
|
+
backdrop tile["backdrop"] &.url
|
173
|
+
heading tile["heading"] &.as_text
|
174
|
+
description tile["description"]&.as_html with_links
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end.flatten.compact
|
179
|
+
}
|
180
|
+
```
|
181
|
+
This would result in a `resource.data.tiles` array with one or more hashes including `backdrop`, `heading`, and `description` keys.
|
32
182
|
|
33
|
-
|
183
|
+
The Ruby DSL is pretty nifty, but you may occasionally run into a conflict between your variable name and an existing Ruby method. For example, you couldn't add something like `method doc["page.method"] .as_text` because `method` is an existing Ruby object method. Instead, use `set` like so:
|
184
|
+
|
185
|
+
```ruby
|
186
|
+
set :method, doc["page.method"].as_text
|
187
|
+
```
|
188
|
+
|
189
|
+
Finally, if you decide to need to bail and want to provide a standard hash instead of using the Ruby DSL, you can do that too! It's not as flexible as the DSL because you can't arbitrarily insert multi-line statements of Ruby code within the data hash, but it's easy enough to understand:
|
190
|
+
|
191
|
+
```ruby
|
192
|
+
def self.process_prismic_document(doc)
|
193
|
+
provide_data({
|
194
|
+
# Variable # Prismic Field # Formatting
|
195
|
+
id: doc.id,
|
196
|
+
slug: prismic_slug(doc),
|
197
|
+
type: doc.type,
|
198
|
+
created_at: doc.first_publication_date,
|
199
|
+
|
200
|
+
layout: :post,
|
201
|
+
title: doc["test_page.title"] .as_text,
|
202
|
+
|
203
|
+
content: doc["test_page.body"] &.as_html(with_links),
|
204
|
+
})
|
205
|
+
end
|
206
|
+
```
|
207
|
+
|
208
|
+
Just remember to put all your colons, commas, and parentheses in the right places! 😅
|
209
|
+
|
210
|
+
### Mind your defaults!
|
211
|
+
|
212
|
+
One gotcha to be aware of is that Prismic-sourced resources _will not pick up front matter defaults_ from any `_defaults.yml` files you may add to your `src` tree (for example in `src/_posts`). This is because `_defaults.yml` acts upon the file system directly, and resources originating from Prismic aren't part of the filesystem per se.
|
213
|
+
|
214
|
+
However, you can definitely use the YAML-based front matter defaults which you add to `bridgetown.config.yml` to set defaults for any collection. In addition, you can put any "default" data directly in your model definitions (such as the `layout: post` example above).
|
215
|
+
|
216
|
+
### Trying Out Your Models
|
217
|
+
|
218
|
+
The Bridgetown console is a good place to inspect your content. Just run `bin/bridgetown console` or `c` and then you can poke through your collections and see what's what.
|
219
|
+
|
220
|
+
```
|
221
|
+
irb> resource = site.collections.pages.resources.find { |page| page.data.slug == "my-page" }
|
222
|
+
|
223
|
+
irb> resource.data
|
224
|
+
|
225
|
+
irb> resource.content
|
226
|
+
|
227
|
+
irb> resource.model.prismic_doc # access the original Prismic Document object
|
228
|
+
```
|
229
|
+
|
230
|
+
## Indicating Previews in Your Site's Layout
|
231
|
+
|
232
|
+
When previewing content, it's helpful to know at a glance that you're looking at a preview, not a piece of published content. You can add a conditional block to the top of your layout's `<body>` which will detect the presense of a preview token and display a preview notice at the top of the page.
|
233
|
+
|
234
|
+
Example for a Liquid layout:
|
235
|
+
|
236
|
+
```liquid
|
237
|
+
{% if site.prismic_preview_token %}
|
238
|
+
<p class="text-center" style="padding:7px; background:rgb(255, 230, 0); border-bottom:2px solid #333; margin:0; font-family:sans-serif; font-weight:bold; font-size:110%">
|
239
|
+
PREVIEW
|
240
|
+
</p>
|
241
|
+
{% endif %}
|
242
|
+
```
|
243
|
+
|
244
|
+
or an ERB layout:
|
245
|
+
|
246
|
+
```erb
|
247
|
+
<% if site.config.prismic_preview_token %>
|
248
|
+
<p class="text-center" style="padding:7px; background:rgb(255, 230, 0); border-bottom:2px solid #333; margin:0; font-family:sans-serif; font-weight:bold; font-size:110%">
|
249
|
+
PREVIEW
|
250
|
+
</p>
|
251
|
+
<% end %>
|
252
|
+
```
|
253
|
+
|
254
|
+
## Deploying on Render
|
255
|
+
|
256
|
+
You can easily deploy your preview site on [Render](https://render.com) and use it for previewing draft content. For modest website deployments, your preview site could also serve as your public site (with the public only seeing the "static" published content), but generally we recommend a second static site deployment for the public to access (which Render also supports—you can run `bin/bridgetown configure render` to set up a static site config).
|
257
|
+
|
258
|
+
The starter plan (US $7/month as of the time of this writing) is recommended. Simply add (or edit) a `render.yaml` file in the root of your site repo:
|
259
|
+
|
260
|
+
```yaml
|
261
|
+
services:
|
262
|
+
- type: web
|
263
|
+
name: your-site-name-here
|
264
|
+
env: ruby
|
265
|
+
repo: https://github.com/username/your-site-name-here
|
266
|
+
buildCommand: bundle install && yarn install && bin/bridgetown frontend:build
|
267
|
+
startCommand: bin/bridgetown start
|
268
|
+
envVars:
|
269
|
+
- key: BRIDGETOWN_ENV
|
270
|
+
value: production
|
271
|
+
```
|
272
|
+
|
273
|
+
Once your repo is checked into GitHub, you can access it in Render and it will be configured and deployed "automagically." 😁
|
274
|
+
|
275
|
+
After that, in your Prismic CMS settings under "Previews", you can create a new preview with the following settings:
|
276
|
+
|
277
|
+
* Site Name: Preview
|
278
|
+
* Domain: https://your-site-name-here.onrender.com
|
279
|
+
* Link Resolver: /preview
|
280
|
+
|
281
|
+
In addition, you'll want to set up a webhook so any published content will trigger a rebuild of your preview and public sites.
|
282
|
+
|
283
|
+
Go to the "Webhooks" settings page and add a new webook:
|
284
|
+
|
285
|
+
* Name of the webhook: Preview Site (or Public Site)
|
286
|
+
* URL: (you will need to obtain this from your [Render site's deploy hook config (see documentation)](https://render.com/docs/deploy-hooks)
|
287
|
+
* Secret: (leave this blank)
|
288
|
+
|
289
|
+
## Questions? Feedback?
|
290
|
+
|
291
|
+
Please submit an issue to this GitHub repo and we'll address your concerns as soon as possible. In addition, [you can get in touch with the Bridgetown core team and community members](https://www.bridgetownrb.com/docs/community) through the usual channels.
|
292
|
+
|
293
|
+
## Testing This Gem
|
34
294
|
|
35
295
|
* Run `bundle exec rake test` to run the test suite
|
36
296
|
* Or run `script/cibuild` to validate with Rubocop and Minitest together.
|
37
297
|
|
38
298
|
## Contributing
|
39
299
|
|
40
|
-
1. Fork it (https://github.com/
|
300
|
+
1. Fork it (https://github.com/bridgetownrb/bridgetown-prismic/fork)
|
41
301
|
2. Clone the fork using `git clone` to your local development machine.
|
42
302
|
3. Create your feature branch (`git checkout -b my-new-feature`)
|
43
303
|
4. Commit your changes (`git commit -am 'Add some feature'`)
|
44
304
|
5. Push to the branch (`git push origin my-new-feature`)
|
45
305
|
6. Create a new Pull Request
|
46
|
-
|
47
|
-
----
|
48
|
-
|
49
|
-
## Releasing (you can delete this section in your own plugin repo)
|
50
|
-
|
51
|
-
To release a new version of the plugin, simply bump up the version number in both `version.rb` and
|
52
|
-
`package.json`, and then run `script/release`. This will require you to have a registered account
|
53
|
-
with both the [RubyGems.org](https://rubygems.org) and [NPM](https://www.npmjs.com) registries.
|
54
|
-
You can optionally remove the `package.json` and `frontend` folder if you don't need to package frontend
|
55
|
-
assets for Webpack.
|
56
|
-
|
57
|
-
If you run into any problems or need further guidance, please check out our [Bridgetown community resources](https://www.bridgetownrb.com/docs/community)
|
58
|
-
where friendly folks are standing by to help you build and release your plugin or theme.
|
59
|
-
|
60
|
-
**NOTE:** make sure you add the `bridgetown-plugin` [topic](https://github.com/topics/bridgetown-plugin) to your
|
61
|
-
plugin's GitHub repo so the plugin or theme will show up on [Bridgetown's official Plugin Directory](https://www.bridgetownrb.com/plugins)! (There may be a day or so delay before you see it appear.)
|
data/bridgetown-prismic.gemspec
CHANGED
@@ -7,8 +7,8 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.version = BridgetownPrismic::VERSION
|
8
8
|
spec.author = "Bridgetown Team"
|
9
9
|
spec.email = "maintainers@bridgetownrb.com"
|
10
|
-
spec.summary = "
|
11
|
-
spec.homepage = "https://github.com/
|
10
|
+
spec.summary = "A Prismic CMS integration plugin for Bridgetown"
|
11
|
+
spec.homepage = "https://github.com/bridgetownrb/bridgetown-prismic"
|
12
12
|
spec.license = "MIT"
|
13
13
|
|
14
14
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|script|spec|features|frontend)/!) }
|
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.add_dependency "bridgetown", ">= 1.0.0.alpha8", "< 2.0"
|
21
21
|
spec.add_dependency "prismic.io", ">= 1.8"
|
22
|
-
spec.add_dependency "async", ">= 1.30"
|
22
|
+
spec.add_dependency "async", ">= 1.30", "< 2.0"
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler"
|
25
25
|
spec.add_development_dependency "rake", ">= 13.0"
|
data/bridgetown.automation.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
say_status :prismic, "Installing the bridgetown-prismic plugin..."
|
2
|
+
|
1
3
|
add_bridgetown_plugin("bridgetown-prismic")
|
2
4
|
|
3
5
|
append_to_file "bridgetown.config.yml" do
|
4
6
|
<<~YAML
|
5
7
|
|
8
|
+
|
6
9
|
# Prismic config:
|
7
10
|
prismic_repository: repo_name_here
|
8
11
|
autoload_paths:
|
@@ -11,4 +14,8 @@ append_to_file "bridgetown.config.yml" do
|
|
11
14
|
YAML
|
12
15
|
end
|
13
16
|
|
14
|
-
|
17
|
+
get "https://raw.githubusercontent.com/bridgetownrb/bridgetown-prismic/main/test/fixtures/models/post.rb",
|
18
|
+
"models/post.rb"
|
19
|
+
|
20
|
+
say_status :prismic, "All set! Double-check your Prismic settings and model files and review docs at"
|
21
|
+
say_status :prismic, "https://github.com/bridgetownrb/bridgetown-prismic"
|
@@ -10,7 +10,12 @@ module BridgetownPrismic
|
|
10
10
|
next "/preview/#{link.type}/#{link.id}" if site.config.prismic_preview_token
|
11
11
|
|
12
12
|
if model_exists_for_prismic_type? link.type
|
13
|
-
|
13
|
+
full_doc = Async do
|
14
|
+
Bridgetown::Current.site = site # ensure fiber has copy of the current site
|
15
|
+
site.config.prismic_api.getByID(link.id)
|
16
|
+
end.wait
|
17
|
+
|
18
|
+
model_for_prismic_type(link.type).prismic_url(full_doc)
|
14
19
|
else
|
15
20
|
"/"
|
16
21
|
end
|
@@ -20,10 +25,27 @@ module BridgetownPrismic
|
|
20
25
|
def query_prismic(custom_type, options = {})
|
21
26
|
Bridgetown.logger.info "Prismic API:", "Loading #{custom_type.to_s.green}..."
|
22
27
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
28
|
+
results = []
|
29
|
+
page = 1
|
30
|
+
finalpage = false
|
31
|
+
options["pageSize"] ||= 100 # pull in as much data as possible for a single request
|
32
|
+
|
33
|
+
until finalpage
|
34
|
+
options["page"] = page
|
35
|
+
|
36
|
+
response = BridgetownPrismic
|
37
|
+
.api
|
38
|
+
.query(Prismic::Predicates.at("document.type", custom_type.to_s), options)
|
39
|
+
|
40
|
+
results += response.results
|
41
|
+
if response.total_pages > page
|
42
|
+
page += 1
|
43
|
+
else
|
44
|
+
finalpage = true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
results
|
27
49
|
end
|
28
50
|
|
29
51
|
def query_prismic_and_generate_resources_for(klass)
|
data/lib/bridgetown-prismic.rb
CHANGED
@@ -22,7 +22,14 @@ Bridgetown::Model::Base.class_eval do # rubocop:disable Metrics/BlockLength
|
|
22
22
|
|
23
23
|
def self.with_links = Bridgetown::Current.site.config.prismic_link_resolver
|
24
24
|
|
25
|
-
def self.provide_data(&block)
|
25
|
+
def self.provide_data(hsh = nil, &block)
|
26
|
+
if hsh
|
27
|
+
hsh.each do |k, v|
|
28
|
+
@prismic_data.set k, v
|
29
|
+
end
|
30
|
+
return
|
31
|
+
end
|
32
|
+
|
26
33
|
@prismic_data.provide_data(&block)
|
27
34
|
end
|
28
35
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bridgetown-prismic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bridgetown Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bridgetown
|
@@ -51,6 +51,9 @@ dependencies:
|
|
51
51
|
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '1.30'
|
54
|
+
- - "<"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '2.0'
|
54
57
|
type: :runtime
|
55
58
|
prerelease: false
|
56
59
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,6 +61,9 @@ dependencies:
|
|
58
61
|
- - ">="
|
59
62
|
- !ruby/object:Gem::Version
|
60
63
|
version: '1.30'
|
64
|
+
- - "<"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '2.0'
|
61
67
|
- !ruby/object:Gem::Dependency
|
62
68
|
name: bundler
|
63
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,7 +128,7 @@ files:
|
|
122
128
|
- lib/bridgetown-prismic/roda/previews.rb
|
123
129
|
- lib/bridgetown-prismic/version.rb
|
124
130
|
- lib/bridgetown/utils/prismic_data.rb
|
125
|
-
homepage: https://github.com/
|
131
|
+
homepage: https://github.com/bridgetownrb/bridgetown-prismic
|
126
132
|
licenses:
|
127
133
|
- MIT
|
128
134
|
metadata: {}
|
@@ -141,8 +147,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
147
|
- !ruby/object:Gem::Version
|
142
148
|
version: '0'
|
143
149
|
requirements: []
|
144
|
-
rubygems_version: 3.
|
150
|
+
rubygems_version: 3.3.3
|
145
151
|
signing_key:
|
146
152
|
specification_version: 4
|
147
|
-
summary:
|
153
|
+
summary: A Prismic CMS integration plugin for Bridgetown
|
148
154
|
test_files: []
|