npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mdx-to-json

v0.0.4

Published

turn mdx to json model

Downloads

5

Readme

MDX to json

这个包将你的 MDX 语法,编译成 JSON 数据格式,这能够带来这些好处:

  • 内容可以直接存储到数据库,并且无需eval即可渲染,契合所有 edge runtime
  • 数据量小,只保留了jsx所需的参数:
    • component (string)
    • props
    • children
  • JSON 对于框架没有要求,任何框架只要能够根据该数据结构渲染出内容,其就可以支持

Aata Structure

[
    {
        "relativePath": "path/to/your/mdx",
        "absoultePath": "/path/to/your/mdx",
        "slug": "relative/to/posts/dir",
        "data": {
            "frontmatter": { "a": "b" },
            "nodes": [
                {
                    "component": "A",
                    "props": { "name": "jokcy" },
                    "children": []
                }
            ]
        }
    }
]

Limitation

JSON 智能存储可序列化的数据格式,所以总体上相较于 MDX 直接编译成 JS,该库有一定的限制,主要集中于 esm 相关的功能:

  • import
  • export
  • declare function
  • declare variable (binary expression maybe supported in the future)
  • scope variable invocation

你可以在 props 或者 children 中使用一些表达式,比如:

  • {1+1}
  • {Data.now()}
  • {'a'.repeat(5)}

对于表达式,我们直接对其进行eval并且把返回的值写入 value,你需要考虑其在编译时的执行结果是否符合你的预期。

Usage

TODO

目前该包只导出了一个mdxToJson函数,具体如何监控本地目录,或者远端文件,则仍然在开发中。