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

gulp-makdoc

v0.2.0

Published

A task library for generating documents

Downloads

4

Readme

NPM version Dependency Status

A task library for generating documents

Install & Usage

Install

$ npm install --save-dev gulp-makdoc

Usage

Require once anywhere:

var makdoc = require('gulp-makdoc');

gulp-makdoc has only peer dependencies so that you should check your dependencies.

Build:

$ gulp

Server:

$ gulp server

Watch:

$ gulp watch

Directory Layouts

.
├── app/
│   ├── layouts/
│   │   └── **/*.hbs
│   ├── partials/
│   │   └── **/*.hbs
│   ├── docs/
│   │   └── **/*.html.md   // docs, markdown to html
│   │   └── **/*.html.hbs // docs, handlebars to html
│   └── root/
│       ├── **/*.xml.hbs   // template, handlebars to xml
│       └── **/*.html.hbs  // template, handlebars to html
└── dist/ //target directory

You can change directory layouts. Override makdoc:init:after task.

gulp.task('makdoc:init:after', function(done){
    var returns = function(v) {
        return function(){
            return v;
        };
    };

    var vars = require('gulp-makdoc').vars;

    var.DOCS = returns('app/docs/**/*.{md,hbs}');
    var.TEMPLATES = returns(['app/root/**/*.hbs']);
    var.PARTIALS = returns('app/partials/**/*.hbs');
    var.LAYOUTS = returns('app/layouts/**/*.hbs');
    var.IMAGES = returns([
        'app/root/**/*.{ico,jpg,jpeg,png,gif}',
        'app/docs/**/*.{ico,jpg,jpeg,png,gif}']);
    var.STYLES = returns('app/root/**/*.{css,scss,less}');
    var.SCRIPTS = returns('app/root/**/*.js');
    var.DIST = returns('dist/');
    var.BASE_URL = returns('http://localhost/');

    done();
});

Deploy

You can define deploy task to easily deploy your documents:

gulp.task('deploy', ['makdoc'], function () {
    ...
});

Before documents are deploying, 'makdoc' task that build your documents should run. Make your documents fresh when you deploy

GitHub

Using gulp-gh-pages, You can easily deploy your site on GitHub page. Just install:

$ npm install --save-dev gulp-gh-pages

As a usage for gulp-gh-pages:

gulp.task('deploy', ['makdoc'], function () {
    var deploy = require('gulp-gh-pages');
    var path = require('path');

    return gulp.src(path.join($.makdoc.vars.DIST(),'**/*'))
        .pipe(deploy({
            remoteUrl: '[email protected]:pismute/pismute.github.io.git',
            cacheDir: '.gh-pages',
            branch:'master'
        }));
});

Model

Makdoc do not use such YAML front matter. so we can write with any editor and format. you can write your documents in an editor like vim or emacs, And then build them using Makdoc to push on your website , or then print them to your printer or pdf file using your own tool like Haroopad without touch.

Instead, Makdoc use model.json file. If the file name of your document is path/to/my-doc.html.md then make anther file of which the name is path/to/my-doc.html.md.json. Makdoc will load and merge it to the document model.

Here are model overriding order in some way:

  1. Default model: Hard-coded model in Makdoc
  2. Extract title and description from content
  3. Directory model(path/to/.model.json)'s default(*)
  4. Directory model(path/to/.model.json)'s Individual.
  5. File model: path/to/xxxx.json file.
  6. Finalize model

Default Model

Makdoc has four type components of documents:

  • Partials: .hbs templates that are partial documents in other .hbs documents.
  • Layouts: .hbs templates that contain other document.
  • Documents: .md, .hbs, and else documents that you write. Makdoc will decorate documents with Layouts, after Makdoc build them.
  • Templates: .hbs templates which is like index.html, atom.xml, sitemap.xml, and so on. Makdoc will decorate with Layouts

Makdoc initializes different model for each type as default.

Layouts, Partials

Layouts and Partials has no a default model:

{}
Templates

The default model of templates is simple:

{
    title: '',
    date: new Date(),
    description: '',
    layout: 'default'
    keywords: []
}
Documents

Every document has 'untitled' title and 'documents' layout and now as date. Makdoc will sort documents in docs variable by date descending:

{
    title: 'untitled',
    date: new Date(),
    description: '',
    layout: 'documents'
    keywords: []
}

Extract title and description from content

Makdoc inject the title and description of documents from rendered content(html) to model. The title is a striped-string from first line(newline ended, not <br>), and the description is a striped-string from the second or third nonempty(after striped and trimmed) line(it use the third line when the second line is empty):

<h1> This is title</h1>

<p>This is description and
this is not description</p>

Directory Model

An example represents layouts of directory and file models.

path/
└── to/
    ├── .model.json // A models for this directory, Directory model.
    ├── document.html.md // A `.md` document
    ├── document.html.md.json // A model for `.md` document, Document model
    ├── document.html.hbs // A `.hbs` document
    └── document.html.hbs.json // A model for `.hbs` document

.model.json:

{
    `*`: //Directory Default Model
    `document.html.md`: // Individual model.
}

File Model

`path/to/document.html.md.json':

{
    date: '2015-05-21',
    keywords: ['new release', 'makdoc']
}

Model for SEO

title, description and keywords of documents are useful for SEO. You can use it in your templates or layouts:

<title>{{{title}}}</title>
<meta name="description"
    content="{{{description}}}"></meta>
<meta name="keywords"
    content="{{{-join keywords ','}}}"></meta>

Tasks

Makdoc tasks are like LEGO bricks for generating documents. You can just use because Makdoc has lots of combination tasks.

you can override some tasks if you want to change it differently:

//after require('gulp-makdoc')
gulp.task('makdoc:task', function(){
    //...
});

Some tasks like server, watch, default, clean is just a task that run other tasks in order or parallel. Therefore, you can override the behavior of Makdoc as complete as you want.

For user

Tasks lead you to get easy:

  • default: Just alias of 'makdoc'
  • makdoc: Build your documents.
    1. 'makdoc:init'
    2. 'makdoc:start'
  • clean: Clean all generated files and optimized-image caches.
    1. 'makdoc:init'
    2. ['makdoc:clean', 'makdoc:clear']
  • server: Build and run server
    1. 'makdoc:init'
    2. 'makdoc:server'
    3. 'makdoc:start'
    4. 'makdoc:open'
  • watch: Build and run and watch for live-reload
    1. 'makdoc:init'
    2. 'makdoc:server'
    3. ['makdoc:start', 'makdoc:watch']
    4. 'makdoc:open'
  • makdoc:init:after: An empty task to override that Makdoc will run it after initialized
  • makdoc:done:after: An empty task to override that Makdoc will run it after all done

For internal

  • makdoc:start: Start makdoc process
    1. 'makdoc:prerequisite
    2. 'makdoc:clean'
    3. ['makdoc:resources', 'makdoc:build']
    4. 'makdoc:done:after'
  • makdoc:clean: Clean files built from Makdoc.
  • makdoc:clear: Clear caches of gulp-cache, which of optimized images
  • makdoc:build: Build documents like Handlebars or Markdown
    1. ['makdoc:partials', 'makdoc:layouts']
    2. 'makdoc:docs'
    3. 'makdoc:templates'
  • makdoc:prerequisite: Check condition.
  • makdoc:init: Initialize Makdoc
    • 'makdoc:init:after'
  • makdoc:partials: Load partial Helpers for Handlebars.
  • makdoc:layouts: Load layouts that are Handlebars templates for decorating documents.
  • makdoc:templates: Build handlebars templates(var.TEMPLATES()).
  • makdoc:docs: Build var.DOCS().
  • makdoc:resources: Build and copy resources without templates
    • 'makdoc:solid'
    • 'makdoc:images'
    • 'makdoc:styles'
    • 'makdoc:scripts'
  • makdoc:solid: Copy files to dist directory.
  • makdoc:images: Optimize and Copy images(var.IMAGES()) to dist directory.
  • makdoc:styles: Build and Copy style files(var.STYLES()) to dist directory.
  • makdoc:scripts: Build script files to dist directory.
  • makdoc:watch: Watch files to run tasks
  • makdoc:open: Open browser to walk your documents
  • makdoc:server: Run server with live-reload.

Links

License

MIT © Changwoo Park