import { NextSeo } from "next-seo"; import LiteYouTubeEmbed from "react-lite-youtube-embed"; import { useState, useEffect } from "react"; import { YOUTUBE_REGEX } from "../lib/constants"; import siteConfig from "../config/siteConfig"; import getMDXComponents from "./_getMDXComponents"; import getObserver from "./_getIntersectionObserver" import { Paragraph } from "./Paragraph"; import { Anchor } from "./Anchor"; // const Anchor = dynamic(() => import('./Anchor').then(module => module.Anchor), { // ssr: false // }) // const Paragraph = dynamic(() => import("./Paragraph").then(mod => mod.Paragraph)) export default function MdxPage({ children }) { const [activeHeading, setActiveHeading] = useState(""); const observer = getObserver((entry) => { if (entry.isIntersecting) { setActiveHeading(entry.target.id); } }) const components = getMDXComponents({ h: { observer } }) useEffect(() => { if (activeHeading) { const tocLink = document.querySelector(`.toc-link[href="#${activeHeading}"]`) tocLink.classList.add("active"); return () => { tocLink.classList.remove("active") } }; }, [activeHeading]); const { Component, frontmatter: { title, description, date, keywords, youtube, podcast, image, _raw, }, } = children; let youtubeThumnbnail; const youtubeId = youtube && YOUTUBE_REGEX.test(youtube) && youtube.split(/^|=|\//).pop(); if (youtubeId && !image) { // get the youtube thumbnail image from https://img.youtube.com/vi//maxresdefault.jpg youtubeThumnbnail = youtube.replace( YOUTUBE_REGEX, `https://img.youtube.com/vi/${youtubeId}/maxresdefault.jpg` ); } const PodcastIcon = siteConfig.social.find((s) => s.name === "Podcast").icon; 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; // enable editing content only for claims, concepts, and guide for now const editUrl = ["claims", "concepts", "guide"].includes(_raw.sourceFileDir) ? siteConfig.repoRoot + siteConfig.repoEditPath + _raw.sourceFilePath : null; return ( <> ); }