Skip to content

Commit

Permalink
Use image field as fallback for teaser and preview (#34)
Browse files Browse the repository at this point in the history
* Use image field as fallback for teaser and preview

* Add fallback for the two types of indexes, new and old

* Update README

Co-authored-by: Victor Fernandez de Alba <sneridagh@gmail.com>
  • Loading branch information
ericof and sneridagh committed Nov 4, 2021
1 parent 9fc3711 commit b1e7849
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Feature

- Use image field as fallback for teaser and preview @ericof

### Bugfix

- Play well with the new blocks defaults @sneridagh
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ any registered block types are allowed.

## Teaser block

For convenience, this package includes a "teaser" block that allows you to pull content from a source content object and brings in to a block (title, description, preview_image fields).
For convenience, this package includes a "teaser" block that allows you to pull content from a source content object and brings in to a block (`title`, `head_line`, `description`, and `preview_image` fields). It tries to get these fields from the original source content first, and allows you to override them afterwards.

You'll find the `preview_image` field in `kitconcept.volto` add-on, or use your own definition of it in your Volto integration package.
You'll find the `preview_image` field in `plone.volto` (and previous to that, in `kitconcept.volto`) add-on. If no `preview_image` field is present in the source content, it will fallback to the `image` (eg. `Lead image` behavior), if any. If no image fields are present, it won't show any image unless you override it (using the local `preview_image` field) in the block's config.

It includes a configuration option `imageScale` (see above example) that allows you to use an specific scale for the `preview_image`.

Expand Down
2 changes: 1 addition & 1 deletion src/components/Teaser/DefaultBody.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const TeaserDefaultTemplate = (props) => {
href={href['@id']}
target={data.openLinkInNewTab ? '_blank' : null}
>
{(href.hasPreviewImage || image) && (
{(href.hasPreviewImage || href.image_field || image) && (
<div className="grid-image-wrapper">
<img
src={flattenToAppURL(getTeaserImageURL(href, image))}
Expand Down
1 change: 1 addition & 0 deletions src/components/Teaser/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const TeaserSchema = (props) => {
'head_title',
'Description',
'hasPreviewImage',
'image_field',
],
allowExternals: true,
},
Expand Down
4 changes: 3 additions & 1 deletion src/components/Teaser/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export function getTeaserImageURL(href, image) {
return image['@id'];
}
} else {
return `${href['@id']}/@@images/preview_image/${imageScale}`;
return `${href['@id']}/@@images/${
href.image_field || 'preview_image'
}/${imageScale}`;
}
}

0 comments on commit b1e7849

Please sign in to comment.