fix(mdx): handle double curly braces serialization in MDX payload attributes
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 7s
Build & Deploy / 🧪 QA (push) Successful in 48s
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
Build & Deploy / 🏗️ Build (push) Has been cancelled
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 7s
Build & Deploy / 🧪 QA (push) Successful in 48s
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
Build & Deploy / 🏗️ Build (push) Has been cancelled
This commit is contained in:
@@ -40,9 +40,19 @@ function HeroSection(props: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function Block(props: any) {
|
async function Block(props: any) {
|
||||||
const { type, data, children } = props;
|
const { type, children } = props;
|
||||||
|
let { data } = props;
|
||||||
const locale = await getLocale();
|
const locale = await getLocale();
|
||||||
|
|
||||||
|
// If data was passed as a JSON string (via our lib/blog.ts fix), parse it back
|
||||||
|
if (typeof data === 'string') {
|
||||||
|
try {
|
||||||
|
data = JSON.parse(data);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to parse MDX block data:', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Normalize type (Payload sometimes uses blockType in data)
|
// Normalize type (Payload sometimes uses blockType in data)
|
||||||
const blockType = type || data?.blockType;
|
const blockType = type || data?.blockType;
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,13 @@ export async function getPostBySlug(slug: string, locale: string): Promise<PostD
|
|||||||
const fileContent = await fs.readFile(filePath, 'utf-8');
|
const fileContent = await fs.readFile(filePath, 'utf-8');
|
||||||
const { data, content } = matter(fileContent);
|
const { data, content } = matter(fileContent);
|
||||||
|
|
||||||
let parsedContent = content;
|
// Fix MDX data props dropped by next-mdx-remote
|
||||||
|
// Payload serializes as data={{"items":...}} which Acorn treats as a Block statement.
|
||||||
|
const fixedContent = content.replace(/data=\{\{([\s\S]*?)\}\}/g, (match, p1) => {
|
||||||
|
return 'data="{' + p1.replace(/"/g, '"') + '}"';
|
||||||
|
});
|
||||||
|
|
||||||
|
let parsedContent = fixedContent;
|
||||||
try {
|
try {
|
||||||
if (content.trim().startsWith('{')) {
|
if (content.trim().startsWith('{')) {
|
||||||
parsedContent = JSON.parse(content);
|
parsedContent = JSON.parse(content);
|
||||||
|
|||||||
@@ -113,7 +113,7 @@
|
|||||||
"prepare": "husky",
|
"prepare": "husky",
|
||||||
"preinstall": "npx only-allow pnpm"
|
"preinstall": "npx only-allow pnpm"
|
||||||
},
|
},
|
||||||
"version": "2.3.22-rc.21",
|
"version": "2.3.22-rc.22",
|
||||||
"pnpm": {
|
"pnpm": {
|
||||||
"onlyBuiltDependencies": [
|
"onlyBuiltDependencies": [
|
||||||
"@parcel/watcher",
|
"@parcel/watcher",
|
||||||
|
|||||||
Reference in New Issue
Block a user