-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Responsive media component #45
base: main
Are you sure you want to change the base?
Changes from 12 commits
acc7d84
1a09d50
aea566d
5e0244a
44921f7
faa5607
9aea425
55081a1
d7f8994
7cd4aae
7c45fc6
eb006eb
5d584ce
d9de07a
4a33f22
95c725c
9eedefb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,12 @@ | |
Render Contentful asset (video/...). Uses data from cssg-plugin-assets if available. | ||
|
||
@example - Go Template | ||
{{- partial "utils/asset/svg" (dict | ||
{{- partial "utils/asset/video" (dict | ||
"context" $video | ||
"options" (dict | ||
"loop" "false" | ||
"muted" "false" | ||
"autoplay" "false" | ||
"loop" false | ||
"muted" false | ||
"autoplay" false | ||
"class_name" "c-video" | ||
) | ||
) -}} | ||
|
@@ -26,9 +26,10 @@ | |
{{- $autoplay := $params.autoplay | default true -}} | ||
{{- $playsinline := $params.playsinline | default true -}} | ||
{{- $controls := $params.controls | default false -}} | ||
{{- $poster := $params.poster | default false -}} | ||
{{/* Use transparent base64, the real poster should be loaded as <picture> element */}} | ||
{{- $poster := "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" -}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not skip the poster attribute completely? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question. I asked myself the same question (see TBD). The poster is not a mandatory attribute, but there was some reason... maybe the background is black when the video is not yet loaded? I don't know. I will try to find out and take it out for now. |
||
{{- $muted := (or $autoplay $params.muted) -}} | ||
{{- $loading := cond (eq $params.lazy true) "lazy" ($params.loading | default false) -}} | ||
{{- $loading := cond (eq ($params.lazy | default true) true) "lazy" ($params.loading | default false) -}} | ||
{{- $preload := $params.preload | default false -}} | ||
{{- $media := $params.media -}} | ||
|
||
|
@@ -39,18 +40,11 @@ | |
"controls" $controls | ||
"class" $class_name | ||
"poster" $poster | ||
"loading" $loading | ||
) $params -}} | ||
|
||
{{- if in $mime_type "video" -}} | ||
{{- $preload_attr := (dict | ||
"as" "image" | ||
"href" $poster | ||
"media" $media | ||
) -}} | ||
{{- if and $preload $poster (not (in ($globals.Scratch.Get "preload") $preload)) -}} | ||
{{- $globals.Scratch.Add "preload" (slice $preload) -}} | ||
{{- end -}} | ||
<video {{$attributes}}> | ||
<video {{$attributes}}{{- if eq $loading "lazy" -}} data-video{{- end -}}> | ||
{{- if eq $loading "lazy" -}} | ||
<source data-src="{{- $url -}}" type="{{- $mime_type -}}" /> | ||
{{- else -}} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,9 @@ module.exports = withHelpers(async (migration, _context, helpers) => { | |
const defaultLocale = await helpers.locale.getDefaultLocale(); | ||
|
||
const cMedia = migration | ||
.createContentType('c-media') | ||
.name('Component: Media') | ||
.description('Images / loop videos with predefined ratios') | ||
.createContentType('c-responsive-media') | ||
.name('Component: Responsive media') | ||
.description('Image or short loop video for different screen sizes') | ||
.displayField('internal_name'); | ||
|
||
cMedia | ||
|
@@ -23,25 +23,15 @@ module.exports = withHelpers(async (migration, _context, helpers) => { | |
.createField('alt') | ||
.name('Alt text') | ||
.type('Symbol') | ||
.localized(false) | ||
.required(false) | ||
.validations([]) | ||
.disabled(false) | ||
.omitted(false); | ||
|
||
cMedia | ||
.createField('caption') | ||
.name('Caption') | ||
.type('Text') | ||
.localized(false) | ||
.required(false) | ||
.localized(true) | ||
.required(true) | ||
.validations([]) | ||
.disabled(false) | ||
.omitted(false); | ||
|
||
cMedia | ||
.createField('media') | ||
.name('Media') | ||
.createField('mobile_media') | ||
.name('Mobile > Media') | ||
.type('Link') | ||
.localized(true) | ||
.required(true) | ||
|
@@ -56,35 +46,21 @@ module.exports = withHelpers(async (migration, _context, helpers) => { | |
|
||
cMedia | ||
.createField('mobile_ratio') | ||
.name('Mobile ratio') | ||
.name('Mobile > Ratio') | ||
.type('Symbol') | ||
.localized(false) | ||
.required(false) | ||
.validations([ | ||
{ | ||
in: ['hd', 'rectangle', 'square', 'portrait'], | ||
in: ['1x1', '16x9', '9x16', '4x3', '3x4'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely the better naming and more obviously 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think so too. 👍 Unfortunately, there is still a bug in Sonar that I don't exactly understand yet. I'll have a look. https://sonarcloud.io/project/issues?resolved=false&types=BUG&pullRequest=45&id=jungvonmatt_create-contentful-hugo-app&open=AYNg2o7ptY5uRUoaXYTE There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds like sonar thinks that this is a mathematical expression and you just could write 1, I guess.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @dlemm, that solved it. |
||
}, | ||
]) | ||
.disabled(false) | ||
.omitted(false); | ||
|
||
cMedia | ||
.createField('desktop_ratio') | ||
.name('Desktop ratio') | ||
.type('Symbol') | ||
.localized(false) | ||
.required(false) | ||
.validations([ | ||
{ | ||
in: ['hd', 'rectangle', 'square', 'portrait'], | ||
}, | ||
]) | ||
.disabled(false) | ||
.omitted(false); | ||
|
||
cMedia | ||
.createField('focus_area') | ||
.name('Focus area') | ||
.createField('mobile_focus_area') | ||
.name('Mobile > Focus area') | ||
.type('Symbol') | ||
.localized(false) | ||
.required(false) | ||
|
@@ -112,8 +88,8 @@ module.exports = withHelpers(async (migration, _context, helpers) => { | |
.omitted(false); | ||
|
||
cMedia | ||
.createField('media_hd') | ||
.name('Media hd') | ||
.createField('desktop_media') | ||
.name('Desktop > Media') | ||
.type('Link') | ||
.localized(true) | ||
.required(false) | ||
|
@@ -127,49 +103,47 @@ module.exports = withHelpers(async (migration, _context, helpers) => { | |
.linkType('Asset'); | ||
|
||
cMedia | ||
.createField('media_rectangle') | ||
.name('Media rectangle') | ||
.type('Link') | ||
.localized(true) | ||
.required(false) | ||
.validations([ | ||
{ | ||
linkMimetypeGroup: ['image', 'video'], | ||
}, | ||
]) | ||
.disabled(false) | ||
.omitted(false) | ||
.linkType('Asset'); | ||
|
||
cMedia | ||
.createField('media_square') | ||
.name('Media square') | ||
.type('Link') | ||
.localized(true) | ||
.createField('desktop_ratio') | ||
.name('Desktop > Ratio') | ||
.type('Symbol') | ||
.localized(false) | ||
.required(false) | ||
.validations([ | ||
{ | ||
linkMimetypeGroup: ['image', 'video'], | ||
in: ['1x1', '16x9', '9x16', '4x3', '3x4'], | ||
}, | ||
]) | ||
.disabled(false) | ||
.omitted(false) | ||
.linkType('Asset'); | ||
.omitted(false); | ||
|
||
cMedia | ||
.createField('media_portrait') | ||
.name('Media portrait') | ||
.type('Link') | ||
.localized(true) | ||
.createField('desktop_focus_area') | ||
.name('Desktop > Focus area') | ||
.type('Symbol') | ||
.localized(false) | ||
.required(false) | ||
.validations([ | ||
{ | ||
linkMimetypeGroup: ['image', 'video'], | ||
in: [ | ||
'center', | ||
'top', | ||
'bottom', | ||
'right', | ||
'left', | ||
'top_right', | ||
'top_left', | ||
'bottom_right', | ||
'bottom_left', | ||
'face', | ||
'faces', | ||
], | ||
}, | ||
]) | ||
.defaultValue({ | ||
[defaultLocale.code]: 'center', | ||
}) | ||
.disabled(false) | ||
.omitted(false) | ||
.linkType('Asset'); | ||
.omitted(false); | ||
|
||
cMedia | ||
.createField('lazy') | ||
|
@@ -185,49 +159,32 @@ module.exports = withHelpers(async (migration, _context, helpers) => { | |
.omitted(true); | ||
|
||
cMedia.changeFieldControl('internal_name', 'builtin', 'singleLine', { | ||
helpText: 'e.g. "Home page > Stage > Media"', | ||
helpText: 'e.g. "Home page > Media > Responsive media"', | ||
}); | ||
|
||
cMedia.changeFieldControl('alt', 'builtin', 'singleLine', {}); | ||
|
||
cMedia.changeFieldControl('caption', 'builtin', 'multipleLine', {}); | ||
cMedia.changeFieldControl('mobile_media', 'builtin', 'assetLinkEditor', {}); | ||
|
||
cMedia.changeFieldControl('media', 'builtin', 'assetLinkEditor', {}); | ||
|
||
cMedia.changeFieldControl('mobile_ratio', 'builtin', 'dropdown', { | ||
helpText: 'Select the ratio for mobile. Leave empty to use original image dimensions', | ||
}); | ||
|
||
cMedia.changeFieldControl('desktop_ratio', 'builtin', 'dropdown', { | ||
helpText: 'Select the ratio for desktop. Leave empty to use original image dimensions', | ||
cMedia.changeFieldControl('mobile_focus_area', 'builtin', 'dropdown', { | ||
helpText: 'Choose a focus area that will be used for resizing. Default is "center".', | ||
}); | ||
|
||
cMedia.changeFieldControl('focus_area', 'builtin', 'dropdown', { | ||
helpText: 'You can choose the focus area for resizing. The default is center', | ||
}); | ||
|
||
cMedia.changeFieldControl('media_hd', 'builtin', 'assetLinkEditor', { | ||
helpText: 'Ratio: 16:9', | ||
showLinkEntityAction: true, | ||
showCreateEntityAction: true, | ||
cMedia.changeFieldControl('mobile_ratio', 'builtin', 'dropdown', { | ||
helpText: 'Select a ratio for mobile or leave empty to use original image dimensions.', | ||
}); | ||
|
||
cMedia.changeFieldControl('media_rectangle', 'builtin', 'assetLinkEditor', { | ||
helpText: 'Ratio: 4:3', | ||
showLinkEntityAction: true, | ||
showCreateEntityAction: true, | ||
cMedia.changeFieldControl('desktop_media', 'builtin', 'assetLinkEditor', { | ||
helpText: | ||
'Can be used to use different ratios on mobile and desktop. If empty, the mobile media will be used for both.', | ||
}); | ||
|
||
cMedia.changeFieldControl('media_square', 'builtin', 'assetLinkEditor', { | ||
helpText: 'Ratio: 1:1', | ||
showLinkEntityAction: true, | ||
showCreateEntityAction: true, | ||
cMedia.changeFieldControl('desktop_ratio', 'builtin', 'dropdown', { | ||
helpText: 'Select a ratio for desktop. Leave empty to use original media dimensions.', | ||
}); | ||
|
||
cMedia.changeFieldControl('media_portrait', 'builtin', 'assetLinkEditor', { | ||
helpText: 'Ratio: 2:3', | ||
showLinkEntityAction: true, | ||
showCreateEntityAction: true, | ||
cMedia.changeFieldControl('desktop_focus_area', 'builtin', 'dropdown', { | ||
helpText: 'Choose a focus area that will be used for resizing. Default is "center".', | ||
}); | ||
|
||
cMedia.changeFieldControl('lazy', 'builtin', 'boolean', {}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we needed it because with different ratios the sizes come from the
<source>
elements. Maybe it is enough there. But I just noticed another problem, there is a layout shift when the sources have a media attribute. I am looking for a solution.