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

servedown

v0.5.2

Published

Serve your markdown documentations

Downloads

8

Readme

NPM version Build Status Coverage Status License NPM dependencies

Servedown

Serve your markdown documentations

Why?

  • Needed a simple solution to render markdown files in many git projects
  • Did not get fully satisfied with gollum or smeagol
  • Render docs for read-only usage
  • Ability to easily customize styles and templates

Getting started

With a sample configuration, let's serve this project documentation :

  • Configuration ~/.servedown.yml :

    repos:
      - name: servedown
        ssh: [email protected]:openhoat/servedown.git
        url: https://github.com/openhoat/servedown
        filePattern: /blob/master/{{file}}
  • Start the server :

    $ servedown
    INFO  - servedown:181 - 131ms - cloning repo "servedown"...
    INFO  - servedown:409 - 4.2s - servedown is listening to 0.0.0.0:3000

    Now your server is ready...

  • Browse :

    $ xdg-open http://localhost:3000
  • Result :

    The welcome page is generated from a default template string (or your own index.html)

  • Click on "Servedown" doc project :

    Now you see your markdown files rendered with styles :-)

Command line

The simplest way to use servedown is the command line.

All you have to do is :

  1. setup your servedown configuration file (.servedown.yml) into your home directory
  2. run the servedown command

Installation

$ npm i servedown -g

Usage

Setup your custom configuration in ~/.servedown.yml :

Have a look at the default configuration file to understand all the customizable features.

Starts the servedown doc server :

$ servedown

If repos are specified in configuraton servedown will checkout them into the working directory (~/.servedown), then it will compute recursively the working dir to render the doc site.

Module

If you prefer to embed servedown features into an existing app, then use the servedown module.

Installation

$ cd yournodeproject
$ npm i servedown --save

Usage

const path = require('path');
const ServeDown = require('../lib/servedown');

ServeDown.start( // Factory static helper method
  {
    cacheDir: path.join(__dirname, '..', 'dist', 'working', 'cache'), // Cache dir
    repos: [{ // Git repos to get the markdown docs from
      name: 'servedown',
      url: 'https://github.com/openhoat/servedown'
    }]
  })
  .then(() => {
    console.log('ready');
  });

or the longer way :

const path = require('path');
const express = require('express');
const ServeDown = require('servedown');
const app = express();

const servedown = new ServeDown(); // Create a servedown instance

servedown.init({ // Initialize with custom config
  cacheDir: path.join(__dirname, '..', 'dist', 'working', 'cache'), // Cache dir
  repos: [{ // Git repos to get the markdown docs from
    name: 'servedown',
    url: 'https://github.com/openhoat/servedown'
  }]
});
app.use(servedown.buildExpressRouter()); // Use provided express middleware
app.listen(3000, () => {
  servedown.process(() => {  // Prepare html rendering
    console.log('ready');
  });
});

Principles and conventions

Here's a short description of how servedown works :

  • servedown first loads the configuration (init)
  • if there are git repos, a git pull or clone is executed for each repo
  • all source files are scanned
  • each markdown file is converted to html content
  • html content and meta datas are stored in a filesystem cache (specified by cacheDir in configuration)

Conventions :

  • each doc project is associated with a context name (directory of the git url)
  • static theme assets are served with /assets/* route
  • /search route is reserved to the search form page
  • all doc routes are based on the doc file path encoded to a valid uri (lowercase, spaces replaced by '-')
  • any doc file name matching the configured index pattern is considered as a welcome page for its parent directory (/mypath/home.md is exposed as /mypath/)

Features

Configuration format

Servedown supports json, js, or yaml format for configuration file.

Git support

Prerequisite : git command installed

Add your git repositories and servedown will automatically checkout them.

By default, servedown will optimize the clone operation : only markdown files are fetched.

Theme support

Use one of the two themes provided or use your owns, and hot switch the current theme with ?theme=.

Provided themes :

  • github : sample "github like" template
  • mydocs (default) : a complete and pretty template with table of contents, breadcrumb, and action buttons
  • readthedocs : "readthedocs" like template, for test purpose
  • simple : simplest template (no style)

TOC support

Table of contents is dynamically generated from the level 2 headers of markdown contents, look at mydocs theme template example to see how TOC is rendered.

Git source link

Optionnaly show the source link of the current document to make documentation changes easy.

Hot update

Add ?update to your browser address and it will reload, included git update.

Search support

Add ?q=anysearch to your browser address and servedown will search through your docs, show matches in a search result page and highlight the results into the doc content.

Into the doc content, press 'n' or 'p' to go to next/previous matching.

The /search route provides a default search form overridable by search.html theme template.

Markdown extensions

Link title

[[ My Title ]]

This is shorthand to My Title

Include

[[ include: my/doc/to/include.md ]]

Specified doc path is included into content, relative or absolute paths are supported, file extension is required.

Mermaid charts

Embed your Mermaid charts in md content with mermaid** ** tags.

Example :

    ```mermaid

    sequenceDiagram

    title Authentication Sequence

    Alice->Bob: Authentication Request
    note right of Bob: Bob thinks about it
    Bob->Alice: Authentication Response

    ```

Config var injection

First place a config.yml file at the root level of the documentation :

myvar: this will be injected
another:
    foo: bar

Then inject configuration data reference into markdown content using [{ }] tag :

[{ myvar }]

Another example :

[{ another.foo }]

Enjoy!