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

@snappify/next-markdown

v1.8.1

Published

Static pages generated from markdown files for your Next.js website.

Downloads

7

Readme

Made for people

  • having a nextjs project
  • in ❤️ with markdown
  • who want to generate boring (but very necessary!) pages like /about, /terms, /blog, /docs or /whatever/other/route from markdown files with 0 effort

Used by

  • lembot.com - all pages except the home page are generated from markdown hosted in a separate public github repo.
  • snappify.io (blog, docs) - a powerful design tool to create and manage beautiful images of your code.
  • frouo.com - a dev blog
  • reach us on twitter @nextmarkdown to add your website here (or personal: @frouo)

Get Started ✨

In your nextjs project, run

npm install next-markdown

Add the following [...nextmd].jsx file in the pages/ folder

import NextMarkdown from "next-markdown";

const nextmd = NextMarkdown({ pathToContent: "./pages-markdown" });

export const getStaticPaths = nextmd.getStaticPaths;
export const getStaticProps = nextmd.getStaticProps;

export default function MarkdownPage({ frontMatter, html, subPaths }) {
  return <div dangerouslySetInnerHTML={{ __html: html }} /> 👈 design your own layout 🧑‍🎨
}

Usage 👋

At the root of your project create the folder pages-markdown/, add the following hello.md file

# Hello World

This is **awesome**

That's it. Open http://localhost:3000/hello page and see the magic.

Enjoy.

nextmd demo

Features 🚀

Dynamic Routes for Markdown Files

next-markdown generates routes based on the path of your markdown files.

Just like nextjs does with pages/.

For example, the following project structure will result into creating the following pages:

pages/
├ index.jsx    ......... ➡️ /
├ caveat.jsx   ......... ➡️ /caveat
├ [...nextmd].jsx

pages-markdown/
├ about.md     ......... ➡️ /about
├ caveat.md    ......... ➡️ ❌ because `pages/caveat.jsx` is already defined cf. https://nextjs.org/docs/routing/dynamic-routes#caveats
├ hello/
  ├ index.md   ......... ➡️ /hello
  ├ world.md   ......... ➡️ /hello/world
  ├ jurassic/
    ├ park.md  ......... ➡️ /hello/jurassic/park
├ blog/
  ├ index.md   ......... ➡️ /blog
  ├ hello.md   ......... ➡️ /blog/hello
  ├ world.md   ......... ➡️ /blog/world
├ docs/
  ├ index.md   ......... ➡️ /docs
  ├ get-started.md   ... ➡️ /docs/get-started
  ├ features.md   ...... ➡️ /docs/features
  ├ contribute.md   .... ➡️ /docs/contribute

See the example.

Blog Aware (example)

next-markdown is blog-aware:

  • list all the posts
  • write draft or unpublish a post by simply prefixing the file name with an underscore (eg. _hello.md will redirect to 404)
  • reading time
  • etc.

Documentation (example)

next-markdown lets you build a documentation:

  • sidebar
  • previous / next
  • organize your docs by folders
  • etc.

Table of Contents (example)

For each page you'll receive the Table of Contents based on headings in your markdown.

Personal Blog (example)

Use next-markdown to browse and parse your markdown files so you can build your personal blog in seconds.

MDX Support (example)

There is nothing to setup on your side, MDX support comes for free.

You can mix .md and .mdx files.

Configure custom remark and rehype plugins (example)

next-markdown comes with some default remark and rehype plugins to ensure its basic functionality.

In some cases you might want to specify additional plugins to enrich your page with extra features.

You can pass custom remark and rehype plugins via the next-markdown initializer config:

import NextMarkdown from "next-markdown";

const nextmd = NextMarkdown({
  ...,
  remarkPlugins: [],
  rehypePlugins: [],
});

Host Your .md Files in Another Repo (example)

For many good reasons you may want to host your content in another GIT repo.

Examples 🖥

More examples here ↗️.

Feel free to browse them to see next-markdown in action.

Contributing 🏗️

Thanks for your interest in next-markdown! You are very welcome to contribute. If you are proposing a new feature, please open an issue to make sure it is inline with the project goals.

1. Fork this repository to your own GitHub account and clone it to your local device

git clone https://github.com/your-name/next-markdown.git
cd next-markdown

2. Install the dependencies and run dev script

npm install
npm run dev

terminal 1

3. Open another terminal, pick an example in the examples/ folder, install dependencies and run dev

cd examples/blog # or dynamic-routes, or remote-content
npm install
npm run dev

terminal 2

4. Start coding

  • edit files in src/, save: http://localhost:3000 gets updated automatically (aka hot-reloading)
  • add tests in src/__tests__/. Run tests with npm test command.

browser

5. Submitting a PR

Before you make your pull request, make sure to run:

  • npm test to make sure nothing is broken
  • npm run format to make sure the code looks consistent
  • npm run lint to make sure there is no problem in the code

Contributors 🙏