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

@pipythonmc/markdown-folder-to-html

v2.5.4

Published

Convert a folder with files and markdown documents to an HTML site

Downloads

2

Readme

Fork Changes

  • Add syntax highlighting to the default template

  • Add snippet to default template for checkboxes

  • Add checkboxes support

  • Add footnotes support

  • Changed some links in the readme to point to the fork

markdown-folder-to-html

Simplest zero-config way to generate html docs from markdown files.

Copies docs to _docs and compiles markdown files to html using docs/template.html.

Live example at chimeces.com/markdown-folder-to-html (does not contain changes made by fork)

Usage

Requires node.js >= 6

Given we have some docs:

  1. mkdir -p docs
  2. Add some docs echo "**Banana**" > docs/banana.md
  3. Add some docs echo "**Apple**" > docs/index.md

In a project

  1. Install npm install -D markdown-folder-to-html
  2. Add docs to npm scripts {"scripts": {"docs": "markdown-folder-to-html"}}
  3. 🎉 npm run docs and open _docs/index.html

Globally

  1. Install npm install -g markdown-folder-to-html
  2. 🎉 markdown-folder-to-html and open _docs/index.html

Conventions

Input/Output folder

You can pass an argument to the cli to change the input folder (by default docs). That will change the output folder too to _FOLDERNAME (by default _docs).

markdown-folder-to-html documentation
# Outputs site to _documentation

If you want to change the output folder name, just mv it to something else.

Custom HTML

The default HTML is extremely basic, but simple and pretty, and is the one used in the docs.

This is the basic template that would work:

<!doctype html>
<html>
<body>
<nav>
	<!--NAV-->
</nav>
<article>
	<!--CONTENT-->
</article>
</body>
</html>

Create your own in your docs folder docs/template.html to use that one instead. Feel free to include styles inline or CSS files (since all will be copied to output).

Order

You may have noticed that files are sorted alphabetically. There's a little trick where if you name your folders/files with XX-folder/XX-file (XX being a number of 1+ digits) those numbers won't show up on the index of the pages, giving you the ability to organize files both in the filesystem and in the generated HTML site.

Also, the root index.md file will always show up at the beginning of the index.

Site contents and information for custom templates

If you want to do things with a custom template HTML you need the information of the site. This will allow you to do things in the front-end UI, like adding search to the static site with lunrjs or other things like adding buttons for the next/previous article.

For this use cases, you will see a contents.json generated in your output folder. It contains the hierarchical paths of the files, and the contents with the original markup, the HTML, the original path and the transformed URL:

{
  "paths": [
    {
      "type": "file",
      "value": "index.md"
    },
    {
      "type": "file",
      "value": "1-banana.md"
    },
    {
      "type": "dir",
      "name": "a-folder",
      "children": [
        {
          "type": "file",
          "value": "a-folder/with-a-post.md"
        }
      ]
    }
    //...
  ],
  "contents": [
    {
      "path": "index.md",
      "url": "index.html",
      "content": "# markdown-folder-to-html\n\nSimplest zero-config ...",
      "html": "<h1>markdown-folder-to-html</h1>\n<p>Simplest zero-config ...",
      "id": 0
    },
    {
      "path": "1-banana.md",
      "url": "1-banana.html",
      "content": "**Banana**\n\nYou can have [nested folders](./n...",
      "html": "<p><strong>Banana</strong></p>\n<p>You can have <a h...",
      "id": 1
    }
    //...
  ]
}

See the JSON file of our documentation site for an example.

You can then fetch this JSON file with JS from your template, and go crazy with it, processing the contents to adapt them for search, looking for the previous/next articles to link to them, etc.

If you have working examples of a template that does something interesting, please let me know and I'll list them here!

Why

After quite a lot of research, I couldn't find a simple and straightforward solution to generating html docs from a folder full of markdown files that relied on simple concepts. That is what this tool does:

  • Simply copy everything over, and translate .md files to .html with a pure HTML layout (feel free to add CSS, or JS, or precompile those assets if you need to)
  • .md links are rewritten to .html so that you can reference files with their real path on your markdown files and they'll work on the HTML version too.
  • Provide sensible defaults and zero-configuration. JUST WORK.
  • Use know abstraction, like the file system, pure HTML, etc

Links

  • https://github.com/pythonmcpi/markdown-folder-to-html
  • https://npmjs.org/package/@pipythonmc/markdown-folder-to-html