From 8524db8ecf30e24589186afd71b7706e48154fed Mon Sep 17 00:00:00 2001 From: Aaron Yarborough <3855819+AaronJY@users.noreply.github.com> Date: Sat, 3 May 2025 16:14:07 +0100 Subject: [PATCH] fix: stop mdx ddossing me --- package.json | 2 +- src/lib/mdx-components.js | 16 ++++++++-------- src/pages/[[...path]].jsx | 21 --------------------- 3 files changed, 9 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 624668f..4d01bee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "www-aaronjy-me", - "version": "2.1.0", + "version": "2.1.1", "private": true, "type": "module", "scripts": { diff --git a/src/lib/mdx-components.js b/src/lib/mdx-components.js index 2f59a51..d4fd3cc 100644 --- a/src/lib/mdx-components.js +++ b/src/lib/mdx-components.js @@ -5,33 +5,33 @@ import { useEffect, useState, useTransition } from 'react' export const mdxComponents = { StaticContentList: ({ type, urlPrefix, max = 0 }) => { const [items, setItems] = useState([]) - const [isLoading, setLoading] = useState(true) + const [isLoading, setLoading] = useState(false) useEffect(function () { + if (!urlPrefix || max <= 0) + return; + switch (type) { case 'posts': (async function () { + setLoading(true) const res = await fetchPosts([]) const json = await res.json() setItems(json.data.sort((a, b) => a.datePublished < b.datePublished) ?? []) setLoading(false) })() - break + break; default: throw `Could not render StaticContentList: content type ${type} not supported.` } - }) + }, [type, urlPrefix, max]) return ( <> - {isLoading &&

Loading...

} - - - + {isLoading &&

Loading...

} {!isLoading && } - ) } } diff --git a/src/pages/[[...path]].jsx b/src/pages/[[...path]].jsx index 45df8d4..6f001ee 100644 --- a/src/pages/[[...path]].jsx +++ b/src/pages/[[...path]].jsx @@ -8,27 +8,6 @@ import { } from 'next-mdx-remote-client/serialize' import { NextSeo } from 'next-seo' -// export async function getStaticPaths () { -// const res = await fetchBasicPages(['path']) - -// if (!res.ok) { -// throw new FailedFetchBasicPagesError(await res.text()) -// } - -// const pages = (await res.json()).data - -// const paths = { -// paths: pages.map(page => ({ -// params: { -// path: page.path?.split('/') // about/page -> [about, page] -// .filter(p => !!p) ?? [] // deal with paths starting with '/' -// } -// })), -// fallback: true // false or "blocking" -// } - -// return paths -// } export async function getServerSideProps ({ params }) { const { path } = params console.log(params)