import Head from "next/head"; import ReactPlayer from "react-player/lazy"; import { Paragraph } from "./Link"; import { NextSeo } from "next-seo"; import siteConfig from "../config/siteConfig"; import { YOUTUBE_REGEX } from "../lib/constants"; const components = { Head, p: Paragraph, }; export default function MdxPage({ children, editUrl }) { const { Component, frontmatter: { title, description, date, authors, youtube, podcast, image, _raw, }, } = children; let youtubeThumnbnail; let podcastEmbed; if (youtube && YOUTUBE_REGEX.test(youtube) && !image) { // get the youtube thumbnail image from https://img.youtube.com/vi//maxresdefault.jpg const youtubeId = youtube.split(/^|=|\//).pop(); youtubeThumnbnail = youtube.replace( YOUTUBE_REGEX, `https://img.youtube.com/vi/${youtubeId}/maxresdefault.jpg` ); } if (podcast && podcast.includes("life-itself")) { const podcastUrl = podcast; podcastEmbed = [ podcastUrl.slice(0, "https://anchor.fm/life-itself".length), "/embed", podcastUrl.slice("https://anchor.fm/life-itself".length), ].join(""); } const titleFromUrl = _raw.flattenedPath .split("/") .pop() .replace(/-/g, " ") // capitalize first char of each word .replace(/(^\w{1})|(\s{1}\w{1})/g, (str) => str.toUpperCase()); const SeoTitle = title ?? titleFromUrl; const imageUrl = image ? siteConfig.url + image : youtubeThumnbnail ? youtubeThumnbnail : null; return ( <>
{title &&

{title}

} {authors && (

{authors}

)} {date && (

on {date}

)} {description &&

{description}

} {youtube && YOUTUBE_REGEX.test(youtube) && (
)} {podcast && (
{podcastEmbed && (