• Stars
    star
    122
  • Rank 292,031 (Top 6 %)
  • Language
    TypeScript
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

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

More Repositories

1

elm-canvas

A canvas drawing library for Elm
Elm
163
star
2

cljs-browser-repl

A ClojureScript REPL and tutorial in your browser!
Clojure
36
star
3

context-cards

Wikipedia page previews for any site
Elm
31
star
4

cnake

A clojurescript canvas snake game
Clojure
26
star
5

elm-node

Run Elm + JS programs easily in node
JavaScript
18
star
6

elm-7guis

Elm implementation of the 7GUIs tasks
Elm
17
star
7

immutable-fns

facebook/immutable-js wrapper providing static functions to work with functional programming
JavaScript
12
star
8

group-phabricator-notifications

Browser extension to group phabricator notifications.
JavaScript
9
star
9

diving-into-clojurescript-exercises

Code and exercises of the workshop
Clojure
8
star
10

cljs-node-repl

A sample project for using cljs with node in lighttable
JavaScript
8
star
11

elm-canvas-sketch

elm-canvas example project
JavaScript
6
star
12

webkipedia

An experiment to create a native web app for wikipedia
Clojure
5
star
13

do-i-have-internet

Continuously check if your connection is working on the command line.
JavaScript
5
star
14

task-queue

A customizable job/task queue for javascript processes.
TypeScript
5
star
15

.vim

.vim folder
Vim Script
5
star
16

rust-random-text-generation

markov chain text generator written in rust
Rust
5
star
17

resume

Resume
HTML
5
star
18

sum-types

Sum types for JS
JavaScript
4
star
19

elm-js-interop

Elm to Js interop alternatives
JavaScript
4
star
20

node-elm-server

A small node.js server with the core logic built in Elm
JavaScript
4
star
21

mortgage-simulator

HTML
3
star
22

elm-basic-platformer-game

Basic platformer game in Elm
Elm
3
star
23

elm-grid

2d and 3d grid folding. Loop over a coordinate space, build a result
Elm
3
star
24

frontend-libraries-comparison

Scripts and info about different frontend libraries.
JavaScript
3
star
25

animalcoders

Animal coders website repo
JavaScript
3
star
26

wikireaper

Reporting notable deaths
JavaScript
3
star
27

ocaml-random-text-generation

markov chain text generator written in ocaml
Standard ML
2
star
28

boring-brunch

A brunch skeleton featuring JS, Less and Handlebars. Generators included.
JavaScript
2
star
29

wikimedia-graphql

GraphQL server for wikimedia APIs
JavaScript
2
star
30

backbone-basics

Basics library for developing backbone applications
JavaScript
2
star
31

agruntemplate

JavaScript
2
star
32

jquery-cache

A little cache system to use with jQuery to improve performance
2
star
33

loot-ui

Frontend server for rendering an experimental version of Wikipedia
JavaScript
2
star
34

loot

Backend server for mobile restbase html
JavaScript
2
star
35

gather-exporter

Export gather collections from Wikipedia for backup
JavaScript
2
star
36

jessay

A simple way to blog, present essays, or mantain a hierarchical list of pages (wiki?). Markdown and html/css/js. Static web generator. Python and Perl required.
JavaScript
2
star
37

loot-content-analysis

A cli tool for analyzing [loot](https://github.com/joakin/loot) content.
JavaScript
2
star
38

resource-modules

Checking ResourceLoader code files with configuration for linting and verification for MediaWiki projects
TypeScript
2
star
39

countador

Web counter with countdown and countup based ajax requests
JavaScript
2
star
40

dotfiles

My dotfiles
Shell
1
star
41

joakin.github.com

Web
CSS
1
star
42

gimme-gif

A small webapp for getting a gif related to a tag
Elm
1
star
43

protowiki

The simplest wikipedia spa for prototyping UIs
JavaScript
1
star
44

update-resourceloader-config-plugin

Update extension.json for mediawiki's resourceloader config with frontend modules for the webpack entry points.
JavaScript
1
star
45

water-automata

Small automata to simulate water
Elm
1
star
46

posterous-theme

The modified cleanup theme for posterous that i'm using in the blog
1
star
47

parcel-bundler-test

A test repo for parcel with typescript, css modules and react
TypeScript
1
star
48

plugins.js

A plugins file in javascript to collect all the plugins needed for your apps. Configurable by url.
JavaScript
1
star
49

freeboard

public anonymous post board forum
CSS
1
star
50

furgoneta

Functional JS library
JavaScript
1
star
51

elm-flee

A small game built for the Elm gamejam 4
Elm
1
star
52

hovercards-tests

Hovercards analytics browser tests
JavaScript
1
star
53

method-memoize

npm package to memoize class instance methods
JavaScript
1
star