The source code for this blog is available on GitHub.
Note
Top

The Component We Crafted

Cover Image for The Component We Crafted
Han Chen
Han Chen

The Component We Crafted

The following is all the path under HYTE

/403.tsx
/404.tsx
/500.jsx
/_app.tsx
/_document.tsx
/about-us.jsx
/accessibility-policy.jsx
/account/index.jsx
/auth/login.jsx
/auth/sign-up.jsx
/blog/[post].tsx
/blog/index.tsx
/carousel-ex.jsx
/carousel.jsx
/cart.tsx
/ces-layout.jsx
/checkout.tsx
/cnvs.jsx
/community/custom-builds.jsx
/computex-mobile.jsx
/contact.jsx
/cookie-policy.jsx
/countdown.jsx
/deals/black-friday.jsx
/deals/cyber-monday.jsx
/deals/year-end.jsx
/events/ces.jsx
/events/computex.jsx
/events/tutorial-desktop.jsx
/events/tutorial.jsx
/forgot-password.tsx
/hyte-x-series/[series].jsx
/hyte-x-series/index.jsx
/index.tsx
/landing-pages-xml-builder.jsx
/landing-pages.xml.tsx
/nexus/download.jsx
/nexus/how-to.jsx
/nexus/index.jsx
/pc-accessories/[accessories].jsx
/pc-accessories/index.jsx
/pc-cases/[case].jsx
/pc-cases/index.jsx
/pc-hardware/[hardware].jsx
/pc-hardware/index.jsx
/posts.xml.jsx
/press/[post].tsx
/press/index.tsx
/press/press-kit.jsx
/privacy-policy.jsx
/reset-password.jsx
/revolt3.jsx
/sales-inquiry.jsx
/shipping-and-returns.jsx
/sitemap.jsx
/sitemapindex.xml.jsx
/store/[product].jsx
/store/index.jsx
/store.xml.jsx
/terms-and-conditions.jsx
/verify.jsx
/warranty-service.jsx
/where-to-buy.jsx
/y40.jsx
/y60.jsx

We can check our main sitepage in sitemap

Our landing page is (We can view all the landing page here)

/y40.jsx
/y60.jsx
/revolt3.jsx

https://staging.hyte.com/events/computex

YouTube with image overlay in next js

You can directly overwrite the custom css on top of the existing YouTube style to make an image overlay

import LiteYouTubeEmbed from "react-lite-youtube-embed";
import "react-lite-youtube-embed/dist/LiteYouTubeEmbed.css";
import useHost from "@/hooks/use-host.hook";

const router = useRouter();
const host = useHost();
const isLive = host === "hyte.com";

<style jsx global>{`
  ${!isLive &&
  `.yt-lite:before {
      background-image: url("https://upload.wikimedia.org/wikipedia/commons/thumb/2/24/Blackpink_PUBG_210321.jpg/2560px-Blackpink_PUBG_210321.jpg");
      height: 100%;
      background-size: cover; /* Or use 'contain' if you want to see the entire image */
      background-position: center; /* Adjust as needed */
      background-repeat: no-repeat;
  }
  `}
`}</style>

<LiteYouTubeEmbed
    id={videoId}
    src="https://youtu.be/tV5PHCrZXOw?t=1"
    adNetwork={false}
    playlist={false}
    title="GREAT"
    noCookie={true}
  />
</div>

YouTube with image overlay in next js on Product page

  • If the ID is something like 5qwer, it's not legitimate since numbers and capital letters are not allowed in IDs. I added this instead 👉 video-${videoId}
import LiteYouTubeEmbed from "react-lite-youtube-embed";
import "react-lite-youtube-embed/dist/LiteYouTubeEmbed.css";
import useHost from "@/hooks/use-host.hook";
import { useNextSanityImage } from "next-sanity-image";
import { useContext } from "react";
import PRODUCT_STATE from "@/util/react-context/product-state";
import classname from "classnames";
export default function YoutubeContent({ data }) {
  const { header, url } = data;
  const regex =
    /(https?:\/\/)?(((m|www)\.)?(youtube(-nocookie)?|youtube.googleapis)\.com.*(v\/|v=|vi=|vi\/|e\/|embed\/|user\/.*\/u\/\d+\/)|youtu\.be\/)([_0-9a-z-]+)/i;

  const videoId = url.match(regex)[8];

  const [, isLive] = useHost();
  const sanityAsset = data?.overlayImage?.asset

  const {
    sanityEnv: { projectId, dataset },
  } = useContext(PRODUCT_STATE);
  const sanityImage = sanityAsset && useNextSanityImage(
    { projectId, dataset },
    data.overlayImage.asset
  );

  return (
    // Specific formula to keep Youtube embed responsive
    // See https://css-tricks.com/fluid-width-video/
    <section className="my-xxxl youtube-section max-md" key={data._key}>
      <style jsx global>{`
        ${sanityImage &&
        `.video-${videoId}:before {
                background-image: url("${sanityImage.src}");
                height: 100%;
                background-size: cover; /* Or use 'contain' if you want to see the entire image */
                background-position: center; /* Adjust as needed */
                background-repeat: no-repeat;
            }
        `}
      `}</style>

      <h2>{header}</h2>
      {/* https://github.com/ibrahimcesar/react-lite-youtube-embed */}
      <LiteYouTubeEmbed
        id={videoId}
        wrapperClass={classname("yt-lite", `video-${videoId}`)}
        adNetwork={false}
        playlist={false}
        title={header}
        noCookie={true}
      />
    </section>
  );
}

© 2024 WOOTHINK. All Rights Reserved.
Site MapTerms and ConditionsPrivacy PolicyCookie Policy