Skip to content

Commit 2b6d1e0

Browse files
committed
Make video responsive
1 parent ffc3d51 commit 2b6d1e0

File tree

4 files changed

+46
-10
lines changed

4 files changed

+46
-10
lines changed

components/Main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Component } from "react"
33
export default class Main extends Component<{className?: string, homePage?: true}> {
44
render() {
55
const classes =
6-
(!this.props.homePage ? "max-w-4xl w-full" : "") +
6+
(!this.props.homePage ? "max-w-4xl w-full px-1" : "") +
77
(this.props.className ?? "")
88

99
return (

pages/guides/[category].tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { GetStaticPathsResult, GetStaticPropsContext, GetStaticPropsResult } from "next"
22
import Head from "next/head"
3-
import ReactMarkdown from "react-markdown"
43
import FormattedLink from "../../components/FormattedLink"
54
import Main from "../../components/Main"
65
import { getGuides, urlify } from "../../utils/data-cache"
@@ -55,7 +54,7 @@ export async function getStaticProps(context: GetStaticPropsContext): Promise<Ge
5554

5655
return {
5756
props: {
58-
guide: category
57+
guide: category // TODO optimize
5958
},
6059
revalidate: 60 * 60
6160
}

pages/guides/[category]/[guide].tsx

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import ReactMarkdown from "react-markdown"
44
import FormattedLink from "../../../components/FormattedLink"
55
import Main from "../../../components/Main"
66
import { getGuides, urlify, yeetBrackets } from "../../../utils/data-cache"
7-
import { Guide, GuidePage } from "../../../utils/types"
7+
import { Guide } from "../../../utils/types"
88
import YouTube from "react-youtube"
9+
import styles from "../../style.module.css"
910

1011
interface Props {
1112
guide: Guide
@@ -50,21 +51,38 @@ export default function GuideWebpage({ guide, pageNumber, location }: Props & {
5051
</div>
5152
</div>
5253

53-
<ul>
54+
<div>
5455
<ReactMarkdown>{(page.desc?.replace(/ ?\$\{.*?\}/g, "") ?? "")}</ReactMarkdown>
5556
{page.img && <ExternalImg src={page.img} />}
5657
{page.url && page.url.startsWith("https://youtu.be/") && <div>
57-
<h2 className="text-xl font-semibold pt-1">Video:</h2>
58-
<YouTube videoId={page.url.replace("https://youtu.be/", "")} containerClassName="w-xl" className="w-xl" />
58+
<h2 className="text-xl font-semibold py-1">Video:</h2>
59+
<div style={{
60+
position: "relative",
61+
paddingBottom: "56.25%" /* 16:9 */,
62+
paddingTop: 25,
63+
height: 0
64+
}}>
65+
<iframe
66+
style={{
67+
position: "absolute",
68+
top: 0,
69+
left: 0,
70+
width: "100%",
71+
height: "100%"
72+
}}
73+
src={`https://www.youtube.com/embed/${page.url.replace("https://youtu.be/", "")}`}
74+
frameBorder="0"
75+
/>
76+
</div>
5977
</div>
6078
}
61-
</ul>
79+
</div>
6280
</Main>
6381
)
6482
}
6583
function ExternalImg({ src }: { src: string }) {
6684
// eslint-disable-next-line @next/next/no-img-element
67-
return <FormattedLink href={src} target="_blank"><img className="p-1 relative max-w-4xl" style={{ maxHeight: "56rem" }} decoding="async" alt="Guide Image" src={src} /></FormattedLink>
85+
return <FormattedLink href={src} target="_blank"><img className={`p-1 relative ${styles.autosize}`} decoding="async" alt="Guide Image" src={src} /></FormattedLink>
6886
// return <div className="p-1 relative max-w-2xl">
6987
// <Image alt="Guide Image" src={src} width={825} height={963}/>
7088
// </div>
@@ -87,7 +105,7 @@ export async function getStaticProps(context: GetStaticPropsContext): Promise<Ge
87105

88106
return {
89107
props: {
90-
guide,
108+
guide, // TODO optimize
91109
pageNumber
92110
},
93111
revalidate: 60 * 60

pages/style.module.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.autosize {
2+
max-height: "56rem";
3+
max-width: "min(100%, 56rem)";
4+
}
5+
6+
.fill {
7+
position: "absolute";
8+
top: 0;
9+
left: 0;
10+
width: "100%";
11+
height: "100%";
12+
}
13+
14+
.video {
15+
position: "relative";
16+
padding-bottom: "56.2;%";
17+
padding-top: 25;
18+
height: 0;
19+
}

0 commit comments

Comments
 (0)