bridgetown-prismic 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +3 -3
- data/lib/bridgetown-prismic/api.rb +6 -1
- data/lib/bridgetown-prismic/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: edc984dde8e51c56c4b6da117b7f0a16f5fb81ec966ff28b9424bde9c2bc7858
|
4
|
+
data.tar.gz: 3e553d7e6af94da3cf2590fe4b2301c1e368c7dfc95408898a41e0aa28438925
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec881170fdaff8ef22f840cffd403b1dd4bcfa427bb858db4487e75a47c7b59ceb4e5a8b1135e850378f2c400761ceb81fb01893d5c6ba15c31cc26fb333d6c1
|
7
|
+
data.tar.gz: 124c223cdfc6ff567acd33c67e0986ac4d4a88ca05e881e7f0be160709393f5f085c7d108cb8d1f3014dd55d87862e716894fd13319d703e5590397c2bbfd60e
|
data/CHANGELOG.md
CHANGED
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
|
|
@@ -141,7 +141,7 @@ end
|
|
141
141
|
|
142
142
|
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
143
|
|
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 (
|
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, 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
145
|
|
146
146
|
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
147
|
|
@@ -185,7 +185,7 @@ The Ruby DSL is pretty nifty, but you may occasionally run into a conflict betwe
|
|
185
185
|
set :method, doc["page.method"].as_text
|
186
186
|
```
|
187
187
|
|
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!
|
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! 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
189
|
|
190
190
|
```ruby
|
191
191
|
def self.process_prismic_document(doc)
|
@@ -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
|