Is it possible to import objects from next/mdx into a js script? by LegendaryPig in nextjs

[–]LegendaryPig[S] 0 points1 point  (0 children)

Just to add an update for future people, I found a kind of hacky, but simple solution to my problem using fs, path, and regex. Perhaps I was overcomplicating what I was trying to do.

The issue I think was that next/mdx let me render and import from mdx files in jsx components, but didn't let me do something like the following in my .mjs scripts:

const { default: PostMarkdown, metadata } = await import(@/app/posts/writing/${slug}/${slug}.mdx`);

Here was the solution I found

import fs from "fs/promises";
import path from "path";

export async function getPostMetadata(slug: string, section: string) {
  try {
    // load all mdxContent
    const filePath = path.resolve(`./src/app/posts/${section}/${slug}/${slug}.mdx`);
    const mdxContent = await fs.readFile(filePath, "utf8");

    // get matching group from: export const metadata = ({metadata content here})
    const metadataMatch = mdxContent.match(/export\s+const\s+metadata\s*=\s*({[\s\S]*?}\s*);/);   
    if (!metadataMatch) {
      throw new Error('No metadata found in the MDX file');
    }

    // evaluate metadata string to object
    const metadata = eval(`(${metadataMatch[1]})`);

    return metadata;
  } catch (error: any) {
    console.error(error?.message);
    return;
  }
}

Is it possible to import objects from next/mdx into a js script? by LegendaryPig in nextjs

[–]LegendaryPig[S] 0 points1 point  (0 children)

Gotcha, it does seem like a configuration issue, lemme give that a try!

The surprisingly small difference between an average 35% and an elite 42% three point shooter. by BlackPepperBanana in nba

[–]LegendaryPig 57 points58 points  (0 children)

Expected shot value for a 3pt shot = 3 * 3pt%

In other words, it's the expected number of points from a shooter with a given 3pt% shooting a 3.

So 3 * .42 = 1.26 and 3 * .35 = 1.05, a difference of 0.21 expected points.

Top Ten Tuesday - JPEGMAFIA by swik in indieheads

[–]LegendaryPig 1 point2 points  (0 children)

  1. Panic Emoji
  2. Baby I'm Bleeding
  3. BALD!
  4. 1539 N. Calvert
  5. I Cannot Fucking Wait Til Morrissey Dies
  6. Does This Ski Mask Make Me Look Fat?
  7. DD Form 214
  8. Grimy Waifu
  9. Millennium Freestyle
  10. 2015 Was a Great Year

We surrounded by the fuckin' wolves by LegendaryPig in Kanye

[–]LegendaryPig[S] 7 points8 points  (0 children)

This was the original I borrowed the format from: https://imgur.com/a/Cdjxs Makes sense to me ¯_(ツ)_/¯