Git Product home page Git Product logo

sitedown's Introduction

sitedown

Minimalist Markdown-based static site generator.

npm build downloads

Overview

Sitedown turns a folder with Markdown files into a static HTML site.

.                              build/
โ”œโ”€ README.md         ==>       โ”œโ”€ index.html
โ”œโ”€ about.md          ==>       โ””โ”€ about/
โ”‚                              โ”‚  โ””โ”€ index.html
โ”‚                              โ”‚
โ”œโ”€ docs/                       โ””โ”€ docs/
โ”‚  โ”œโ”€ README.md      ==>       โ”‚  โ”œโ”€ index.html
โ”‚  โ””โ”€ ref.md         ==>       โ”‚  โ””โ”€ ref/
โ”‚                              โ”‚     โ””โ”€ index.html
โ”‚                              โ”‚
โ””โ”€ assets/                     โ””โ”€ assets/
   โ””โ”€ cat.jpg        ==>          โ””โ”€ cat.jpg

It takes all markdown files in the current folder (and subfolders) and generates a new site in the build directory.

  • Converts README.md files into indexes (index.html).
  • Creates directory indexes for pretty URLs (CHANGELOG.md => changelog/index.html).
  • Supports custom layouts (comes with a default layout.html).
  • Copies assets (defaults to copying over contents of assets folder).
  • Comes with a dev mode that starts a server and watches for changes for easy local development.

Sitedown's website was built with sitedown, so you know it's for real.

Read the Usage section for a full overview of options and defaults.

Install

npm install sitedown

Usage

CLI

Usage: sitedown [source] [options]

    Example: sitedown . -b dist -l layout.html

    source                path to source directory (default: current working directory)
    --build, -b           path to build directory (default: "build")
    --pretty              use directory indexes for pretty URLs (default: true)
    --el, -e              css selector for target element (default: ".markdown-body")
    --layout, -l          path to layout file
    --github-headings, -g add anchors to headings just like GitHub (default: false)
    --no-hljs-class       don't add the hljs class to codeblocks (default: false)
    --silent, -s          make less noise during build
    --watch, -w           watch a directory or file (experimental)
    --dev, -d             start development server (experimental) (default: false)
    --assets, -a          assets folder to copy (default: "assets")
    --version, -v         show version information
    --help, -h            show help

Node API

var sitedown = require('sitedown')

var options = {
  source: '.',            // path to source directory                 default: cwd
  build: 'build',         // path to build directory                  default: 'build' in cwd
  pretty: true,           // use directory indexes for pretty URLs    default: true
  el: '.markdown-body',   // css selector for target element          default: '.markdown-body'
  layout: 'layout.html',  // path to layout                           default: none
  githubHeadings: false,  // add anchors to headings just like GitHub default: false
  noHljsClass: false,     // don't add hljs class to codeblocks       default: false
  silent: false           // make less noise during build             default: false
}

sitedown(options, function (err) {
  if (err) return console.error(err)
  console.log('success')
})

Layout

All files are wrapped in a layout.html file. Markdown content is appended to the first .markdown-body element, and the page title (<title> in <head>) is set to the text of the first h1 element.

The default layout is:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title></title>
    <link rel="stylesheet" href="https://unpkg.com/style.css">
  </head>
  <body>
    <main class="markdown-body"></main>
  </body>
</html>

The default layout comes bundled with style.css, a classless stylesheet for markdown documents.

Directory indexes (pretty URLs)

Markdown files ($f.md, $f.markdown) are lowercased and parsed into $f/index.html files. Directory indexes can be disabled with the pretty: false option. README.md files are always converted to directory indexes (index.html).

Links

Relative links that point to markdown files ($f.md, $f.markdown) are rewritten as $f/ to point to their $f/index.html equivalent.

Contributing

Contributions welcome! Please read the contributing guidelines first.

License

ISC

Page image is from emojipedia.

sitedown's People

Contributors

bcomnes avatar dependabot[bot] avatar flet avatar ungoldman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

flet bcomnes yawetse

sitedown's Issues

v6 roadmap

  • replace (or just supplement) layout.html convention with transforms:
    • allow piping markdown to a function in a JS file (e.g. transform.js) to add whatever you want
      • potentially anything from custom layouts to additional preprocessing to React/MDX support
  • remove highlightjs and github-headings options (super dated, not working great anymore)
  • change default el selector (either just main or maybe .sitedown)
  • convert to async/await (RIP callbacks)

fix link rewrite bugs

  • /readme.md should be rewritten to /index.html
  • when pretty: false, rewrite without directory indexes (e.g. guide.md -> guide.html)

Option to specify static content to copy to build directory

Its probably common that a generated site would use some css/js/images to make it look pretty.

Does it make sense to build that into sitedown, or should users just handle this outside of this command (via a simple cp in their build script perhaps)?

Would you prefer sitedown stay focused on the transformation of markdown only?

Cheerio 1.0.0

Was looking to stay up to date on the dep treadmill and was playing around with cheerio 1.0.0. Looks like its adding a and tag when loading docs now, instead of fragments.

See https://github.com/cheeriojs/cheerio/blob/v1.0.0/History.md for more info.

Anyway, we'll have to update the snapshots to account for that.

They do have some advice on how to use fragments (the old behavior). I tried it quickly, and couldn't get it to work the same way. It seems like going down the full document body path is probably ideal.

Default template in README.md is missing style.

The default template code in README.md is missing the following:

<style type="text/css">
    .markdown-body {
      max-width: 46em;
      margin: 2em auto;
      padding: 0 1em;
      overflow: hidden;
      word-wrap: break-word;
    }
</style>

Without it the entire page looks broken and it had me a bit confused for a minute.

Use marky-markdown?

Has marky-markdown been considered instead of using markdown-it directly?

marky-markdown is a markdown parser, written in NodeJS, that aims for
parity with [GitHub-style markdown]. It is built on top of [markdown-it],
a [CommonMark] markdown parser. You can use marky-markdown:

  • [programmatically in NodeJS]
  • [in your terminal]
  • [in the browser] *does not yet support syntax highlighting

marky-markdown is the thing that parses package READMEs on
http://www.npmjs.com.

https://www.npmjs.com/package/marky-markdown

Having parity to the way GitHub parses markdown would be a nice convention to rely on.

I started playing with switching over to marky-markdown locally and it worked, but then I realized my fork of sitedown was very, very old :/

One drawback: marky-markdown uses highlights for syntax highlighting, which requires oniguruma, which needs to be built at install via node-gyp. I can totally see how this could be a deal breaker for this project.

One thing that is holding back using sitedown with standard-www is generating anchors for headings automatically, which marky-markdown does out of the box. It certainly could be built for sitedown separately too...

bundle style.css with default layout

I used this yesterday at a hack night and noticed the dev UX is a little rough around the edges, especially for someone unfamiliar with the project or new to node. I think bundling good default styles for markdown would improve the experience.

We can link directly to the dist of the latest style.css using unpkg like so:

<link rel="stylesheet" href="https://unpkg.com/style.css@latest/style.css">

support layout

Right now sitedown is limited to a static header and footer. I've thought about adding basic layout support for a single file like

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>l1v3jRnL</title>
</head>
<body>
  {{content}}
</body>
</html>

or a more feature-rich setup like

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>{{title}}</title>
</head>
<body>
  <header>
    <h1>{{title}}</h1>
    <nav>
      <ul>{{nav_links}}</ul>
    </nav>
  </header>

  <div class="markdown-body">
    {{content}}
  </div>

  <footer>
    <nav>
      <ul>{{nav_links}}</ul>
    </nav>
  </footer>
</body>
</html>

The first isn't too much of a stretch, but the second necessitates choosing a layout engine and allowing for some dynamic stuff that may be a bit beyond scope. @Flet feedback welcome

copy images

Images referenced in markdown should be copied to output directory.

Better example of what this / how it works

This module is super underrated, and I think its because it could be described better. I have ideas but don't have time to describe them right now. Just stubbing out this issue for now.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.