bridgetown-prismic 0.2.0 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +12 -4
- data/bridgetown-prismic.gemspec +1 -1
- data/lib/bridgetown-prismic/api.rb +12 -1
- data/lib/bridgetown-prismic/origin.rb +0 -1
- data/lib/bridgetown-prismic/version.rb +1 -1
- data/lib/bridgetown-prismic.rb +0 -4
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a64037c715098425b27a464a43b5f8cea1edaf1127b669fbc4df73405b9aede8
|
4
|
+
data.tar.gz: 1fa416c491f88cc63e8f20f09432888bfd02abdb83f5056570a7f621facfa797
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 942a5d2e94dbfb4dd6aca256d1313bbbfd1cca88f5e540ff4f72ddb954c144fcfca5abb527900ff5caec1f9cb285c93e1d77edbcd47f470814da97e97c6c4552
|
7
|
+
data.tar.gz: 425c8b63a93eb13393cb77ce6f14de8b8f13dcd2f8da8af0c5330badacf3a5f6219fd0bf7b21303add95484a4361d02bbf9c3d5a96b53fc908fe89e8cdf53cab
|
data/CHANGELOG.md
CHANGED
@@ -9,6 +9,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
9
9
|
|
10
10
|
...
|
11
11
|
|
12
|
+
## 0.2.3
|
13
|
+
|
14
|
+
- Register resource extensions upfront
|
15
|
+
|
16
|
+
## 0.2.2
|
17
|
+
|
18
|
+
- Lock Async dependency to < 2.0 until fiber race condition is resolved
|
19
|
+
|
20
|
+
## 0.2.1
|
21
|
+
|
22
|
+
- Fix issue where link resolvers didn't provide the full document
|
23
|
+
|
12
24
|
## 0.2.0
|
13
25
|
|
14
26
|
- Automatically paginate through results sets
|
data/README.md
CHANGED
@@ -115,7 +115,7 @@ end
|
|
115
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
116
|
* `prismic_custom_type`: this will be the "API ID" of the custom type in Prismic.
|
117
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
|
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
119
|
|
120
120
|
All right, with those options out of the way, on to the main event:
|
121
121
|
|
@@ -129,6 +129,7 @@ def self.process_prismic_document(doc)
|
|
129
129
|
created_at doc.first_publication_date
|
130
130
|
date doc["blog_post.optional_publish_datetime"]&.value&.localtime || created_at
|
131
131
|
|
132
|
+
layout :post
|
132
133
|
title doc["blog_post.title"] .as_text
|
133
134
|
subtitle doc["blog_post.subtitle"] &.as_text
|
134
135
|
author doc["blog_post.author_name"] &.as_text
|
@@ -141,7 +142,7 @@ end
|
|
141
142
|
|
142
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.
|
143
144
|
|
144
|
-
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 (
|
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.
|
145
146
|
|
146
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.
|
147
148
|
|
@@ -185,7 +186,7 @@ The Ruby DSL is pretty nifty, but you may occasionally run into a conflict betwe
|
|
185
186
|
set :method, doc["page.method"].as_text
|
186
187
|
```
|
187
188
|
|
188
|
-
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!
|
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:
|
189
190
|
|
190
191
|
```ruby
|
191
192
|
def self.process_prismic_document(doc)
|
@@ -196,6 +197,7 @@ def self.process_prismic_document(doc)
|
|
196
197
|
type: doc.type,
|
197
198
|
created_at: doc.first_publication_date,
|
198
199
|
|
200
|
+
layout: :post,
|
199
201
|
title: doc["test_page.title"] .as_text,
|
200
202
|
|
201
203
|
content: doc["test_page.body"] &.as_html(with_links),
|
@@ -205,6 +207,12 @@ end
|
|
205
207
|
|
206
208
|
Just remember to put all your colons, commas, and parentheses in the right places! 😅
|
207
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
|
+
|
208
216
|
### Trying Out Your Models
|
209
217
|
|
210
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.
|
@@ -236,7 +244,7 @@ Example for a Liquid layout:
|
|
236
244
|
or an ERB layout:
|
237
245
|
|
238
246
|
```erb
|
239
|
-
<% if site.
|
247
|
+
<% if site.config.prismic_preview_token %>
|
240
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%">
|
241
249
|
PREVIEW
|
242
250
|
</p>
|
data/bridgetown-prismic.gemspec
CHANGED
@@ -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"
|
@@ -10,11 +10,22 @@ 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
|
17
22
|
end
|
23
|
+
|
24
|
+
Bridgetown::Model::Base.descendants.each do |klass|
|
25
|
+
next unless klass.respond_to?(:prismic_custom_type)
|
26
|
+
|
27
|
+
Bridgetown::Resource.register_extension klass
|
28
|
+
end
|
18
29
|
end
|
19
30
|
|
20
31
|
def query_prismic(custom_type, options = {})
|
@@ -28,7 +28,6 @@ module BridgetownPrismic
|
|
28
28
|
raise "Could not find a specialized model class for ID `#{id}'"
|
29
29
|
end
|
30
30
|
|
31
|
-
Bridgetown::Resource.register_extension klass unless klass.extensions_have_been_registered
|
32
31
|
@data = klass.prismic_data(self, @prismic_document)
|
33
32
|
@data[:_id_] = id
|
34
33
|
@data[:_origin_] = self
|
data/lib/bridgetown-prismic.rb
CHANGED
@@ -14,10 +14,6 @@ require_relative "bridgetown-prismic/origin"
|
|
14
14
|
require_relative "bridgetown/utils/prismic_data"
|
15
15
|
|
16
16
|
Bridgetown::Model::Base.class_eval do # rubocop:disable Metrics/BlockLength
|
17
|
-
class << self
|
18
|
-
attr_accessor :extensions_have_been_registered
|
19
|
-
end
|
20
|
-
|
21
17
|
def self.import_prismic_document(doc) = new(BridgetownPrismic::Origin.import_document(doc))
|
22
18
|
|
23
19
|
def self.with_links = Bridgetown::Current.site.config.prismic_link_resolver
|
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.2.
|
4
|
+
version: 0.2.3
|
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-04-20 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
|
@@ -141,7 +147,7 @@ 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
153
|
summary: A Prismic CMS integration plugin for Bridgetown
|