import { useState, useEffect } from "react" import { Helmet } from "react-helmet-async" import { useLocation } from "react-router-dom" import styled from "styled-components" import MainContent from "../../components/MainContent" import PostCard from "../../components/PostCard" import Loading from "../../components/Loading" import TagList from "../../components/TagList" import Tag from "../../components/Tag" import NotFound from "../NotFound" import SeriesControlButtons from "./SeriesControlButtons" import { categorizePageType, fetchContent, PageType, parsePageData, } from "./helper" import Meta from "./Meta" import Toc from "./Toc" import type { PageData } from "@developomp-site/blog-content/src/types/types" import contentMap from "../../contentMap" const StyledTitle = styled.h1` margin-bottom: 1rem; word-wrap: break-word; ` const ProjectImage = styled.img` max-width: 100%; ` export default function Page() { const { pathname } = useLocation() const [pageData, setPageData] = useState(undefined) const [pageType, setPageType] = useState(PageType.POST) const [isLoading, setIsLoading] = useState(true) // this code runs if either the url or the locale changes useEffect(() => { const content_id = pathname.replace(/\/$/, "") // remove trailing slash const pageType = categorizePageType(content_id) fetchContent(pageType, content_id).then((fetched_content) => { if (!fetched_content) { // stop loading without fetching pageData so 404 page will display setIsLoading(false) return } setPageData(parsePageData(fetched_content, pageType, content_id)) setPageType(pageType) setIsLoading(false) }) }, [pathname]) if (isLoading) return if (!pageData) return return ( <> pomp | {pageData.title} {/* next/previous series post buttons */} {pageType == PageType.SERIES && ( )} {pageData.title} {/* Post tags */} {pageData.tags.length > 0 && ( {pageData.tags.map((tag) => { return (
) })}
)}
{/* Post metadata */} {[PageType.POST, PageType.SERIES, PageType.SERIES_HOME].includes( pageType ) && }

{/* add table of contents if it exists */} {/* page content */}
{/* series post list */} {pageType == PageType.SERIES_HOME && pageData.order.map((post) => { return ( ) })} ) }