Skip to content

Commit e3920ba

Browse files
committed
updating homepage media
1 parent 12e9619 commit e3920ba

File tree

6 files changed

+110
-16
lines changed

6 files changed

+110
-16
lines changed

content/pages/home.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ blocks:
9898
TinaCMS
9999
link: 'https://app.tina.io/quickstart'
100100
mediaContent:
101-
- videoSrc: 'https://www.youtube.com/embed/sTVd8CYtXrA?si=0jMAjA_5ZTXJIuBC'
102-
thumbnail: /uploads/posts/learning-to-blog.png
101+
- videoSrc: 'https://www.youtube.com/embed/E0nehGoMwWM?si=eQc9_PDnArhWTkkE'
102+
thumbnail: /uploads/getting-started-with-npx.png
103103
alt: alt
104104
_template: youtubeVideo
105105
_template: MediaFeature
@@ -131,10 +131,10 @@ blocks:
131131
editorial workflow.
132132
link: 'https://tina.io/docs/tinacloud/editorial-workflow'
133133
mediaContent:
134-
- videoSrc: 'https://www.youtube.com/embed/sTVd8CYtXrA?si=0jMAjA_5ZTXJIuBC'
135-
thumbnail: /uploads/posts/learning-about-markdown.png
136-
alt: alt
137-
_template: youtubeVideo
134+
- video: /uploads/create-branch.webm
135+
altText: Editorial Workflow
136+
size: small
137+
_template: video
138138
- isMediaOnRight: false
139139
features:
140140
- title: API Reference

public/uploads/create-branch.webm

4.36 MB
Binary file not shown.
411 KB
Loading

src/components/blocks/MediaFeature/MediaFeature.template.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,44 @@ export const MediaFeatureBlockSchema: Template = {
7272
},
7373
],
7474
},
75+
{
76+
name: "video",
77+
label: "Video",
78+
fields: [
79+
{
80+
name: "video",
81+
label: "Video URL",
82+
type: "image",
83+
},
84+
{
85+
name: "altText",
86+
label: "Alt Text",
87+
type: "string",
88+
},
89+
{
90+
name: "size",
91+
label: "Size",
92+
options: [
93+
{ label: "Small", value: "small" },
94+
{ label: "Medium", value: "medium" },
95+
{ label: "Large", value: "large" },
96+
],
97+
type: "string",
98+
},
99+
{
100+
name: "width",
101+
label: "Width",
102+
type: "number",
103+
description: "Optional: Set a specific width for the video",
104+
},
105+
{
106+
name: "height",
107+
label: "Height",
108+
type: "number",
109+
description: "Optional: Set a specific height for the video",
110+
},
111+
],
112+
},
75113
{
76114
name: "youtubeVideo",
77115
label: "YouTube Video",

src/components/blocks/MediaFeature/MediaFeature.tsx

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ function YouTubeVideoPlayer({ mediaContent }: { mediaContent: any }) {
1111
const [showVideo, setShowVideo] = useState(false);
1212

1313
if (showVideo) {
14+
const autoplayUrl = `${mediaContent.videoSrc}&autoplay=1`;
15+
1416
return (
1517
<div className="relative w-full aspect-[16/9]">
1618
<iframe
17-
src={mediaContent.videoSrc}
19+
src={autoplayUrl}
1820
title={mediaContent.alt || "YouTube Video"}
1921
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
2022
allowFullScreen
@@ -54,22 +56,70 @@ function YouTubeVideoPlayer({ mediaContent }: { mediaContent: any }) {
5456
);
5557
}
5658

59+
function VideoPlayer({ mediaContent }: { mediaContent: any }) {
60+
const getSizeClasses = (size: string) => {
61+
switch (size) {
62+
case "small":
63+
return "max-w-md mx-auto";
64+
case "medium":
65+
return "max-w-2xl mx-auto";
66+
case "large":
67+
return "max-w-4xl mx-auto";
68+
default:
69+
return "max-w-2xl mx-auto";
70+
}
71+
};
72+
73+
const videoUrl =
74+
typeof mediaContent.video === "string"
75+
? mediaContent.video
76+
: mediaContent.video?.url || mediaContent.video;
77+
78+
if (!videoUrl) {
79+
return null;
80+
}
81+
82+
return (
83+
<div className={`w-full ${getSizeClasses(mediaContent.size || "medium")}`}>
84+
<video
85+
src={videoUrl}
86+
width={mediaContent.width || undefined}
87+
height={mediaContent.height || undefined}
88+
autoPlay
89+
loop
90+
muted
91+
playsInline
92+
className="w-full h-auto rounded-lg shadow-lg"
93+
>
94+
{mediaContent.altText && (
95+
<p>Your browser doesn't support HTML video. {mediaContent.altText}</p>
96+
)}
97+
</video>
98+
</div>
99+
);
100+
}
101+
57102
function renderMediaContent(mediaContent: any) {
58103
if (mediaContent.__typename.includes("YoutubeVideo")) {
59104
return <YouTubeVideoPlayer mediaContent={mediaContent} />;
60105
}
61106
if (mediaContent.__typename.includes("Image")) {
62107
return (
63108
<div>
64-
<Image
65-
src={mediaContent.image.url}
66-
alt={mediaContent.image.alt || "Untitled Image"}
67-
width={mediaContent.image.width}
68-
height={mediaContent.image.height}
69-
/>
109+
{mediaContent?.image?.url && (
110+
<Image
111+
src={mediaContent.image.url}
112+
alt={mediaContent?.image?.alt || "Untitled Image"}
113+
width={mediaContent?.image?.width || 500}
114+
height={mediaContent?.image?.height || 500}
115+
/>
116+
)}
70117
</div>
71118
);
72119
}
120+
if (mediaContent.__typename.includes("Video")) {
121+
return <VideoPlayer mediaContent={mediaContent} />;
122+
}
73123
return null;
74124
}
75125

@@ -86,7 +136,9 @@ function renderFeatures(features: any[]) {
86136
<div className="flex flex-col">
87137
{features.map((feature, index) => (
88138
<div
89-
key={`${feature.title || 'untitled'} - ${index}-${feature.description || ''}`}
139+
key={`${feature.title || "untitled"} - ${index}-${
140+
feature.description || ""
141+
}`}
90142
data-tina-field={tinaField(feature)}
91143
className={`p-8 ${
92144
features.length === 2 && index === 0
@@ -162,7 +214,11 @@ export default function MediaFeature({
162214
<div className="py-10">
163215
{data.MediaBlock &&
164216
data.MediaBlock.map((block: any, index: number) => (
165-
<div key={`media-block-${index}-${block.isMediaOnRight ? 'right' : 'left'}`}>
217+
<div
218+
key={`media-block-${index}-${
219+
block.isMediaOnRight ? "right" : "left"
220+
}`}
221+
>
166222
{mediaBlock(block)}
167223
</div>
168224
))}

tina/tina-lock.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)